Package com.ibm.icu.dev.util
Class CollectionUtilities
java.lang.Object
com.ibm.icu.dev.util.CollectionUtilities
Utilities that ought to be on collections, but aren't
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
For producing filtered iteratorsstatic class
Reverse a matchstatic class
CollectionUtilities.MapComparator<K extends Comparable,
V extends Comparable> static interface
Matches item.static class
static class
static class
CollectionUtilities.SetComparator<T extends Comparable>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelationstatic final int
Used for results of getContainmentRelation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
U extends Collection<T>>
UAdd all items in iterator to target collectionstatic <T> Map
<T, T> asMap
(T[][] source) static <T> Map
<T, T> Utility like Arrays.asList()static <T extends Comparable>
intCompare iteratorsstatic <T extends Comparable>
intcompare
(T a, T b) Compare, allowing nulls and putting them firststatic <T extends Comparable,
U extends Collection<T>>
intcompare
(U o1, U o2) Compare, with shortest first, and otherwise lexicographicallystatic <K extends Comparable,
V extends Comparable, T extends Map.Entry<K, V>>
intcompareEntrySets
(Collection<T> o1, Collection<T> o2) static boolean
containsAll
(Collection a, Collection b) static boolean
containsNone
(Collection a, Collection b) static boolean
containsSome
(Collection a, Collection b) static <T> boolean
equals
(T a, T b) Compare, allowing nullsstatic <T,
U extends Collection<T>>
TgetBest
(U c, Comparator<T> comp, int direction) Get the "best" in collection.static int
Assesses all the possible containment relations between collections A and B with one call.
Returns an int with bits set, according to a "Venn Diagram" view of A vs B.
NOT_A_SUPERSET_B: a - b != {}
NOT_A_DISJOINT_B: a * b != {} // * is intersects
NOT_A_SUBSET_B: b - a != {}
Thus the bits can be used to get the following relations:
for A_SUPERSET_B, use (x invalid input: '&' CollectionUtilities.NOT_A_SUPERSET_B) == 0
for A_SUBSET_B, use (x invalid input: '&' CollectionUtilities.NOT_A_SUBSET_B) == 0
for A_EQUALS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_EQUALS_B) == 0
for A_DISJOINT_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) == 0
for A_OVERLAPS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) != 0<T,
U extends Collection<T>>
TgetFirst
(U c) Get first item in collection, or null if there is none.static <T> String
Join an array of items.Join a collection of items.static int
matchesAt
(CharSequence text, int offset, CharSequence other) Does one string contain another, starting at a specific offset?static <K,
V> Map <K, V> removeAll
(Map<K, V> m, Collection<K> itemsToRemove) Utility that ought to be on Mapstatic <T,
U extends Collection<T>>
UremoveAll
(U c, CollectionUtilities.ObjectMatcher<T> f) Remove matching itemsstatic <T,
U extends Collection<T>>
UretainAll
(U c, CollectionUtilities.ObjectMatcher<T> f) Retain matching itemsstatic int
Get the size of an iterator (number of items in it).
-
Field Details
-
ALL_EMPTY
public static final int ALL_EMPTYUsed for results of getContainmentRelation- See Also:
-
NOT_A_SUPERSET_B
public static final int NOT_A_SUPERSET_BUsed for results of getContainmentRelation- See Also:
-
NOT_A_DISJOINT_B
public static final int NOT_A_DISJOINT_BUsed for results of getContainmentRelation- See Also:
-
NOT_A_SUBSET_B
public static final int NOT_A_SUBSET_BUsed for results of getContainmentRelation- See Also:
-
NOT_A_EQUALS_B
public static final int NOT_A_EQUALS_BUsed for results of getContainmentRelation- See Also:
-
A_PROPER_SUBSET_OF_B
public static final int A_PROPER_SUBSET_OF_BUsed for results of getContainmentRelation- See Also:
-
A_PROPER_SUPERSET_B
public static final int A_PROPER_SUPERSET_BUsed for results of getContainmentRelation- See Also:
-
A_PROPER_OVERLAPS_B
public static final int A_PROPER_OVERLAPS_BUsed for results of getContainmentRelation- See Also:
-
-
Constructor Details
-
CollectionUtilities
public CollectionUtilities()
-
-
Method Details
-
join
Join an array of items.- Type Parameters:
T
-- Parameters:
array
-separator
-- Returns:
- string
-
join
Join a collection of items.- Type Parameters:
T
-U
-- Parameters:
collection
-separator
-array
-- Returns:
- string
-
asMap
Utility like Arrays.asList()- Type Parameters:
T
-- Parameters:
source
-target
-reverse
-- Returns:
-
addAll
Add all items in iterator to target collection- Type Parameters:
T
-U
-- Parameters:
source
-target
-- Returns:
-
size
Get the size of an iterator (number of items in it).- Parameters:
source
-- Returns:
-
asMap
- Type Parameters:
T
-- Parameters:
source
-- Returns:
-
removeAll
Utility that ought to be on Map- Type Parameters:
K
-V
-- Parameters:
m
-itemsToRemove
-- Returns:
- map passed in
-
getFirst
Get first item in collection, or null if there is none.- Type Parameters:
T
-U
-- Parameters:
c
-- Returns:
- first item
-
getBest
Get the "best" in collection. That is the least if direction is invalid input: '<' 0, otherwise the greatest. The first is chosen if there are multiples.- Type Parameters:
T
-U
-- Parameters:
c
-comp
-direction
-- Returns:
-
removeAll
Remove matching items- Type Parameters:
T
-U
-- Parameters:
c
-f
-- Returns:
-
retainAll
Retain matching items- Type Parameters:
T
-U
-- Parameters:
c
-f
-- Returns:
-
containsSome
- Parameters:
a
-b
-- Returns:
-
containsAll
-
containsNone
-
getContainmentRelation
Assesses all the possible containment relations between collections A and B with one call.
Returns an int with bits set, according to a "Venn Diagram" view of A vs B.
NOT_A_SUPERSET_B: a - b != {}
NOT_A_DISJOINT_B: a * b != {} // * is intersects
NOT_A_SUBSET_B: b - a != {}
Thus the bits can be used to get the following relations:
for A_SUPERSET_B, use (x invalid input: '&' CollectionUtilities.NOT_A_SUPERSET_B) == 0
for A_SUBSET_B, use (x invalid input: '&' CollectionUtilities.NOT_A_SUBSET_B) == 0
for A_EQUALS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_EQUALS_B) == 0
for A_DISJOINT_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) == 0
for A_OVERLAPS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) != 0 -
matchesAt
Does one string contain another, starting at a specific offset?- Parameters:
text
-offset
-other
-- Returns:
-
equals
public static <T> boolean equals(T a, T b) Compare, allowing nulls- Parameters:
a
-b
-- Returns:
-
compare
Compare, allowing nulls and putting them first- Parameters:
a
-b
-- Returns:
-
compare
Compare iterators- Parameters:
iterator1
-iterator2
-- Returns:
-
compare
Compare, with shortest first, and otherwise lexicographically- Parameters:
a
-b
-- Returns:
-
compare
Compare, with shortest first, and otherwise lexicographically- Parameters:
a
-b
-- Returns:
-
compare
public static <K extends Comparable,V extends Comparable, int compareT extends Map.Entry<K, V>> (T a, T b) Compare, allowing nulls and putting them first- Parameters:
a
-b
-- Returns:
-
compareEntrySets
public static <K extends Comparable,V extends Comparable, int compareEntrySetsT extends Map.Entry<K, V>> (Collection<T> o1, Collection<T> o2)
-