Class ArrayDataObject<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- ArrayDataObject<T>
-
- All Implemented Interfaces:
DataObject
,Serializable
,Iterable<T>
,Collection<T>
,List<T>
- Direct Known Subclasses:
ArrayOfDataObject
public class ArrayDataObject<T> extends AbstractList<T> implements DataObject
An ArrayDataObject is a DataObject whose content is an array. It is useful where you need a DataObject as the representation for an ASN.1 SEQUENCE OF or SET OF type, and is used if the extendible adaptation is given.This implementation assumes that the contained datatype is an opaque type with no special properties. For arrays of datatypes that implement DataObject,
ArrayOfDataObject
should be used.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected T[]
value
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ArrayDataObject(T[] value)
Constructs from a given initial array value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkModify()
Checks whether this DataObject is mutable.ArrayDataObject<T>
clone()
Perform a deep copy of this object.static ArrayDataObject<?>
copyOf(ArrayDataObject<?> from)
Creates a new ArrayDataObject, initialising its value from that of the given ArrayDataObject.boolean
equals(Object obj)
Compares some other object to this one for equality by value.T
get(int index)
Gets the element at the given position in the list.T[]
getValue()
Gets the array value from this DataObject.int
hashCode()
Gets a hash code value for this object.boolean
isReadOnly()
Check if this object has been set read-only.T
set(int index, T element)
Sets the element at the given position in the list to the given value.void
setReadOnly()
Set this object to be "read-only".int
size()
Gets the size of the list.String
toString()
Returns a printable representation of this.-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
value
protected final T[] value
-
-
Constructor Detail
-
ArrayDataObject
public ArrayDataObject(T[] value)
Constructs from a given initial array value.- Parameters:
value
- array value; must not be null.
-
-
Method Detail
-
getValue
public T[] getValue()
Gets the array value from this DataObject. If this instance is readonly, a copy of the array is returned, to avoid possible mutation of the array contents.- Returns:
- array
-
get
public T get(int index)
Gets the element at the given position in the list.
-
set
public T set(int index, T element)
Sets the element at the given position in the list to the given value.
-
size
public int size()
Gets the size of the list.- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
- Returns:
- number of elements in list
-
clone
public ArrayDataObject<T> clone()
Description copied from interface:DataObject
Perform a deep copy of this object. Read-only state of the object is not copied; the new object will be read-write by default.Inherently immutable objects may optionally return the same object without modification from clone(), rather than constructing a new instance.
- Specified by:
clone
in interfaceDataObject
- Overrides:
clone
in classObject
- Returns:
- a new object that is a deep copy of this object; for immutable objects, the same object may optionally be returned.
-
setReadOnly
public void setReadOnly()
Description copied from interface:DataObject
Set this object to be "read-only". Any subsequent attempt to modify this object will throw IllegalStateException. Once an object has been made read-only, it cannot be later set to read-write - this is a "one-way" operation.Note that a read-only object is not necessarily immutable; if reference types are returned from accessors, then callers could theoretically mutate those objects even if the top-level object is marked as read-only. The ability to make objects read-only is intended to catch programming errors (e.g. attempting to modify a data object passed as part of a SLEE event), not to provide an absolute guarantee of immutability.
Calling setReadOnly() on an object that is already read-only is a no-op.
Some DataObject implementations may be inherently immutable. In those cases, they are considered always read-only.
- Specified by:
setReadOnly
in interfaceDataObject
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:DataObject
Check if this object has been set read-only.- Specified by:
isReadOnly
in interfaceDataObject
- Returns:
- true if the object is read-only or inherently immutable
- See Also:
DataObject.setReadOnly()
-
checkModify
protected void checkModify()
Checks whether this DataObject is mutable.- Throws:
IllegalStateException
- if this DataObject is read-only
-
copyOf
public static ArrayDataObject<?> copyOf(ArrayDataObject<?> from)
Creates a new ArrayDataObject, initialising its value from that of the given ArrayDataObject.- Parameters:
from
- the object from which to copy- Returns:
- new ArrayDataObject
-
toString
public String toString()
Returns a printable representation of this. The printable representations of components are separated by commas and the whole is enclosed in braces, like ASN.1 value notation.- Overrides:
toString
in classAbstractCollection<T>
- Returns:
- String
-
equals
public boolean equals(Object obj)
Compares some other object to this one for equality by value.- Specified by:
equals
in interfaceCollection<T>
- Specified by:
equals
in interfaceList<T>
- Overrides:
equals
in classAbstractList<T>
- Parameters:
obj
- other object- Returns:
- boolean whether values are equal
-
hashCode
public int hashCode()
Gets a hash code value for this object.- Specified by:
hashCode
in interfaceCollection<T>
- Specified by:
hashCode
in interfaceList<T>
- Overrides:
hashCode
in classAbstractList<T>
- Returns:
- Arrays.deepHashCode(value)
-
-