public final class Containers extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Set<T> |
asHashSet(T[] array)
Returns a set backed by the given array (i.e.
|
static <T> Set<T> |
asIdentitySet(T[] array)
Returns an identity set backed by the given array (i.e.
|
static <T> T[] |
copy(T[] src,
int srcPos,
T[] dest,
int destPos,
int length)
Calls System.arraycopy(src, srcPos, dest, destPos, length) and returns the destination array.
|
static <T> T[] |
copy(T[] src,
T[] dest)
Calls System.arraycopy(src, 0, dest, 0, src.length) and returns the destination array.
|
static <T> Iterator<T> |
emptyIterator()
Returns an iterator that has no elements.
|
static int |
hashBinarySearch(Object[] array,
Object key)
Searches the specified array for the specified object using the binary search algorithm
and object equality.
|
static Comparator<Object> |
hashComparator()
Returns a comparator that compares objects according to their
hashcodes . |
static <T> T[] |
hashSort(T[] array)
Calls
Arrays.sort(Object[], Comparator) on the
given array and returns it. |
static int |
identityBinarySearch(Object[] array,
Object key)
Searches the specified array for the specified object using the binary search algorithm
and reference equality.
|
static Comparator<Object> |
identityComparator()
Returns a comparator that compares objects according to their
identity hashcodes . |
static <T> T[] |
identitySort(T[] array)
Calls
Arrays.sort(Object[], Comparator) on the
given array and returns it. |
static <T,E extends T> |
iterate(E... items)
Returns a new iterator over the given array of items.
|
static <T,E extends T> |
iterate(int start,
int end,
E... items)
Returns a new iterator over the given array of items.
|
static <T> Set<T> |
setDifference(Set<T> left,
Set<T> right)
Returns a new set that contains the asymmetric difference between the left and the right sets.
|
public static final <T> Set<T> asHashSet(T[] array)
hashSort(Object[])
), and its contents
must not be changed while it is in use by the returned set.all i, j: [0..array.length) | i < j => array[i].hashCode() <= array[j].hashCode
public static final <T> Set<T> asIdentitySet(T[] array)
identitySort(Object[])
), and its contents
must not be changed while it is in use by the returned set.all i, j: [0..array.length) | i < j => System.identityHashCode(array[i]) <= System.identityHashCode(array[j])
public static final <T> T[] copy(T[] src, int srcPos, T[] dest, int destPos, int length)
System.arraycopy(src, srcPos, dest, destPos, length)
public static final <T> T[] copy(T[] src, T[] dest)
dest.length >= src.length
System.arraycopy(src, 0, dest, 0, src.length)
public static final <T> Iterator<T> emptyIterator()
public static final int hashBinarySearch(Object[] array, Object key)
hashSort(Object[])
) prior to making this call. If it is not sorted,
the results are undefined. If the array contains multiple occurences of the specified object,
there is no guarantee which one will be found.all i, j: [0..array.length) | i < j => System.identityHashCode(array[i]) <= System.identityHashCode(array[j])
public static final Comparator<Object> hashComparator()
hashcodes
. The null reference is
considered to have a hashcode of 0.hashcodes
.public static final <T> T[] hashSort(T[] array)
Arrays.sort(Object[], Comparator)
on the
given array and returns it. The elements are sorted in the ascending
order of their hashcodes.java.util.Arrays.sort(array, hashComparator()
)
public static final int identityBinarySearch(Object[] array, Object key)
identitySort(Object[])
) prior to making this call. If it is not sorted,
the results are undefined. If the array contains multiple occurences of the specified object,
there is no guarantee which one will be found.all i, j: [0..array.length) | i < j => array[i].hashCode() <= array[j].hashCode())
public static final Comparator<Object> identityComparator()
identity hashcodes
.identity hashcodes
.public static final <T> T[] identitySort(T[] array)
Arrays.sort(Object[], Comparator)
on the
given array and returns it. The elements are sorted in the ascending
order of their identity hashcodes.java.util.Arrays.sort(array, identityComparator()
)
@SafeVarargs public static final <T,E extends T> Iterator<T> iterate(E... items)
NullPointerException
- items = null@SafeVarargs public static final <T,E extends T> Iterator<T> iterate(int start, int end, E... items)
NullPointerException
- items = nullIllegalArgumentException
- start < end && (start < 0 || end > items.length) ||
start > end && (start >= items.length || end < -1)
© Emina Torlak 2005-present