list and sexp types.Warning
This interface should not be implemented or extended by code outside of this library.
Ion sequences implement the standard Java List interface, behaving
generally as expected, with the following exceptions:
remove(Object) do not use Object#equals as
specified by the contract of java.util.Collection .
Instead they use reference equality (== operator) to find the
given instance.
IonValue instance may be a child of at most one
IonContainer. Instances may be children of any number of
non-Ion Collections.
List#equals(Object)} and
List#hashCode() does not conform to the specification of those
methods in order to conform with Ion's definition of equality which
takes into account the IonSequence's IonType and its
annotations in addition to the contents of the collection.
List#equals(Object) always returns false
for any non-IonSequence implementation of List,
including the sub-list returned from
IonSequence#subList(int, int).
List#hashCode() returns a different hash code than
other List#hashCode() implementations. including the
sub-list returned from IonSequence#subList(int, int).
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(IonValue
is the value to be appended to this sequence. child)Redeclares java. Appends a child value to the end of this sequence. |
| public ValueFactory | |
| public void | add(int
index at which the specified element is to be inserted index, IonValue is the element to be appended to this sequence. child)Redeclares java. Inserts a child value at the specified position in this sequence. |
| public ValueFactory | add(int
element to be appended to this list index)Redeclares java. Provides a factory that when invoked constructs a new value and
|
| public boolean | Returns: true if this sequence changed as a result of the call.elements to be appended to this sequence. c)Redeclares java. Appends all of the elements in the specified collection to the end of this sequence, in the order that they are returned by the collection's iterator. |
| public boolean | Returns: true if this sequence changed as a result of the call.index at which to insert first element from the specified collection. index, Collection<? extends IonValue> elements to be inserted into this sequence. c)Redeclares java. Inserts all of the elements in the specified collection into this sequence at the specified position. |
| public IonSequence | clone()
Redeclares com. Creates a copy of this value and all of its children. |
| public boolean | Returns: true if o is an element of this sequence.element whose presence in this list is to be tested o)Redeclares java. Determines whether this sequence contains the given instance. |
| public boolean | Returns: true if this sequence contains all of the elements of
the given collection.collection to be checked for containment in this list c)Redeclares java. Determines whether this sequence contains all of the given instances. |
| public <T extends IonValue> T[] | |
| public IonValue | Returns: the element at the given index; notnull.identifies the element to return. index)Redeclares java. Returns the element at the specified position in this sequence. |
| public int | Returns: the index in this sequence of the element, or -1 if this sequence doesn't contain the element.the element to search for. o)Redeclares java. Returns the index in the sequence of the specified element, or -1 if this sequence doesn't contain the element. |
| public int | Returns: the index in this sequence of the element, or -1 if this sequence doesn't contain the element.the element to search for. o)Redeclares java. Returns the index in the sequence of the specified element, or -1 if this sequence doesn't contain the element. |
| public ListIterator | listIterator()
Redeclares java. Returns a list iterator of the elements in this sequence (in proper order). |
| public ListIterator | listIterator(int
index of first element to be returned from the list iterator (by a call
to the index)next method).Redeclares java. Returns a list iterator of the elements in this sequence (in proper order), starting at the specified position in this sequence. |
| public IonValue | Returns: the element previously at the specified position.the index of the element to be removed. index)Redeclares java. Removes the element at the specified position. |
| public boolean | Returns: true if this sequence changed as a result of the call.element to be removed from this list, if present o)Redeclares java. Removes a given |
| public boolean | Returns: true if this sequence changed as a result of the call.collection containing elements to be removed from this list c)Redeclares java. Removes all elements from this sequence that are also contained in the specified collection. |
| public boolean | Returns: true if this sequence changed as a result of the call.collection containing elements to be retained in this list c)Redeclares java. Retains only the elements in this sequence that are also contained in the specified collection. |
| public IonValue | Returns: the element previously at the specified index.index of the element to replace. index, IonValue element to be stored at the specified position. element)Redeclares java. Replaces the element at the specified position in this list with the specified element. |
| public List | subList(int
low endpoint (inclusive) of the subList fromIndex, int high endpoint (exclusive) of the subList toIndex)Redeclares java.
Returns a view of the portion of this list according to
|
| public IonValue[] | Returns: an array containing all of the elements in this sequence in proper order.Redeclares java. Returns an array containing all of the elements in this sequence in proper order. |
| public <T> T[] | Returns: an array containing all of the elements in this sequence in proper order.the array into which the elements of this sequence are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose. a)Redeclares java. Returns an array containing all of the elements in this sequence in proper order; the runtime type of the returned array is that of the specified array. |
| add | back to summary |
|---|---|
| public boolean add(IonValue child) throws ContainedValueException, NullPointerException Redeclares java. Appends a child value to the end of this sequence.
If
| |
| add | back to summary |
|---|---|
| public ValueFactory add() Provides a factory that when invoked constructs a new value and
These two lines are equivalent:
seq.add().newInt(3);
seq.add(seq.getSystem().newInt(3));
| |
| add | back to summary |
|---|---|
| public void add(int index, IonValue child) throws ContainedValueException, NullPointerException Redeclares java. Inserts a child value at the specified position in this sequence.
If
| |
| add | back to summary |
|---|---|
| public ValueFactory add(int index) Redeclares java. Provides a factory that when invoked constructs a new value and
These two lines are equivalent:
seq.add(12).newInt(3);
seq.add(12, seq.getSystem().newInt(3));
The given
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(Collection<? extends IonValue> c) Redeclares java. Appends all of the elements in the specified collection to the end of this sequence, in the order that they are returned by the collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this sequence, and it's nonempty.)
Since Ion values can only have a single parent, this method will fail if
the given collection is a non-empty
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(int index, Collection<? extends IonValue> c) Redeclares java. Inserts all of the elements in the specified collection into this sequence at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this sequence in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this sequence, and it's nonempty.)
Since Ion values can only have a single parent, this method will fail if
the given collection is a non-empty
| |
| clone | back to summary |
|---|---|
| public IonSequence clone() throws UnknownSymbolException Redeclares com. Doc from com. Creates a copy of this value and all of its children. The cloned value
may use the same shared symbol tables, but it will have an independent local
symbol table if necessary. The cloned value will
be modifiable regardless of whether this instance
The cloned value will be created in the context of the same
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Redeclares java. Determines whether this sequence contains the given instance.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(Collection<?> c) Redeclares java. Determines whether this sequence contains all of the given instances.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| extract | back to summary |
|---|---|
| public <T extends IonValue> T[] extract(Class<T> type) Removes all children of this sequence, returning them in an array. This is much more efficient than iterating the sequence and removing children one by one.
| |
| get | back to summary |
|---|---|
| public IonValue get(int index) throws NullValueException, IndexOutOfBoundsException Redeclares java. Returns the element at the specified position in this sequence.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(Object o) Redeclares java. Returns the index in the sequence of the specified element, or -1 if this sequence doesn't contain the element.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(Object o) Redeclares java. Returns the index in the sequence of the specified element, or -1 if this sequence doesn't contain the element.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| listIterator | back to summary |
|---|---|
| public ListIterator Redeclares java. Returns a list iterator of the elements in this sequence (in proper order).
The result does not support
| |
| listIterator | back to summary |
|---|---|
| public ListIterator Redeclares java. Returns a list iterator of the elements in this sequence (in proper order), starting at the specified position in this sequence.
The result does not support
| |
| remove | back to summary |
|---|---|
| public IonValue remove(int index) Redeclares java. Removes the element at the specified position. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
| |
| remove | back to summary |
|---|---|
| public boolean remove(Object o) Redeclares java. Removes a given
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(Collection<?> c) Redeclares java. Removes all elements from this sequence that are also contained in the specified collection. After this call returns, this sequence will contain no elements in common with the specified collection.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(Collection<?> c) Redeclares java. Retains only the elements in this sequence that are also contained in the specified collection. In other words, removes from this sequence all of its elements that are not contained in the specified collection.
Due to the reference-equality-based semantics of Ion sequences,
this method does not use
| |
| set | back to summary |
|---|---|
| public IonValue set(int index, IonValue element) Redeclares java. Replaces the element at the specified position in this list with the specified element.
| |
| subList | back to summary |
|---|---|
| public List Redeclares java.
Returns a view of the portion of this list according to
Sublist methods will throw a
List<IonValue> returned by this method
implements List#equals(Object) and
List#equals(Object) ()} per the specification of these methods.
However, the existing implementation of IonSequence does not
provide a specification compliant List#equals and
List#hashCode()} which results to the following caveats:
Given:
int[] ints = new int[] {1, 2, 3, 4};
IonList list = SYSTEM.newList(ints);
IonSexp sexp = SYSTEM.newSexp(ints)
IonSexp dgrm = SYSTEM.newDatagram(ints)
List
IonSequence#equals(Object) always returns false when presented
with a non IonSequence instance of List<IonValue>.
Hence, the following invocations of Object#equals(Object)
return false even if the contained elements are equivalent. This
means that Object#equals(Object) is not symmetric in these
cases. The reason for the asymmetry is historical:
IonSequence has long violated the contract outlined by the
List documentation. For the current major version of this
library we maintain backwards compatibility and support this behaviour
as-is.
list.equals(listSubList) // false
list.equals(sexpSubList) // false
list.equals(dgrm) // false
list.equals(arrayList) // false
sexp.equals(listSubList) // false
sexp.equals(sexpSubList) // false
sexp.equals(dgrm) // false
sexp.equals(arrayList) // false
dgrm.equals(listSubList) // false
dgrm.equals(sexpSubList) // false
dgrm.equals(dgrmSubList) // false
dgrm.equals(arrayList) // false
However, IonSequence#subList(int, int) was implemented much
later and faithfully implements List#equals(Object) meaning
the cases below all work as expected. While IonSequence
does not comply with the specification for List#equals(Object)
because it has to comply with Ion's rules for equality, the same is
not true for sub-lists. Unlike IonSequence, sub-lists have
no notion of an IonType, annotations or nullability which
allows for compliance with the List specification.
listSubList.equals(listSubList); // true
listSubList.equals(sexpSubList); // true
listSubList.equals(dgrmSubList); // true
listSubList.equals(list); // true
listSubList.equals(sexp); // true
listSubList.equals(arrayList); // true
sexpSubList.equals(listSubList); // true
sexpSubList.equals(sexpSubList); // true
sexpSubList.equals(dgrmSubList); // true
sexpSubList.equals(list); // true
sexpSubList.equals(sexp); // true
sexpSubList.equals(arrayList); // true
dgrmSubList.equals(listSubList); // true
dgrmSubList.equals(sexpSubList); // true
dgrmSubList.equals(dgrmSubList); // true
dgrmSubList.equals(list); // true
dgrmSubList.equals(sexp); // true
dgrmSubList.equals(arrayList); // true
| |
| toArray | back to summary |
|---|---|
| public IonValue[] toArray() Redeclares java. Returns an array containing all of the elements in this sequence in
proper order. Obeys the general contract of the
If this sequence is an Ion null value, it will behave like an empty sequence.
| |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(T[] a) Redeclares java. Returns an array containing all of the elements in this sequence in
proper order; the runtime type of the returned array is that of the
specified array. Obeys the general contract of the
If this sequence is an Ion null value, it will behave like an empty sequence.
| |