java.lang.Objectjavax.baja.nre.util.Array
Array is a dynamic array similar to Vector or ArrayList except that it stores its elements in an array of a specific type. This provides fail fast capability when adding items of the wrong type and is easy to use when converting back to a Java array.
| Constructor Summary | |
Array()
Convenience for Array(Object.class, 10) |
|
Array(java.lang.Class ofClass)
Convenience for Array(ofClass, 10) |
|
Array(java.lang.Class ofClass,
java.util.Collection c)
Construct an Array using Collection.toArray() |
|
Array(java.lang.Class ofClass,
int capacity)
Create an array of the specified type. |
|
Array(java.util.Collection c)
Convenience for Array(Object.class, c) |
|
Array(java.lang.Object[] array)
Convenience for Array(array, array.length) |
|
Array(java.lang.Object[] array,
int size)
Construct an Array to use the specified array as the initial internal array including its contents. |
|
| Method Summary | |
void |
add(int index,
java.lang.Object item)
Add the item at the specified index. |
boolean |
add(java.lang.Object item)
Add the item to the end of this array. |
void |
addAll(Array array)
Convenience for add(array.array(), array.size()). |
void |
addAll(java.util.Collection c)
Add all the items from the collection to this array. |
void |
addAll(java.lang.Object[] array)
Convenience for add(array, array.length). |
void |
addAll(java.lang.Object[] array,
int size)
Add all the items from array[0] to array[size-1]. |
Array |
apply(java.lang.Class resultOf,
ILambda lambda)
Return a new Array where the items are the result of applying the lambda function to all this Array's items. |
Array |
apply(ILambda lambda)
Convenience for apply(null, lambda). |
java.lang.Object[] |
array()
Get a direct reference to the internal array. |
void |
clear()
Remove all the items. |
boolean |
contains(java.lang.Object item)
Return if this array contains the specified item using equals(). |
Array |
copy()
Return a shallow copy of this array. |
Array |
copy(int beginIndex)
Returns a new Array that is a subsequence of this Array. |
Array |
copy(int beginIndex,
int endIndex)
Returns a new Array that is a subsequence of this Array. |
boolean |
equals(java.lang.Object o)
Compare another Array for equality. |
Array |
filter(IFilter filter)
Return a new Array with this Array's items which return true for filter.include(). |
Array |
filterNull()
Return a new Array with all the null items filtered out. |
java.lang.Object |
first()
Get the item at index 0 or return null if empty. |
java.lang.Object |
get(int index)
Get the item at the specified index. |
void |
grow(int length)
Grow the array to ensure the specified length. |
int |
indexOf(java.lang.Object item)
Return the index of the specified object using equals(), or -1 if not in this array. |
int |
indexOf(java.lang.Object item,
int fromIndex)
Return the index of the specified object using equals(), or -1 if not in this array, starting the search at the specified index. |
Array |
intersection(java.lang.Object[] items)
Return a new Array that contains the intersection of this Array's contents and the specified items. |
boolean |
isEmpty()
Return if size is zero. |
java.util.ListIterator |
iterator()
Return an instance of ListIterator to iterator through the items in the array. |
java.lang.Object |
last()
Get the item at index size-1 or return null if empty. |
int |
lastIndexOf(java.lang.Object item)
Return the rightmost index of the specified object using equals(), or -1 if not in this array, searching backwards starting at size() - 1. |
int |
lastIndexOf(java.lang.Object item,
int fromIndex)
Return the rightmost index of the specified object using equals(), or -1 if not in this array, searching backwards starting at the specified index. |
java.util.List |
list()
Return a modifiable List which wraps this Array. |
java.lang.Class |
ofClass()
Get the Class type of the items in this array. |
java.lang.Object |
peek()
Convenience for get(size()-1) when
working with the array as a stack. |
java.lang.Object |
pop()
Convenience for remove(size()-1) when
working with the array as a stack. |
void |
push(java.lang.Object item)
Convenience for add(item) when working
with the array as a stack. |
java.lang.Object |
remove(int index)
Remove the item at the specified index and return it. |
boolean |
remove(java.lang.Object item)
If the item is in this array using indexOf() then remove it and return true. |
Array |
removeAll(java.lang.Object[] items)
Return a new Array having this Array's contents, with all the specified items filtered out. |
void |
removeRange(int fromIndex,
int toIndex)
Remove from this Array all of the items whose index is between fromIndex, inclusive and toIndex, exclusive. |
Array |
reverse()
Return a new Aray with the order of the items reversed. |
Array |
rsort()
Return a new Array with the items sorted in descending order using SortUtil. |
java.lang.Object |
set(int index,
java.lang.Object item)
Replace the item at the specified index and return the old item. |
int |
size()
Return the number of items in the array. |
Array |
slice(int fromIndex,
int toIndex)
Returns a new Array that is a shallow copy of the portion of this Array that lies between fromIndex, inclusive, and toIndex, exclusive. |
Array |
sort()
Return a new Array with the items sorted in ascending order using SortUtil. |
Array |
sort(java.util.Comparator comparator)
Return a new Array with the items sorted using specified Comparator. |
void |
swap(int i1,
int i2)
Swap two items in the array. |
java.lang.String |
toString()
Return a string representation of the Array. |
java.lang.Object[] |
trim()
Trim the internal array to size() and get a direct reference to it. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Array()
Array(Object.class, 10)
public Array(java.lang.Class ofClass)
Array(ofClass, 10)
public Array(java.lang.Class ofClass,
int capacity)
public Array(java.lang.Object[] array)
Array(array, array.length)
public Array(java.lang.Object[] array,
int size)
public Array(java.lang.Class ofClass,
java.util.Collection c)
Collection.toArray()
public Array(java.util.Collection c)
Array(Object.class, c)
| Method Detail |
public final java.lang.Class ofClass()
array().getClass().getComponentType().
public final java.lang.Object get(int index)
public final int indexOf(java.lang.Object item)
public final int indexOf(java.lang.Object item,
int fromIndex)
public final int lastIndexOf(java.lang.Object item)
public final int lastIndexOf(java.lang.Object item,
int fromIndex)
public final boolean contains(java.lang.Object item)
public final int size()
public final boolean isEmpty()
public boolean equals(java.lang.Object o)
public java.lang.String toString()
public final boolean add(java.lang.Object item)
public final void add(int index,
java.lang.Object item)
public final void addAll(java.lang.Object[] array)
add(array, array.length).
public final void addAll(Array array)
add(array.array(), array.size()).
public final void addAll(java.lang.Object[] array,
int size)
public final void addAll(java.util.Collection c)
public final java.lang.Object set(int index,
java.lang.Object item)
public final java.lang.Object remove(int index)
public final boolean remove(java.lang.Object item)
public Array removeAll(java.lang.Object[] items)
public final void removeRange(int fromIndex,
int toIndex)
fromIndex - index of first item to be removed.toIndex - index after last item to be removed.
public Array slice(int fromIndex,
int toIndex)
fromIndex - low endpoint (inclusive) of the slice.toIndex - high endpoint (exclusive) of the slice.public Array intersection(java.lang.Object[] items)
public final void push(java.lang.Object item)
add(item) when working
with the array as a stack.
public final java.lang.Object pop()
remove(size()-1) when
working with the array as a stack.
public final java.lang.Object peek()
get(size()-1) when
working with the array as a stack.
public final java.lang.Object first()
public final java.lang.Object last()
public final void grow(int length)
public final java.lang.Object[] array()
public final java.lang.Object[] trim()
public final void clear()
public final java.util.ListIterator iterator()
public final java.util.List list()
public void swap(int i1,
int i2)
public Array copy()
public Array copy(int beginIndex)
public Array copy(int beginIndex,
int endIndex)
public Array filter(IFilter filter)
filter.include().
For example to filter out Strings of length 0:
a = a.filter(new IFilter()
{
public boolean accept(Object o) { return o.toString().length() > 0; }
});
public Array filterNull()
public Array apply(java.lang.Class resultOf,
ILambda lambda)
a = a.apply(null, new ILambda()
{
public Object eval(Object o) { return o.toString().toLowerCase(); }
});
The resultOf parameter specifies the ofClass of the new
array. If resultOf is null then the new array of the
same class as this array.
public Array apply(ILambda lambda)
apply(null, lambda).
public Array sort(java.util.Comparator comparator)
public Array sort()
public Array rsort()
public Array reverse()
Copyright © 2000-2016 Tridium Inc. All rights reserved.