Package jahuwaldt.js.datareader
Class DataElementList<E extends DataElement>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- jahuwaldt.js.datareader.DataElementList<E>
-
- All Implemented Interfaces:
DataElement
,java.lang.Comparable<DataElement>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
,javolution.lang.Reusable
public abstract class DataElementList<E extends DataElement> extends java.util.AbstractList<E> implements DataElement, javolution.lang.Reusable
A named list ofDataElement
objects with associated user data.Modified by: Joseph A. Huwaldt
- Version:
- October 15, 2015
- Author:
- Joseph A. Huwaldt, Date: March 5, 2003
-
-
Field Summary
-
Fields inherited from interface jahuwaldt.js.datareader.DataElement
RESOURCES
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E value)
Inserts the specifiedDataElement
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 ofDataElement
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 thisDataElementList
.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 theDataElement
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 benull
).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
-
-
-
-
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 interfacejava.util.Collection<E extends DataElement>
- Specified by:
size
in interfacejava.util.List<E extends DataElement>
- Specified by:
size
in classjava.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 interfacejava.util.List<E extends DataElement>
- Specified by:
get
in classjava.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 theDataElement
at the specified position in this list with the specified element. Null elements are ignored.- Specified by:
set
in interfacejava.util.List<E extends DataElement>
- Overrides:
set
in classjava.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 specifiedDataElement
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 interfacejava.util.List<E extends DataElement>
- Overrides:
add
in classjava.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 interfacejava.util.List<E extends DataElement>
- Overrides:
remove
in classjava.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<E> iterator()
Returns an iterator over the elements in this list (allocated on the stack when executed in a StackContext).- Specified by:
iterator
in interfacejava.util.Collection<E extends DataElement>
- Specified by:
iterator
in interfacejava.lang.Iterable<E extends DataElement>
- Specified by:
iterator
in interfacejava.util.List<E extends DataElement>
- Overrides:
iterator
in classjava.util.AbstractList<E extends DataElement>
- Returns:
- an iterator over this list values.
-
listIterator
public java.util.ListIterator<E> listIterator()
Returns a list iterator over the elements in this list (allocated on the stack when executed in a StackContext).- Specified by:
listIterator
in interfacejava.util.List<E extends DataElement>
- Overrides:
listIterator
in classjava.util.AbstractList<E extends DataElement>
- Returns:
- an iterator over this list values.
-
listIterator
public java.util.ListIterator<E> listIterator(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 interfacejava.util.List<E extends DataElement>
- Overrides:
listIterator
in classjava.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<E> unmodifiable()
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 interfacejavolution.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, thennull
is returned.- Specified by:
getUserObject
in interfaceDataElement
-
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. Storingnull
for no user object is fine.- Specified by:
setUserObject
in interfaceDataElement
-
getName
public java.lang.CharSequence getName()
Return the name of this data element.- Specified by:
getName
in interfaceDataElement
-
setName
public void setName(java.lang.CharSequence name)
Change the name of this data element to the specified name (may not benull
).- Specified by:
setName
in interfaceDataElement
-
equals
public boolean equals(java.lang.Object obj)
Compares the specified object with this list ofDataElement
objects for equality. Returns true if and only if both collections contain equal values in the same order.- Specified by:
equals
in interfacejava.util.Collection<E extends DataElement>
- Specified by:
equals
in interfacejava.util.List<E extends DataElement>
- Overrides:
equals
in classjava.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 thisDataElementList
.- Specified by:
hashCode
in interfacejava.util.Collection<E extends DataElement>
- Specified by:
hashCode
in interfacejava.util.List<E extends DataElement>
- Overrides:
hashCode
in classjava.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 classjava.util.AbstractCollection<E extends DataElement>
-
compareTo
public int compareTo(DataElement otherElement)
- Specified by:
compareTo
in interfacejava.lang.Comparable<E extends DataElement>
-
-