Class DataElementList<E extends DataElement>

  • All Implemented Interfaces:
    DataElement, java.lang.Comparable<DataElement>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, javolution.lang.Reusable
    Direct Known Subclasses:
    DataCase, DataSet

    public abstract class DataElementList<E extends DataElement>
    extends java.util.AbstractList<E>
    implements DataElement, javolution.lang.Reusable
    A named list of DataElement objects with associated user data.

    Modified by: Joseph A. Huwaldt

    Version:
    October 15, 2015
    Author:
    Joseph A. Huwaldt, Date: March 5, 2003
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, E value)
      Inserts the specified DataElement at the specified position in this list.
      void addAll​(int index, E[] elements)
      Inserts the specified list of elements at the specified position in this list.
      void addAll​(E[] elements)
      Appends the specified list of elements to the end of this list.
      int compareTo​(DataElement otherElement)  
      boolean equals​(java.lang.Object obj)
      Compares the specified object with this list of DataElement objects for equality.
      E get​(int index)
      Returns the element at the specified position in this list.
      E get​(java.lang.CharSequence name)
      Returns the element with the specified name from this list.
      int getIndexFromName​(java.lang.CharSequence name)
      Return the index to the 1st data element in this list with the specified name.
      java.lang.CharSequence getName()
      Return the name of this data element.
      java.lang.Object getUserObject()
      Return any user defined object associated with this data element.
      int hashCode()
      Returns the hash code for this DataElementList.
      java.util.Iterator<E> iterator()
      Returns an iterator over the elements in this list (allocated on the stack when executed in a StackContext).
      java.util.ListIterator<E> listIterator()
      Returns a list iterator over the elements in this list (allocated on the stack when executed in a StackContext).
      java.util.ListIterator<E> listIterator​(int index)
      Returns a list iterator from the specified position (allocated on the stack when executed in a StackContext).
      E remove​(int index)
      Removes the element at the specified position in this list.
      E remove​(java.lang.CharSequence name)
      Removes the element at the specified name in this list.
      void reset()
      Resets the internal state of this object to its default values.
      E set​(int index, E element)
      Replaces the DataElement at the specified position in this list with the specified element.
      void setName​(java.lang.CharSequence name)
      Change the name of this data element to the specified name (may not be null).
      void setUserObject​(java.lang.Object data)
      Set the user defined object associated with this data element.
      int size()
      Returns the number of elements in this list.
      java.lang.String toString()
      Create a string representation of this data element which simply consists of the element's name.
      javolution.text.Text toText()
      Create a Text representation of this data element which simply consists of the element's name.
      java.util.List<E> unmodifiable()
      Returns the unmodifiable view associated to this collection.
      • Methods inherited from class java.util.AbstractList

        add, addAll, clear, indexOf, lastIndexOf, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Method Detail

      • size

        public int size()
        Returns the number of elements in this list. If the list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        size in interface java.util.Collection<E extends DataElement>
        Specified by:
        size in interface java.util.List<E extends DataElement>
        Specified by:
        size in class java.util.AbstractCollection<E extends DataElement>
        Returns:
        the number of elements in this list.
      • get

        public E get​(int index)
        Returns the element at the specified position in this list.
        Specified by:
        get in interface java.util.List<E extends DataElement>
        Specified by:
        get in class java.util.AbstractList<E extends DataElement>
        Parameters:
        index - index of element to return.
        Returns:
        the element at the specified position in this list.
        Throws:
        java.lang.IndexOutOfBoundsException - if the given index is out of range (index < 0 || index > size()-1)
      • set

        public E set​(int index,
                     E element)
        Replaces the DataElement at the specified position in this list with the specified element. Null elements are ignored.
        Specified by:
        set in interface java.util.List<E extends DataElement>
        Overrides:
        set in class java.util.AbstractList<E extends DataElement>
        Parameters:
        index - The index of the element to replace.
        element - The element to be stored at the specified position.
        Returns:
        The element previously at the specified position in this list.
        Throws:
        java.lang.IndexOutOfBoundsException - - if (index < 0) || (index > size()-1)
      • add

        public void add​(int index,
                        E value)
        Inserts the specified DataElement at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). Null values are ignored.

        Note: If this method is used, concurrent access must be synchronized (the table is not thread-safe).

        Specified by:
        add in interface java.util.List<E extends DataElement>
        Overrides:
        add in class java.util.AbstractList<E extends DataElement>
        Parameters:
        index - the index at which the specified element is to be inserted.
        value - the element to be inserted.
        Throws:
        java.lang.IndexOutOfBoundsException - if (index < 0) || (index > size()-1)
      • addAll

        public void addAll​(E[] elements)
        Appends the specified list of elements to the end of this list. Null elements are ignored.
        Parameters:
        elements - Array of elements to be inserted.
      • addAll

        public void addAll​(int index,
                           E[] elements)
        Inserts the specified list of elements at the specified position in this list. Shifts the elements currently at that position (if any) and any subsequent parameters to the right (adds one to their indices) until all the elements have been added.
        Parameters:
        index - Index at which the specified list of elements is to be inserted.
        elements - List of elements to be inserted.
      • remove

        public E remove​(int index)
        Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
        Specified by:
        remove in interface java.util.List<E extends DataElement>
        Overrides:
        remove in class java.util.AbstractList<E extends DataElement>
        Parameters:
        index - the index of the element to remove.
        Returns:
        the element previously at the specified position.
      • iterator

        public java.util.Iterator<Eiterator()
        Returns an iterator over the elements in this list (allocated on the stack when executed in a StackContext).
        Specified by:
        iterator in interface java.util.Collection<E extends DataElement>
        Specified by:
        iterator in interface java.lang.Iterable<E extends DataElement>
        Specified by:
        iterator in interface java.util.List<E extends DataElement>
        Overrides:
        iterator in class java.util.AbstractList<E extends DataElement>
        Returns:
        an iterator over this list values.
      • listIterator

        public java.util.ListIterator<ElistIterator()
        Returns a list iterator over the elements in this list (allocated on the stack when executed in a StackContext).
        Specified by:
        listIterator in interface java.util.List<E extends DataElement>
        Overrides:
        listIterator in class java.util.AbstractList<E extends DataElement>
        Returns:
        an iterator over this list values.
      • listIterator

        public java.util.ListIterator<ElistIterator​(int index)
        Returns a list iterator from the specified position (allocated on the stack when executed in a StackContext). The list iterator being returned does not support insertion/deletion.
        Specified by:
        listIterator in interface java.util.List<E extends DataElement>
        Overrides:
        listIterator in class java.util.AbstractList<E extends DataElement>
        Parameters:
        index - the index of first value to be returned from the list iterator (by a call to the next method).
        Returns:
        a list iterator of the values in this table starting at the specified position in this list.
      • unmodifiable

        public java.util.List<Eunmodifiable()
        Returns the unmodifiable view associated to this collection. Attempts to modify the returned collection result in an UnsupportedOperationException being thrown. The view is typically part of the collection itself (created only once) and also an instance of FastCollection supporting direct iterations.
        Returns:
        the unmodifiable view over this collection.
      • reset

        public void reset()
        Resets the internal state of this object to its default values.
        Specified by:
        reset in interface javolution.lang.Reusable
      • get

        public E get​(java.lang.CharSequence name)
        Returns the element with the specified name from this list.
        Parameters:
        name - The name of the element we are looking for in the list.
        Returns:
        The element matching the specified name. If the specified element name isn't found in the list, then null is returned.
      • remove

        public E remove​(java.lang.CharSequence name)
        Removes the element at the specified name in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
        Parameters:
        name - the name of the element to remove.
        Returns:
        the element previously at the specified position.
      • getIndexFromName

        public int getIndexFromName​(java.lang.CharSequence name)
        Return the index to the 1st data element in this list with the specified name.
        Parameters:
        name - The name of the data element to find in this list.
        Returns:
        The index to the named data element or -1 if it is not found.
      • getUserObject

        public java.lang.Object getUserObject()
        Return any user defined object associated with this data element. If there is no user data, then null is returned.
        Specified by:
        getUserObject in interface DataElement
      • setUserObject

        public void setUserObject​(java.lang.Object data)
        Set the user defined object associated with this data element. This can be used to store any type of information with a data element that could be useful. Storing null for no user object is fine.
        Specified by:
        setUserObject in interface DataElement
      • getName

        public java.lang.CharSequence getName()
        Return the name of this data element.
        Specified by:
        getName in interface DataElement
      • setName

        public void setName​(java.lang.CharSequence name)
        Change the name of this data element to the specified name (may not be null).
        Specified by:
        setName in interface DataElement
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares the specified object with this list of DataElement objects for equality. Returns true if and only if both collections contain equal values in the same order.
        Specified by:
        equals in interface java.util.Collection<E extends DataElement>
        Specified by:
        equals in interface java.util.List<E extends DataElement>
        Overrides:
        equals in class java.util.AbstractList<E extends DataElement>
        Parameters:
        obj - the object to compare with.
        Returns:
        true if this list is identical to that list; false otherwise.
      • hashCode

        public int hashCode()
        Returns the hash code for this DataElementList.
        Specified by:
        hashCode in interface java.util.Collection<E extends DataElement>
        Specified by:
        hashCode in interface java.util.List<E extends DataElement>
        Overrides:
        hashCode in class java.util.AbstractList<E extends DataElement>
        Returns:
        the hash code value.
      • toText

        public javolution.text.Text toText()
        Create a Text representation of this data element which simply consists of the element's name.
      • toString

        public java.lang.String toString()
        Create a string representation of this data element which simply consists of the element's name.
        Overrides:
        toString in class java.util.AbstractCollection<E extends DataElement>