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:
ByteArrayToDataContainer.DummyContainer,DataContainerToByteArray.DummyContainer,DataContainerToString.DummyContainer,Instance,SpreadSheetRow,StringToDataContainer.DummyContainer,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 booleanadd(T point)Adds the point to the list of points.booleanaddAll(Collection points)Adds all the points to the list of points.voidassign(DataContainer<T> other)Obtains the stored variables from the other data point, but not the actual data points.voidclear()Removes all the points.intcompareTo(Object o)Compares this object with the specified object for order.intcompareToData(Object o)Compares this object with the specified object for order.intcompareToHeader(Object o)Compares this object with the specified object for order.booleancontains(Object point)Checks whether the given point is already stored.booleancontainsAll(Collection points)Checks whether all the given points are already stored.voidensureCapacity(int minCapacity)Ensures that the capacity is at least the specified minimum.booleanequals(Object obj)Indicates whether some other object is "equal to" this one.booleanequalsData(Object obj)Indicates whether some other container's header is "equal to" this ones.booleanequalsHeader(Object obj)Indicates whether some other chromatogram's header is "equal to" this ones.ObjectgetClone()Returns a clone of itself.DataContainergetHeader()Returns an empty container with the same payload data as this one.StringgetID()Returns the ID of the sequence.longgetUniqueID()Returns the unique ID.inthashCode()Returns the hash code for this DataContainer.booleanisEmpty()Returns whether the DataContainer is empty.Iterator<T>iterator()Returns an iterator over the points.voidmergeWith(DataContainer other)Adds copies of all the points from the given container to its own.protected booleanmodifiedListener(boolean modified)Method that gets notified about changes in the collection of data points.static DataContainernewInstance(DataContainer cont)Returns a new (empty) instance of the same class as the specified container.booleanremove(Object point)Removes the given point from its list of points.booleanremoveAll(Collection points)Removes all the points from the list of points.booleanretainAll(Collection points)Retains all the given points and removes the others.voidsetID(String value)Sets the ID of the sequence.intsize()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.StringtoString()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.voidtrimToSize()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:
setIDin 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:
getUniqueIDin interfaceUniqueIDHandler- Returns:
- the ID
-
getClone
public Object getClone()
Returns a clone of itself. Note: resets the read-only flag!- Specified by:
getClonein interfaceCloneHandler<T extends DataPoint>- Specified by:
getClonein 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:
assignin 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:
getHeaderin 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:
compareToHeaderin 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:
compareToDatain 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:
equalsDatain 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:
compareToin 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:
equalsHeaderin 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:
clearin interfaceCollection<T extends DataPoint>
-
isEmpty
public boolean isEmpty()
Returns whether the DataContainer is empty.- Specified by:
isEmptyin 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:
addin 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:
addAllin 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:
removein 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:
removeAllin 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:
containsin 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:
containsAllin 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:
retainAllin 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:
sizein 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:
toArrayin interfaceCollection<T extends DataPoint>- Returns:
- the points as array
-
toArray
public Object[] toArray(Object[] array)
Returns the stored points as array.- Specified by:
toArrayin 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:
toListin 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:
toListin 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:
toTreeSetin 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:
toTreeSetin 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
-
-