|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.sido.common.AnnotatedSupport
net.sf.sido.array.Array<T>
T - Type of element in the arraypublic class Array<T>
The Array class represents an immutable and ordered collection. The only ways to update
such an Array is to create a new one, using operations like add(Array),
delete(int...), etc. that return other instances of arrays.
When an Array is created, it is associated with an ArrayEvent that defines the
list of events that have occured on a source to create this new array.
| Constructor Summary | |
|---|---|
|
Array(Collection<T> elements)
Constructor from a list or collection |
protected |
Array(Collection<T> elements,
ArrayEvent<T> event)
Protected constructor for event |
|
Array(T... elements)
Constructor from an array of elements |
| Method Summary | ||
|---|---|---|
Array<T> |
add(Array<T> elements)
Appends elements |
|
Array<T> |
add(Collection<T> elements)
Appends elements |
|
Array<T> |
add(T... elements)
Appends elements |
|
protected Array<T> |
createNewArray(List<T> newList,
ArrayEvent<T> event)
Creates a new instance of an array |
|
Array<T> |
delete(int... indexes)
Deletes one or several elements using their indexes. |
|
static
|
empty()
Creates an empty array. |
|
boolean |
equals(Object o)
|
|
Array<T> |
filter(com.google.common.base.Predicate<T> predicate)
Filters the array using a predicate |
|
T |
get(int index)
Gets an element using its index |
|
ArrayEvent<T> |
getArrayEvent()
Gets the ArrayEvent associated with this Array. |
|
T |
getAt(Integer index)
Same method than get(int) but is useable for script engines like Groovy. |
|
int |
getLength()
Length of this array |
|
T |
getOrNull(int index)
Gets an element using its index and returns null if the index is not available. |
|
int |
hashCode()
|
|
|
index(com.google.common.base.Function<T,K> indexer)
Returns an immutable index of the array using an indexing function. |
|
Array<T> |
insert(int position,
Collection<T> elements)
Appends elements at a given position |
|
Array<T> |
insert(int position,
T... items)
Appends elements at a given position |
|
boolean |
isEmpty()
Checks if this array is empty |
|
Iterator<T> |
iterator()
|
|
int |
length()
Length (short version) - synonym for getLength() |
|
Array<T> |
reverse()
Creates a reversed version of this array |
|
int |
size()
Length of this array. |
|
Array<T> |
sub(int startIndex,
int endIndex)
Sub array using a range between two indexes. |
|
List<T> |
toList()
Returns a list that contains all the elements of this array and in the same order. |
|
String |
toString()
String representation. |
|
|
transform(com.google.common.base.Function<? super T,V> transform)
Transforms an array in another array. |
|
Array<T> |
update(int index,
T newElement)
Updates an element with a new value |
|
| Methods inherited from class net.sf.sido.common.AnnotatedSupport |
|---|
getAnnotation, putAnnotation |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Array(Collection<T> elements)
elements - List of elements to build the array from. The final array is disconnected from the
initial list: modifying the list won't have any impact on the array.
protected Array(Collection<T> elements,
ArrayEvent<T> event)
public Array(T... elements)
elements - Array of elements to build this Array from.| Method Detail |
|---|
public static <V> Array<V> empty()
V - Type of element
public Array<T> add(Array<T> elements)
elements - Array of elements to add
Array, that contains this array's elements, plus the ones in
elementspublic Array<T> add(Collection<T> elements)
elements - Collection of elements to add
Array, that contains this array's elements, plus the ones in
elementspublic Array<T> add(T... elements)
elements - Array of elements to add
Array, that contains this array's elements, plus the ones in
elementspublic Array<T> delete(int... indexes)
indexes array
does not need to be sorted.
indexes - List of indexes to remove from the array.
Array the elements have been removed from. This new array will be
associated with an ArrayEvent that describes the deletion.public boolean equals(Object o)
equals in class Objectpublic Array<T> filter(com.google.common.base.Predicate<T> predicate)
predicate - Function that returns true for the elements that must be kept
Array the elements have been removed from. This new array will be
associated with an ArrayEvent that describes the deletion.public T get(int index)
index - Index of the element to get
IndexOutOfBoundsException - If the index is not validList.get(int)public ArrayEvent<T> getArrayEvent()
ArrayEvent associated with this Array.
ArrayEvent that describes the changes that have created this Arraypublic T getAt(Integer index)
get(int) but is useable for script engines like Groovy.
index - Index of the element to get
IllegalArgumentException - If index is nullget(int)public int getLength()
List.size(),
length()public int size()
length()public T getOrNull(int index)
null if the index is not available.
It still returns an IndexOutOfBoundsException if the index is less than 0.
index - Index of the element
nullpublic int hashCode()
hashCode in class Objectpublic <K> Map<K,T> index(com.google.common.base.Function<T,K> indexer)
K - Type for the index keyindexer - Function that extracts the index key from the elements in the array
public Array<T> insert(int position,
Collection<T> elements)
position - Position in the array to insert the new elements atelements - List of elements to insert at this position
Array where the elements have been inserted into. This new array will
be associated with an ArrayEvent that describes the insertion.
protected Array<T> createNewArray(List<T> newList,
ArrayEvent<T> event)
newList - List of elementsevent - Associated array of events
public Array<T> insert(int position,
T... items)
position - Position in the array to insert the new elements atitems - List of elements to insert at this position
Array where the elements have been inserted into. This new array will
be associated with an ArrayEvent that describes the insertion.public boolean isEmpty()
true is the array is empty, false otherwiseList.isEmpty()public Iterator<T> iterator()
iterator in interface Iterable<T>public int length()
getLength()
getLength()
public Array<T> sub(int startIndex,
int endIndex)
startIndex - Start indexendIndex - End index
Array instance that comprises only the elements between
startIndex and endIndex. An ArrayEvent is
associated with this array, which describes the operation.List.subList(int, int)public List<T> toList()
public String toString()
toString in class ObjectList#toString()public <V> Array<V> transform(com.google.common.base.Function<? super T,V> transform)
V - Type of the target elementtransform - Function that transforms each array element
Array instance that contains a transformed version of each element of this
array
public Array<T> update(int index,
T newElement)
index - Index to update the element atnewElement - Element to replace the initial element with
Array where the elements have been updated. This new array will be
associated with an ArrayEvent that describes the update.public Array<T> reverse()
Collections.reverse(java.util.List)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||