Package adams.data.container
Class AbstractDataContainer<T extends DataPoint>
- java.lang.Object
-
- adams.data.container.AbstractDataContainer<T>
-
- Type Parameters:
T
- the type of the container
- All Implemented Interfaces:
CloneHandler
,Mergeable<DataContainer>
,UniqueIDHandler
,DataContainer<T>
,IDHandler
,MutableIDHandler
,Serializable
,Comparable
,Iterable<T>
,Collection<T>
- Direct Known Subclasses:
Instance
,SpreadSheetRow
,Timeseries
,XYSequence
public abstract class AbstractDataContainer<T extends DataPoint> extends Object implements DataContainer<T>, MutableIDHandler
Superclass for all data structures.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractDataContainer()
Initializes the container.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T point)
Adds the point to the list of points.boolean
addAll(Collection points)
Adds all the points to the list of points.void
assign(DataContainer<T> other)
Obtains the stored variables from the other data point, but not the actual data points.void
clear()
Removes all the points.int
compareTo(Object o)
Compares this object with the specified object for order.int
compareToData(Object o)
Compares this object with the specified object for order.int
compareToHeader(Object o)
Compares this object with the specified object for order.boolean
contains(Object point)
Checks whether the given point is already stored.boolean
containsAll(Collection points)
Checks whether all the given points are already stored.void
ensureCapacity(int minCapacity)
Ensures that the capacity is at least the specified minimum.boolean
equals(Object obj)
Indicates whether some other object is "equal to" this one.boolean
equalsData(Object obj)
Indicates whether some other container's header is "equal to" this ones.boolean
equalsHeader(Object obj)
Indicates whether some other chromatogram's header is "equal to" this ones.Object
getClone()
Returns a clone of itself.DataContainer
getHeader()
Returns an empty container with the same payload data as this one.String
getID()
Returns the ID of the sequence.long
getUniqueID()
Returns the unique ID.int
hashCode()
Returns the hash code for this DataContainer.boolean
isEmpty()
Returns whether the DataContainer is empty.Iterator<T>
iterator()
Returns an iterator over the points.void
mergeWith(DataContainer other)
Adds copies of all the points from the given container to its own.protected boolean
modifiedListener(boolean modified)
Method that gets notified about changes in the collection of data points.static DataContainer
newInstance(DataContainer cont)
Returns a new (empty) instance of the same class as the specified container.boolean
remove(Object point)
Removes the given point from its list of points.boolean
removeAll(Collection points)
Removes all the points from the list of points.boolean
retainAll(Collection points)
Retains all the given points and removes the others.void
setID(String value)
Sets the ID of the sequence.int
size()
Returns the number of points stored in the DataContainer.Object[]
toArray()
Returns the stored points as array.Object[]
toArray(Object[] array)
Returns the stored points as array.List<T>
toList()
Returns a list with the points.List<T>
toList(DataPointComparator comparator)
Returns a list with the points.String
toString()
Returns a string representation of the DataContainer.TreeSet<T>
toTreeSet()
Returns a treeset with the points.TreeSet<T>
toTreeSet(DataPointComparator comparator)
Returns a treeset with the points, sorted according to the given comparator.void
trimToSize()
Trims the capacity of this container to be the container's current size.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Methods inherited from interface adams.data.container.DataContainer
getComparator, newComparator, newPoint
-
-
-
-
Method Detail
-
setID
public void setID(String value)
Sets the ID of the sequence.- Specified by:
setID
in interfaceMutableIDHandler
- Parameters:
value
- the new ID
-
getID
public String getID()
Returns the ID of the sequence.
-
getUniqueID
public long getUniqueID()
Returns the unique ID.- Specified by:
getUniqueID
in interfaceUniqueIDHandler
- Returns:
- the ID
-
getClone
public Object getClone()
Returns a clone of itself. Note: resets the read-only flag!- Specified by:
getClone
in interfaceCloneHandler<T extends DataPoint>
- Specified by:
getClone
in interfaceDataContainer<T extends DataPoint>
- Returns:
- the clone
-
assign
public void assign(DataContainer<T> other)
Obtains the stored variables from the other data point, but not the actual data points.- Specified by:
assign
in interfaceDataContainer<T extends DataPoint>
- Parameters:
other
- the data point to get the values from
-
getHeader
public DataContainer getHeader()
Returns an empty container with the same payload data as this one.- Specified by:
getHeader
in interfaceDataContainer<T extends DataPoint>
- Returns:
- a clone of the payload
-
compareToHeader
public int compareToHeader(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareToHeader
in interfaceDataContainer<T extends DataPoint>
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
compareToData
public int compareToData(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareToData
in interfaceDataContainer<T extends DataPoint>
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equalsData
public boolean equalsData(Object obj)
Indicates whether some other container's header is "equal to" this ones.- Specified by:
equalsData
in interfaceDataContainer<T extends DataPoint>
- Parameters:
obj
- the reference object with which to compare.- Returns:
- true if this object is the same as the obj argument; false otherwise.
-
compareTo
public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfaceComparable<T extends DataPoint>
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equalsHeader
public boolean equalsHeader(Object obj)
Indicates whether some other chromatogram's header is "equal to" this ones.- Specified by:
equalsHeader
in interfaceDataContainer<T extends DataPoint>
- Parameters:
obj
- the reference object with which to compare.- Returns:
- true if this object is the same as the obj argument; false otherwise.
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
-
modifiedListener
protected boolean modifiedListener(boolean modified)
Method that gets notified about changes in the collection of data points. Just passes the modified state through.
The default implementation only passes the value through.- Parameters:
modified
- whether the action modified the collection- Returns:
- the same as the input
-
clear
public void clear()
Removes all the points.- Specified by:
clear
in interfaceCollection<T extends DataPoint>
-
isEmpty
public boolean isEmpty()
Returns whether the DataContainer is empty.- Specified by:
isEmpty
in interfaceCollection<T extends DataPoint>
- Returns:
- true if empty
-
ensureCapacity
public void ensureCapacity(int minCapacity)
Ensures that the capacity is at least the specified minimum.- Parameters:
minCapacity
- the minimum capacity that the container should have for storing data points
-
trimToSize
public void trimToSize()
Trims the capacity of this container to be the container's current size.
-
add
public boolean add(T point)
Adds the point to the list of points.- Specified by:
add
in interfaceCollection<T extends DataPoint>
- Parameters:
point
- the point to add- Returns:
- true if the points changed
-
addAll
public boolean addAll(Collection points)
Adds all the points to the list of points.- Specified by:
addAll
in interfaceCollection<T extends DataPoint>
- Parameters:
points
- the points to add- Returns:
- true if the points changed
-
remove
public boolean remove(Object point)
Removes the given point from its list of points.- Specified by:
remove
in interfaceCollection<T extends DataPoint>
- Parameters:
point
- the point to remove- Returns:
- true if the points changed
-
removeAll
public boolean removeAll(Collection points)
Removes all the points from the list of points.- Specified by:
removeAll
in interfaceCollection<T extends DataPoint>
- Parameters:
points
- the points to remove- Returns:
- true if the points changed
-
contains
public boolean contains(Object point)
Checks whether the given point is already stored.- Specified by:
contains
in interfaceCollection<T extends DataPoint>
- Parameters:
point
- the point to check- Returns:
- true if point already exists in list
-
containsAll
public boolean containsAll(Collection points)
Checks whether all the given points are already stored.- Specified by:
containsAll
in interfaceCollection<T extends DataPoint>
- Parameters:
points
- the points to check- Returns:
- true if points already exist in list
-
retainAll
public boolean retainAll(Collection points)
Retains all the given points and removes the others.- Specified by:
retainAll
in interfaceCollection<T extends DataPoint>
- Parameters:
points
- the points to keep- Returns:
- true if points changed
-
size
public int size()
Returns the number of points stored in the DataContainer.- Specified by:
size
in interfaceCollection<T extends DataPoint>
- Returns:
- the number of points
-
mergeWith
public void mergeWith(DataContainer other)
Adds copies of all the points from the given container to its own. No will get overwritten, only added.
-
toArray
public Object[] toArray()
Returns the stored points as array.- Specified by:
toArray
in interfaceCollection<T extends DataPoint>
- Returns:
- the points as array
-
toArray
public Object[] toArray(Object[] array)
Returns the stored points as array.- Specified by:
toArray
in interfaceCollection<T extends DataPoint>
- Parameters:
array
- the array into which the points of this DataContainer are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- the points as array
-
toList
public List<T> toList()
Returns a list with the points. Very fast, as it only returns the internal linked list.- Specified by:
toList
in interfaceDataContainer<T extends DataPoint>
- Returns:
- a list with all the points
-
toList
public List<T> toList(DataPointComparator comparator)
Returns a list with the points.- Specified by:
toList
in interfaceDataContainer<T extends DataPoint>
- Parameters:
comparator
- the comparator to use- Returns:
- a list with all the points
-
toTreeSet
public TreeSet<T> toTreeSet()
Returns a treeset with the points.- Specified by:
toTreeSet
in interfaceDataContainer<T extends DataPoint>
- Returns:
- a treeset with all the points
-
toTreeSet
public TreeSet<T> toTreeSet(DataPointComparator comparator)
Returns a treeset with the points, sorted according to the given comparator.- Specified by:
toTreeSet
in interfaceDataContainer<T extends DataPoint>
- Parameters:
comparator
- the comparator to use- Returns:
- a treeset with all the points
-
hashCode
public int hashCode()
Returns the hash code for this DataContainer.
-
toString
public String toString()
Returns a string representation of the DataContainer.
-
newInstance
public static DataContainer newInstance(DataContainer cont)
Returns a new (empty) instance of the same class as the specified container.- Parameters:
cont
- the container to use as a class template- Returns:
- the instance or null in case of an error
-
-