public class CollectionUtil extends Object
Collection
instances.コンストラクタと説明 |
---|
CollectionUtil()
CollectionUtil should not normally be instantiated. |
修飾子とタイプ | メソッドと説明 |
---|---|
static void |
addAll(Collection collection,
Enumeration enumeration)
Adds all elements in the enumeration to the given collection.
|
static void |
addAll(Collection collection,
Iterator iterator)
Adds all elements in the iteration to the given collection.
|
static void |
addAll(Collection collection,
Object[] elements)
Adds all elements in the array to the given collection.
|
static boolean |
addIgnoreNull(Collection collection,
Object object)
Adds an element to the collection unless the element is null.
|
static boolean |
containsAny(Collection coll1,
Collection coll2)
Returns
true iff at least one element is in both collections. |
static Collection |
disjunction(Collection a,
Collection b)
Returns a
Collection containing the exclusive disjunction (symmetric difference) of the given Collection
s. |
static Object |
get(Object object,
int index)
Returns the
index -th value in object , throwing IndexOutOfBoundsException if there
is no such element or IllegalArgumentException if object is not an instance of one of the
supported types. |
static Map |
getCardinalityMap(Collection coll)
Returns a
Map mapping each unique element in the given Collection to an Integer representing the
number of occurrences of that element in the Collection . |
static Object |
index(Object obj,
int idx)
非推奨です。
use
get(Object, int) instead. Will be removed in v4.0 |
static Object |
index(Object obj,
Object index)
非推奨です。
use
get(Object, int) instead. Will be removed in v4.0 |
static Collection |
intersection(Collection a,
Collection b)
Returns a
Collection containing the intersection of the given Collection s. |
static boolean |
isEmpty(Collection coll)
Null-safe check if the specified collection is empty.
|
static boolean |
isEqualCollection(Collection a,
Collection b)
Returns true iff the given
Collection s contain exactly the same elements with exactly the same
cardinalities. |
static boolean |
isNotEmpty(Collection coll)
Null-safe check if the specified collection is not empty.
|
static boolean |
isProperSubCollection(Collection a,
Collection b)
Returns true iff a is a proper sub-collection of b, that is, iff the cardinality of
e in a is less than or equal to the cardinality of e in b, for each element e in
a, and there is at least one element f such that the cardinality of f in b is strictly
greater than the cardinality of f in a.
|
static boolean |
isSubCollection(Collection a,
Collection b)
Returns true iff a is a sub-collection of b, that is, iff the cardinality of e in a
is less than or equal to the cardinality of e in b, for each element e in a.
|
static void |
reverseArray(Object[] array)
Reverses the order of the given array.
|
static int |
size(Object object)
Gets the size of the collection/iterator specified.
|
static boolean |
sizeIsEmpty(Object object)
Checks if the specified collection/array/iterator is empty.
|
static Collection |
subtract(Collection a,
Collection b)
Returns a new
Collection containing a - b. |
static Collection |
union(Collection a,
Collection b)
Returns a
Collection containing the union of the given Collection s. |
public CollectionUtil()
CollectionUtil
should not normally be instantiated.public static Collection union(Collection a, Collection b)
Collection
containing the union of the given Collection
s.
The cardinality of each element in the returned Collection
will be equal to the maximum of the cardinality of
that element in the two given Collection
s.
a
- the first collection, must not be nullb
- the second collection, must not be nullCollection.addAll(java.util.Collection<? extends E>)
public static Collection intersection(Collection a, Collection b)
Collection
containing the intersection of the given Collection
s.
The cardinality of each element in the returned Collection
will be equal to the minimum of the cardinality of
that element in the two given Collection
s.
a
- the first collection, must not be nullb
- the second collection, must not be nullCollection.retainAll(java.util.Collection<?>)
,
containsAny(java.util.Collection, java.util.Collection)
public static Collection disjunction(Collection a, Collection b)
Collection
containing the exclusive disjunction (symmetric difference) of the given Collection
s.
The cardinality of each element e in the returned Collection
will be equal to
max(cardinality(e,a),cardinality(e,b)) - min(cardinality(e,a),cardinality(e,b)).
This is equivalent to
subtract
(union(a,b)
,intersection(a,b)
) or
union
(subtract(a,b)
,subtract(b,a)
).
a
- the first collection, must not be nullb
- the second collection, must not be nullpublic static Collection subtract(Collection a, Collection b)
Collection
containing a - b. The cardinality of each element e in the
returned Collection
will be the cardinality of e in a minus the cardinality of e in
b, or zero, whichever is greater.a
- the collection to subtract from, must not be nullb
- the collection to subtract, must not be nullCollection.removeAll(java.util.Collection<?>)
public static boolean containsAny(Collection coll1, Collection coll2)
true
iff at least one element is in both collections.
In other words, this method returns true
iff the intersection(java.util.Collection, java.util.Collection)
of coll1 and coll2 is
not empty.
coll1
- the first collection, must not be nullcoll2
- the first collection, must not be nulltrue
iff the intersection of the collections is non-emptyintersection(java.util.Collection, java.util.Collection)
public static Map getCardinalityMap(Collection coll)
Map
mapping each unique element in the given Collection
to an Integer
representing the
number of occurrences of that element in the Collection
.
Only those elements present in the collection will appear as keys in the map.
coll
- the collection to get the cardinality map for, must not be nullpublic static boolean isSubCollection(Collection a, Collection b)
a
- the first (sub?) collection, must not be nullb
- the second (super?) collection, must not be nulltrue
iff a is a sub-collection of bisProperSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection<?>)
public static boolean isProperSubCollection(Collection a, Collection b)
The implementation assumes
a.size()
and b.size()
represent the total cardinality of a and b, resp.a.size() < Integer.MAXVALUE
a
- the first (sub?) collection, must not be nullb
- the second (super?) collection, must not be nulltrue
iff a is a proper sub-collection of bisSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection<?>)
public static boolean isEqualCollection(Collection a, Collection b)
Collection
s contain exactly the same elements with exactly the same
cardinalities.
That is, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.
a
- the first collection, must not be nullb
- the second collection, must not be nulltrue
iff the collections contain the same elements with the same cardinalities.public static boolean addIgnoreNull(Collection collection, Object object)
collection
- the collection to add to, must not be nullobject
- the object to add, if null it will not be addedNullPointerException
- if the collection is nullpublic static void addAll(Collection collection, Iterator iterator)
collection
- the collection to add to, must not be nulliterator
- the iterator of elements to add, must not be nullNullPointerException
- if the collection or iterator is nullpublic static void addAll(Collection collection, Enumeration enumeration)
collection
- the collection to add to, must not be nullenumeration
- the enumeration of elements to add, must not be nullNullPointerException
- if the collection or enumeration is nullpublic static void addAll(Collection collection, Object[] elements)
collection
- the collection to add to, must not be nullelements
- the array of elements to add, must not be nullNullPointerException
- if the collection or array is null@Deprecated public static Object index(Object obj, int idx)
get(Object, int)
instead. Will be removed in v4.0obj
- the object to get an index of, may be nullidx
- the index to getIndexOutOfBoundsException
ArrayIndexOutOfBoundsException
@Deprecated public static Object index(Object obj, Object index)
get(Object, int)
instead. Will be removed in v4.0obj
- the object to get an index ofindex
- the index to getIndexOutOfBoundsException
ArrayIndexOutOfBoundsException
public static Object get(Object object, int index)
index
-th value in object
, throwing IndexOutOfBoundsException
if there
is no such element or IllegalArgumentException
if object
is not an instance of one of the
supported types.
The supported types, and associated semantics are:
Map.Entry
in position index
in the map's
entrySet
iterator, if there is such an entry.index
-th array entry is returned, if there is such an entry; otherwise an
IndexOutOfBoundsException
is thrown.index
-th object returned by the collection's default iterator,
if there is such an element.index
-th object in the Iterator/Enumeration, if
there is such an element. The Iterator/Enumeration is advanced to index
(or to the end, if
index
exceeds the number of entries) as a side effect of this method.object
- the object to get a value fromindex
- the index to getIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if the object type is invalidpublic static int size(Object object)
This method can handles objects as follows
object
- the object to get the size ofIllegalArgumentException
- thrown if object is not recognised or nullpublic static boolean sizeIsEmpty(Object object)
This method can handles objects as follows
Note: This method is named to avoid clashing with isEmpty(Collection)
.
object
- the object to get the size of, not nullIllegalArgumentException
- thrown if object is not recognised or nullpublic static boolean isEmpty(Collection coll)
Null returns true.
coll
- the collection to check, may be nullpublic static boolean isNotEmpty(Collection coll)
Null returns false.
coll
- the collection to check, may be nullpublic static void reverseArray(Object[] array)
array
- the array to reverseCopyright © 2012 NTT DATA INTRAMART CORPORATION