com.linkedin.data
Class DataList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by com.linkedin.data.collections.CheckedList<java.lang.Object>
              extended by com.linkedin.data.DataList
All Implemented Interfaces:
Common, CommonList<java.lang.Object>, DataComplex, Instrumentable, java.lang.Cloneable, java.lang.Iterable<java.lang.Object>, java.util.Collection<java.lang.Object>, java.util.List<java.lang.Object>

public final class DataList
extends CheckedList<java.lang.Object>
implements DataComplex

A DataList is ordered list of Data objects.

When an value is being added or replaced on the list, the list will verify that the value is a Data object. If the value is not a Data object, then the list will throw an IllegalArgumentException.

Cloning via the clone() method will shallow copy the DataList and will not deep copy contained complex objects. Copying via the copy() method will deep copy the DataList, which includes deep copying the contained complex objects.

Instrumentation if enabled is only enabled for the DataList and not for the underlying CheckedList. Furthermore, if a DataList is cloned, the clone will not have instrumentation enabled and the clone's instrumented data will be cleared.

Since DataList extends CheckedList, copying of the DataList is lazy and may be delayed until the DataList is about to be modified.


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Fields inherited from interface com.linkedin.data.Instrumentable
TIMES_ACCESSED, VALUE
 
Constructor Summary
DataList()
          Construct an empty DataList.
DataList(int initialCapacity)
          Construct a DataList with the specified initial capacity.
DataList(java.util.List<? extends java.lang.Object> list)
          Construct a DataList with Data objects provided by the input list.
 
Method Summary
 void clearInstrumentedData()
          Clear tracked data.
 DataList clone()
          Shallow clone.
 void collectInstrumentedData(java.lang.StringBuilder keyPrefix, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> instrumentedData, boolean collectAllData)
          Collect either all the data in this and contained Instrumentable or only the keys or indices that have been marked as accessed depending on the collectAllData flag.
 DataList copy()
          Deep copy.
 void copyReferencedObjects(java.util.IdentityHashMap<DataComplex,DataComplex> alreadyCopied)
          Deep copy this object and the complex Data objects referenced by this object.
 java.lang.Object get(int index)
           
 DataList getDataList(int index)
          Returns the element at the specified position cast to a DataList.
 DataMap getDataMap(int index)
          Returns the element at the specified position cast to a DataMap.
 boolean isMadeReadOnly()
          Whether this object and recursively contained complex objects are read-only.
 void makeReadOnly()
          Make read-only this object and recursively contained complex objects.
 void startInstrumentingAccess()
          Sets the state of this Instrumentable to start instrumenting data access.
 void stopInstrumentingAccess()
          Sets the state of this Instrumentable to stop instrumenting data access.
 java.util.Collection<java.lang.Object> values()
          Return the collection of values in this complex object.
 
Methods inherited from class com.linkedin.data.collections.CheckedList
add, add, addAll, addAll, addWithoutChecking, clear, contains, containsAll, equals, getObject, hashCode, indexOf, invalidate, isEmpty, isReadOnly, lastIndexOf, remove, remove, removeAll, removeRange, retainAll, set, setReadOnly, setWithoutChecking, size, toArray, toArray, toString
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.linkedin.data.collections.Common
invalidate, isReadOnly, setReadOnly
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator, subList
 

Constructor Detail

DataList

public DataList()
Construct an empty DataList.


DataList

public DataList(java.util.List<? extends java.lang.Object> list)
Construct a DataList with Data objects provided by the input list.

Parameters:
list - provides the initial Data objects in the constructed list.

DataList

public DataList(int initialCapacity)
Construct a DataList with the specified initial capacity.

Parameters:
initialCapacity - provides the initial capacity of the DataList.
Method Detail

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List<java.lang.Object>
Overrides:
get in class CheckedList<java.lang.Object>

clone

public DataList clone()
               throws java.lang.CloneNotSupportedException
Description copied from interface: Common
Shallow clone. The contained values are not recursively cloned. The clone will be read-write enabled.

Specified by:
clone in interface Common
Specified by:
clone in interface CommonList<java.lang.Object>
Specified by:
clone in interface DataComplex
Overrides:
clone in class CheckedList<java.lang.Object>
Returns:
the clone.
Throws:
java.lang.CloneNotSupportedException - if the object cannot be shallow copied.

copy

public DataList copy()
              throws java.lang.CloneNotSupportedException
Description copied from interface: DataComplex
Deep copy. Clones this object, deep copies complex Data objects referenced by this object, and update internal references to point to the deep copies.

Specified by:
copy in interface DataComplex
Throws:
java.lang.CloneNotSupportedException - if the object cannot be deep copied.

copyReferencedObjects

public void copyReferencedObjects(java.util.IdentityHashMap<DataComplex,DataComplex> alreadyCopied)
                           throws java.lang.CloneNotSupportedException
Description copied from interface: DataComplex
Deep copy this object and the complex Data objects referenced by this object.

Specified by:
copyReferencedObjects in interface DataComplex
Parameters:
alreadyCopied - provides the objects already copied, and their copies.
Throws:
java.lang.CloneNotSupportedException - if the referenced object cannot be copied.

values

public java.util.Collection<java.lang.Object> values()
Description copied from interface: DataComplex
Return the collection of values in this complex object. This is not recursive. It only returns the values directly contained in this object.

Specified by:
values in interface DataComplex
Returns:
the collection of values in this complex object.

makeReadOnly

public void makeReadOnly()
Description copied from interface: DataComplex
Make read-only this object and recursively contained complex objects. This is irreversible, once a complex object becomes read-only, it cannot be changed back to read-write. Note: Contained primitive types are always immutable.

Specified by:
makeReadOnly in interface DataComplex

isMadeReadOnly

public boolean isMadeReadOnly()
Description copied from interface: DataComplex
Whether this object and recursively contained complex objects are read-only. Note: Contained primitive types are always immutable.

Specified by:
isMadeReadOnly in interface DataComplex
Returns:
whether this object and recursively contained complex objects are read-only.

getDataList

public DataList getDataList(int index)
Returns the element at the specified position cast to a DataList.

Parameters:
index - of the element to return.
Returns:
the element at the specified position cast to a DataList.

getDataMap

public DataMap getDataMap(int index)
Returns the element at the specified position cast to a DataMap.

Parameters:
index - of the element to return.
Returns:
the element at the specified position cast to a DataMap.

startInstrumentingAccess

public void startInstrumentingAccess()
Description copied from interface: Instrumentable
Sets the state of this Instrumentable to start instrumenting data access. The types of accesses that are instrumented depends on the actual concrete classes that implement this interface. The minimum expectation is that read access via Collection#get, Map#get, and Map.containsKey(Object) are instrumented as an access.

Specified by:
startInstrumentingAccess in interface Instrumentable

stopInstrumentingAccess

public void stopInstrumentingAccess()
Description copied from interface: Instrumentable
Sets the state of this Instrumentable to stop instrumenting data access.

Specified by:
stopInstrumentingAccess in interface Instrumentable

clearInstrumentedData

public void clearInstrumentedData()
Description copied from interface: Instrumentable
Clear tracked data.

Specified by:
clearInstrumentedData in interface Instrumentable

collectInstrumentedData

public void collectInstrumentedData(java.lang.StringBuilder keyPrefix,
                                    java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> instrumentedData,
                                    boolean collectAllData)
Description copied from interface: Instrumentable
Collect either all the data in this and contained Instrumentable or only the keys or indices that have been marked as accessed depending on the collectAllData flag. The data is collected into the instrumentedData supplied. Each entry's key in the instrumentedData map is the fully qualified name of the accessed key or index. The fully qualified name is constructed by pre-pending the provided keyPrefix and the keys and indices of antecedent objects traversed to reach this particular key or index. Each entry's value in the instrumentedData map is another map. The minimum expectation is that the latter map has at least two entries, the "value" entry holds the String representation object identified by the fully qualified name, and the "timesAcessed" entry has the number of times the fully qualified name has been accessed. The number of times accessed may be null in case it is unknown how many times the key or index was accessed due to instrumentation limitations.

Specified by:
collectInstrumentedData in interface Instrumentable
Parameters:
keyPrefix - is the prefix to prepend to the fully qualified name of accessed keys and indices.
instrumentedData - provides the map to hold the output of the collected instrumented data, each map entry's key is the fully qualified name of the key or index accessed, and the map entry's value is another map that holds collected data.
collectAllData - indicates whether to collect all data in this and contained Instrumentable or only the keys or indices accessed.