Package org.cip4.jdflib.util
Class ContainerUtil
java.lang.Object
org.cip4.jdflib.util.ContainerUtil
class with utilities for containers, e.g. Vectors, sets etc.
also simple object utilities
also simple object utilities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Collection<A>add(Collection<A> c, A a) null safe addstatic <A> Collection<A>addAll(Collection<A> c, A[] a) appends all strings of an array tothisstatic <A> Collection<A>addAll(Collection<A> c1, Collection<A> c2) null safe addAllstatic <A> Collection<A>appendUnique(Collection<A> c, A a) AppendUnique - append an object but ignore multiple entriesstatic <A> Collection<A>appendUnique(Collection<A> c, Collection<A> a) AppendUnique - append an object but ignore multiple entriesstatic voidstatic intcompare(Comparable c0, Comparable c1) static implementation of compare for any comparable object that gracefully handles null
null is always the smalleststatic <A> booleancontains(Collection<A> c, A other) null safe helperstatic <A> booleancontainsAll(Collection<A> c, Collection<A> others) null safe helperstatic <A> booleancontainsAny(Collection<A> c, Collection<A> others) checks whether at least one of a given vector of strings is contained inthisstatic <A> intcount(Collection<A> c, A other) null safe helperstatic <A> voidensureSize(int size, Collection<A> coll) ensure that a collection has at least size elements and fill any newly created entries with nullsstatic booleanreturn true if a equals b or both are nullstatic <A> Astatic <A,B> ListMap<B, A> getInvertedListMap(Map<A, B> m) create an inverted map with keys and values swapped.
The new values are vectors since a map may have identical values for different keysstatic <A,B> VectorMap<B, A> getInvertedMap(Map<A, B> m) Deprecated.static <A> Collection<A>getKeyArray(Map<A, ?> m) static <A> List<A>getKeyList(Map<A, ?> m) static <A> Vector<A>getKeyVector(Map<A, ?> m) Deprecated.static <a> IMatchesgetMatch(Collection<? extends IMatches> c, a obj, int iSkip) return a matching element from a collection of IMatchesstatic <A> AgetMatch(IMatches match, Collection<A> c, int iSkip) return a matching element from a collection of IMatchesgetMatches(Collection<? extends IMatches> c, A obj) return a matching element from a collection of IMatchesstatic <A> Vector<A>getMatches(IMatches m, Collection<A> c) return a matching element from a collectiongetMatchesList(Collection<? extends IMatches> c, A obj) return a matching element from a collection of IMatchesstatic <A> List<A>getMatchesList(IMatches m, Collection<A> c) return a matching element from a collectionstatic Collection<?>getNonEmpty(Collection<?> c) return null if c==null or c.isEmpty=true used to zapp empty collectionsstatic Map<?,?> getNonEmpty(Map<?, ?> c) return null if c==null or c.isEmpty=true used to zapp empty collectionsstatic Collection<?>getNonEmptyCollection(Collection<? extends Collection<?>> c) return null if c==null or c.isEmpty=true or c contains an empty collection used to zapp empty collectionsstatic <A> List<A>getOverlapping(Collection<A> c, Collection<A> others) vector of strings that is contained inthisstatic <A> intstatic booleanstatic booleanisEmpty(Collection<?> c) static booleanstatic intstatic booleanreturn true if a matches b or both are nullstatic booleanmatchesExisting(IMatches a, Object b) return true if a matches b or one of a or b is nullstatic <A,B> B static <A,B> Map<A, B> static <A> Aremove but also implementing the usual neg number syntaxstatic <A,B> Map<A, B> retainAll(Map<A, B> map, Collection<A> keep) static intsize(Collection<?> c) static intstatic <A> List<A>toArrayList(A[] array) create an ArrayList from an Array, skipping null elementsstatic <A,B> List<B> toArrayList(Map<A, B> m) create a Vector copy of entry values from a mapstatic <A extends Comparable<? super A>,B>
List<B>toArrayList(Map<A, B> m, boolean sortByKey) create a Vector of entry values from a mapstatic <A> Set<A>toHashSet(A[] l) create a HashSet from an Arraystatic <A> Set<A>toHashSet(Collection<A> list) create a HashSet from a List (Vector...)static <A> Set<A>toHashSet(Enumeration<A> enumeration) create a HashSet from an enumerationstatic <A> Set<A>create a HashSet from a List (Vector...)static <A> StringtoString(Collection<A> c) create a sorted String - never nullstatic <A,B> Vector<B> toValueVector(Map<A, B> m) create a Vector copy of entry values from a mapstatic <a extends Comparable<? super a>,b>
Vector<b>toValueVector(Map<a, b> m, boolean sortByKey) create a Vector of entry values from a mapstatic <A> Vector<A>toVector(A[] array) create a Vector from an Array, skipping null elementsstatic <A> Collection<A>unify(Collection<A> c) unify a collection while retaining the initial order (if the input collection is ordered)static <A extends IMatches>
Collection<A>unifyMatches(Collection<A> c) unify a collection while retaining the initial order (if the input collection is ordered)
-
Constructor Details
-
ContainerUtil
public ContainerUtil()
-
-
Method Details
-
toHashSet
create a HashSet from an enumeration- Type Parameters:
A- the data type of the sets- Parameters:
enumeration- the enumeration- Returns:
- a Set created from list
-
getNonEmpty
return null if c==null or c.isEmpty=true used to zapp empty collections- Parameters:
c- the Collection to test- Returns:
- the converted Collecion
-
getNonEmpty
return null if c==null or c.isEmpty=true used to zapp empty collections- Parameters:
c- the Collection to test- Returns:
- the converted Collecion
-
getNonEmptyCollection
return null if c==null or c.isEmpty=true or c contains an empty collection used to zapp empty collections- Parameters:
c- the Collection to test- Returns:
- the converted Collecion
-
toHashSet
create a HashSet from a List (Vector...)- Type Parameters:
A- the data type of the sets- Parameters:
list- the list- Returns:
- a Set created from list
-
toHashSet
create a HashSet from a List (Vector...)- Type Parameters:
A- the data type of the sets- Parameters:
list- the list- Returns:
- a Set created from list
-
toHashSet
create a HashSet from an Array- Type Parameters:
A- datatype- Parameters:
l- the array- Returns:
- a Set created from list
-
toVector
create a Vector from an Array, skipping null elements -
toString
create a sorted String - never null- Type Parameters:
A-- Parameters:
c-- Returns:
-
toArrayList
create an ArrayList from an Array, skipping null elements -
addAll
null safe addAll- Type Parameters:
A- type- Parameters:
c1- first collectionc2- second collection- Returns:
- c1 with c2 added, c2 if c1==null
-
containsAny
checks whether at least one of a given vector of strings is contained inthis- Parameters:
others- the VSTring of values to test- Returns:
- true if at least one String in other is in
this
-
contains
null safe helper- Type Parameters:
A-- Parameters:
c-other-- Returns:
-
count
null safe helper- Type Parameters:
A-- Parameters:
c-other-- Returns:
-
containsAll
null safe helper- Type Parameters:
A-- Parameters:
c-others-- Returns:
-
getOverlapping
vector of strings that is contained inthis- Parameters:
others- the VString of values to test- Returns:
- true if at least one String in other is in
this
-
addAll
appends all strings of an array tothis- Parameters:
strings- the array of strings to append tothis
-
add
null safe add- Parameters:
strings- the array of strings to append tothis
-
getMatch
return a matching element from a collection of IMatches- Type Parameters:
a- the data type- Parameters:
c- the collection to searchobj- the search key for matchesiSkip- which one to grab, may be negative in which case we count -1=last, -2=second last...- Returns:
- the matching
IMatches
-
getMatch
return a matching element from a collection of IMatches- Type Parameters:
A- the data type- Parameters:
match- the matcherc- theCollectioniSkip- which one to grab, may be negative in which case we count -1=last, -2=second last...- Returns:
- the matching
-
getMatches
return a matching element from a collection of IMatches- Type Parameters:
A- the data type- Parameters:
c- the collection to searchobj- the search key for matches- Returns:
- Vector of matching a
-
getMatchesList
return a matching element from a collection of IMatches- Type Parameters:
A- the data type- Parameters:
c- the collection to searchobj- the search key for matches- Returns:
- Vector of matching a
-
getMatches
return a matching element from a collection- Type Parameters:
A- the data type- Parameters:
c- the collection to searchobj- the matches- Returns:
- Vector of matching a
-
getMatchesList
return a matching element from a collection- Type Parameters:
A- the data type- Parameters:
c- the collection to searchobj- the matches- Returns:
- Vector of matching a
-
toValueVector
public static <a extends Comparable<? super a>,b> Vector<b> toValueVector(Map<a, b> m, boolean sortByKey) create a Vector of entry values from a map- Type Parameters:
a- type of the map keyb- type of the map entry- Parameters:
m- the map to dump to an arraysortByKey- , if true, sort the entries by key- Returns:
- the vector
-
toArrayList
public static <A extends Comparable<? super A>,B> List<B> toArrayList(Map<A, B> m, boolean sortByKey) create a Vector of entry values from a map- Type Parameters:
A- type of the map keyB- type of the map entry- Parameters:
m- the map to dump to an arraysortByKey- , if true, sort the entries by key- Returns:
- the vector
-
toValueVector
create a Vector copy of entry values from a map- Type Parameters:
A- data type of the map keyB- data type of the map value- Parameters:
m- the map to dump to an array- Returns:
- the vector
-
toArrayList
create a Vector copy of entry values from a map- Type Parameters:
A- data type of the map keyB- data type of the map value- Parameters:
m- the map to dump to an array- Returns:
- the vector
-
getInvertedMap
Deprecated.create an inverted map with keys and values swapped.
The new values are vectors since a map may have identical values for different keys- Type Parameters:
A- data type of the map keyB- data type of the map value- Parameters:
m- the map to invert- Returns:
- the inverted map
-
appendUnique
AppendUnique - append an object but ignore multiple entries- Parameters:
a- the A to append, if null nothing is added
-
appendUnique
AppendUnique - append an object but ignore multiple entries- Parameters:
a- the A to append, if null nothing is added
-
index
- Parameters:
l-i-- Returns:
-
get
- Parameters:
l-i-- Returns:
-
remove
remove but also implementing the usual neg number syntax- Parameters:
index- if 0, or positive count from front, else if negative from back- See Also:
-
getInvertedListMap
create an inverted map with keys and values swapped.
The new values are vectors since a map may have identical values for different keys- Type Parameters:
A- data type of the map keyB- data type of the map value- Parameters:
m- the map to invert- Returns:
- the inverted map
-
getKeyVector
Deprecated.create a Vector of key values from a map- Type Parameters:
A- data type of the map key- Parameters:
m- the map to dump to an array- Returns:
- the vector of keys - note that this Vector goes NOT reflect changes to the map
-
equals
return true if a equals b or both are null- Parameters:
a- Object to compareb- Object to compare- Returns:
- boolean true if a equals b or both are null
-
matches
return true if a matches b or both are null- Parameters:
a- Object to compareb- Object to compare- Returns:
- boolean true if a matches b or both are null
-
matchesExisting
return true if a matches b or one of a or b is null- Parameters:
a- Object to compareb- Object to compare- Returns:
- boolean true if a matches b or both are null
-
compare
static implementation of compare for any comparable object that gracefully handles null
null is always the smallest- Parameters:
c0-c1-- Returns:
- -1 if c0 < c1, 0 if equal, 1 if c0 > c1;
-
ensureSize
ensure that a collection has at least size elements and fill any newly created entries with nulls- Type Parameters:
A- anything - needed for the cast- Parameters:
size-coll-
-
unify
unify a collection while retaining the initial order (if the input collection is ordered)- Type Parameters:
A- the data type of the collection- Parameters:
c- the collection to unify- Returns:
- the unified collection - always the input collection
-
unifyMatches
unify a collection while retaining the initial order (if the input collection is ordered)- Type Parameters:
A- the data type of the collection- Parameters:
c- the collection to unify- Returns:
- the unified collection - always the input collection
-
length
- Parameters:
c- the collection to check- Returns:
- 0 for null or size
-
isEmpty
- Parameters:
c- the collection to check- Returns:
- 0 for null or size
-
size
- Parameters:
c- the collection to check- Returns:
- 0 for null or size
-
size
- Parameters:
c- the collection to check- Returns:
- 0 for null or size
-
isEmpty
- Parameters:
c-- Returns:
-
isEmpty
- Parameters:
c-- Returns:
-
getKeyArray
-
getKeyList
-
putAll
- Type Parameters:
A-B-- Parameters:
map-map2-- Returns:
-
retainAll
- Type Parameters:
A-B-- Parameters:
map-map2-- Returns:
-
put
- Type Parameters:
A-B-- Parameters:
map-map2-- Returns:
-
close
-