Class GridFunc
- java.lang.Object
-
- org.apache.ignite.internal.util.lang.GridFunc
-
- Direct Known Subclasses:
F
public class GridFunc extends Object
Contains factory and utility methods forclosures,predicates, andtuples. It also contains functional style collection comprehensions.Most of the methods in this class can be divided into two groups:
- Factory higher-order methods for closures, predicates and tuples, and
- Utility higher-order methods for processing collections with closures and predicates.
Predefin Scala) to provide general utility and functional programming functionality in a shortest syntactical context usingFtypedef.Also note, that in all methods with predicates, null predicate has a
truemeaning. So does the empty predicate array.
-
-
Constructor Summary
Constructors Constructor Description GridFunc()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
VaddIfAbsent(ConcurrentMap<K,V> map, K key, @Nullable Callable<V> c)Gets the value with given key.static <K,V>
VaddIfAbsent(ConcurrentMap<K,V> map, K key, V val)Gets the value with given key.static <K,V>
VaddIfAbsent(Map<? super K,V> map, K key, @Nullable Callable<? extends V> c)Utility map getter.static <K,V>
VaddIfAbsent(Map<K,V> map, K key, V v)Utility map getter.static <T> IgnitePredicate<T>alwaysFalse()Gets predicate that always returnsfalse.static <T> IgnitePredicate<T>alwaysTrue()Gets predicate that always returnstrue.static <T> T[]asArray(T... t)Convenience method to convert multiple elements into array.static <T> List<T>asList(@Nullable T... vals)Converts array toList.static <T> List<T>asList(T t)Creates read-only list with given values.static <K,V>
Map<K,V>asMap(K k, V v)Creates map with given values.static <K,V>
Map<K,V>asMap(K k1, V v1, K k2, V v2)Creates map with given values.static <K,V>
Map<K,V>asMap(K k1, V v1, K k2, V v2, K k3, V v3)Creates map with given values.static <K,V>
Map<K,V>asMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)Creates map with given values.static <K,V>
Map<K,V>asMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)Creates map with given values.static <T> Set<T>asSet(@Nullable T... t)Creates read-only set with given values.static <T> Set<T>asSet(T t)Creates read-only set with given value.static <K,V>
IgniteClosure<javax.cache.Cache.Entry<K,V>,V>cacheEntry2Get()Gets closure that returns value for an entry.static <K,V>
IgnitePredicate<javax.cache.Cache.Entry<K,V>>cacheHasPeekValue()Gets predicate which returnstrueif entry has peek value.static intcompareArrays(boolean[] a1, boolean[] a2)Compare arrays.static intcompareArrays(byte[] a1, byte[] a2)Compare arrays.static intcompareArrays(char[] a1, char[] a2)Compare arrays.static intcompareArrays(double[] a1, double[] a2)Compare arrays.static intcompareArrays(float[] a1, float[] a2)Compare arrays.static intcompareArrays(int[] a1, int[] a2)Compare arrays.static intcompareArrays(long[] a1, long[] a2)Compare arrays.static intcompareArrays(short[] a1, short[] a2)Compare arrays.static intcompareArrays(Object[] a1, Object[] a2)Compare arrays.static intcompareArrays(Object a1, Object a2)Compare arrays.static <T> Collection<T>concat(boolean cp, @Nullable Collection<T> c1, @Nullable Collection<T> c2)Concatenates 2 collections into one.static <T> Collection<T>concat(boolean cp, T t, @Nullable Collection<T> c)Concatenates an element to a collection.static <T> T[]concat(@Nullable T[] arr, T... obj)Concatenates an elements to an array.static Stringconcat(Iterable<?> c, @Nullable String delim)Concatenates strings using provided delimiter.static <T> Iterator<T>concat(Iterator<Iterator<T>> iters)Concatenates multiple iterators as single one.static <T> Iterator<T>concat(Iterator<T>... iters)Concatenates multiple iterators as single one.static booleancontains(int[] arr, int val)static booleancontains(long[] arr, long val)static <T> booleancontains(@Nullable Collection<T> c, T t)Checks if value is contained in the collection passed in.static <T> booleancontainsAny(@Nullable Collection<? extends T> c1, @Nullable T... c2)Checks if collectionc1contains any elements from arrayc2.static <T> Collection<T>emptyIfNull(@Nullable Collection<T> col)static <K,V>
Map<K,V>emptyIfNull(@Nullable Map<K,V> map)static <T> GridIterator<T>emptyIterator()Creates new empty iterator.static booleaneqNotOrdered(@Nullable Collection<?> c1, @Nullable Collection<?> c2)Checks if both collections have equal elements in any order.static booleaneqOrdered(@Nullable Collection<?> c1, @Nullable Collection<?> c2)Checks if both collections have equal elements in the same order.static <V> booleanexist(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p)Checks for existence of the element in input collection for which all provided predicates evaluate totrue.static <V> Vfind(Iterable<? extends V> c, V dfltVal, @Nullable IgnitePredicate<? super V>... p)Finds and returns first element in given collection for which any of the provided predicates evaluates totrue.static <T> Tfirst(@Nullable Iterable<? extends T> c)Gets first element from given collection or returnsnullif the collection is empty.static <T> Tfirst(List<? extends T> list)Gets first element from given list or returnsnullif list is empty.static <K,V>
Map.Entry<K,V>firstEntry(Map<K,V> m)Gets first entry from given map or returnsnullif the map is empty.static <V> VfirstValue(Map<?,V> m)Gets first value from given map or returnsnullif the map is empty.static <T> GridIterator<T>flat(@Nullable Iterable<? extends Iterable<T>> c)Flattens iterable-of-iterables and returns iterable over the elements of the inner collections.static <T> Collection<T>flatCollections(@Nullable Collection<? extends Collection<T>> c)Flattens collection-of-collections and returns collection over the elements of the inner collections.static <T> Iterator<T>flatIterators(@Nullable Iterable<Iterator<T>> c)Flattens iterable-of-iterators and returns iterator over the elements of the inner collections.static <D,B>
Bfold(Iterable<? extends D> c, B b, @Nullable IgniteBiClosure<? super D,? super B,B>... fs)Folds-right given collection using provided closure.static <T> IgniteClosure<T,T>identity()Gets identity closure, i.e. the closure that returns its variable value.static <T> IgniteReducer<T,T>identityReducer(T elem)Gets reducer which always returnstruefromIgniteReducer.collect(Object)method and passed inelementfromIgniteReducer.reduce()method.static <T> booleanisAll(T t, @Nullable IgnitePredicate<? super T>... p)Tests if all provided predicates evaluate totruefor given value.static booleanisAlwaysFalse(@Nullable IgnitePredicate[] p)Tests whether or not given set of predicates consists only of one predicate returned fromalwaysFalse()method.static booleanisAlwaysFalse(IgnitePredicate p)Tests whether or not given predicate is the one returned fromalwaysFalse()method.static booleanisAlwaysTrue(@Nullable IgnitePredicate[] p)Tests whether or not given set of predicates consists only of one predicate returned fromalwaysTrue()method.static booleanisAlwaysTrue(IgnitePredicate p)Tests whether or not given predicate is the one returned fromalwaysTrue()method.static <T> booleanisAny(T t, @Nullable IgnitePredicate<? super T>... p)Tests if any of provided predicates evaluate totruefor given value.static booleanisArray(Object val)static booleanisEmpty(@org.jetbrains.annotations.Nullable byte[] c)Tests if the given array is eithernullor empty.static booleanisEmpty(@org.jetbrains.annotations.Nullable char[] c)Tests if the given array is eithernullor empty.static booleanisEmpty(@org.jetbrains.annotations.Nullable int[] c)Tests if the given array is eithernullor empty.static booleanisEmpty(@org.jetbrains.annotations.Nullable long[] c)Tests if the given array is eithernullor empty.static booleanisEmpty(@Nullable Iterable<?> c)Tests if the given collection is eithernullor empty.static booleanisEmpty(@Nullable String s)Tests if given string isnullor empty.static booleanisEmpty(@Nullable Collection<?> c)Tests if the given collection is eithernullor empty.static booleanisEmpty(@Nullable Map<?,?> m)Tests if the given map is eithernullor empty.static <T> booleanisEmpty(@Nullable T[] c)Tests if the given array is eithernullor empty.static <T> booleanisEmptyOrNulls(@Nullable T[] c)Tests if the given array isnull, empty or contains onlynullvalues.static booleanisSorted(int[] arr)static booleanisSorted(long[] arr)static <T1,T2>
GridIterator<T2>iterator(Iterable<? extends T1> c, IgniteClosure<? super T1,T2> trans, boolean readOnly, @Nullable IgnitePredicate<? super T1>... p)Creates and returns transforming iterator from given collection and optional filtering predicates.static <T1,T2>
Iterator<T2>iterator(Iterator<? extends T1> c, IgniteClosure<? super T1,T2> trans, boolean readOnly, @Nullable IgnitePredicate<? super T1>... p)static <T> GridIterator<T>iterator0(Iterable<? extends T> c, boolean readOnly, IgnitePredicate<? super T>... p)Creates and returns iterator from given collection and optional filtering predicates.static <T> Tlast(@Nullable Iterable<? extends T> c)Gets last element from given collection or returnsnullif the collection is empty.static <T> Collection<T>lose(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p)Loses all elements in input collection that are evaluated totrueby all given predicates.static <T> List<T>loseList(List<T> c, boolean cp, @Nullable Collection<? super T> filter)Loses all elements in input list that are contained infiltercollection.static <T> booleanmapContainsKey(@Nullable Map<T,?> m, T k)Checks if key is contained in the map passed in.static <K,V>
IgniteCallable<ConcurrentMap<K,V>>newCMap()Returns a factory closure that creates newConcurrentMapinstance.static <E> IgniteCallable<Set<E>>newCSet()Returns a factory closure that creates newGridConcurrentHashSetinstance.static <T> IgniteCallable<Set<T>>newSet()Returns a factory closure that creates newSetinstance.static <T> IgnitePredicate<T>not(@Nullable IgnitePredicate<? super T>... p)Negates given predicates.static <T> IgnitePredicate<T>notContains(@Nullable Collection<T> c)Provides predicate which returnstrueif it receives an element that is not contained in the passed in collection.static <T> IgnitePredicate<T>notEqualTo(T target)Gets predicate that evaluates totrueif its free variable is not equal totargetor both arenull.static <T> IgnitePredicate<T>notIn(@Nullable Collection<? extends T> c)Gets predicate that returnstrueif its free variable is not contained in given collection.static <T> IgnitePredicate<T>notNull()Gets predicate that evaluates totrueif its free variable is notnull.static <T> IgnitePair<T>pair(T t1, T t2)Creates pair out of given two objects.static <T> Trand(Collection<? extends T> c)Gets random value from given collection.static <T> Trand(List<T> l)Gets random value from given list.static <T> Collection<T>retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p)Retains all elements in input collection that are evaluated totrueby all given predicates.static <T> intsize(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>... p)Gets size of the given collection with provided optional predicates.static <T> intsize(@Nullable Iterator<? extends T> it, @Nullable IgnitePredicate<? super T>... p)Gets size of the given iterator with provided optional predicates.static intsumInt(Iterable<Integer> c)Calculates sum of all elements.static <V> GridTuple<V>t(V v)Factory method returning new tuple with given parameter.static <V1,V2>
IgniteBiTuple<V1,V2>t(V1 v1, V2 v2)Factory method returning new tuple with given parameters.static <V1,V2,V3>
GridTuple3<V1,V2,V3>t(V1 v1, V2 v2, V3 v3)Factory method returning new tuple with given parameters.static <V1,V2,V3,V4>
GridTuple4<V1,V2,V3,V4>t(V1 v1, V2 v2, V3 v3, V4 v4)Factory method returning new tuple with given parameters.static <V1,V2,V3,V4,V5>
GridTuple5<V1,V2,V3,V4,V5>t(V1 v1, V2 v2, V3 v3, V4 v4, V5 v5)Factory method returning new tuple with given parameters.static <V1,V2,V3,V4,V5,V6>
GridTuple6<V1,V2,V3,V4,V5,V6>t(V1 v1, V2 v2, V3 v3, V4 v4, V5 v5, V6 v6)Factory method returning new tuple with given parameters.static <X,Y>
Collection<Y>transform(Collection<? extends X> c, IgniteClosure<? super X,Y> f)Transforms one collection to another using provided closure.static <T> Collection<T>view(@Nullable Collection<T> c, @Nullable IgnitePredicate<? super T>... p)Creates write-through light-weight view on given collection with provided predicates.static <K0,K extends K0,V0,V extends V0>
Map<K,V>view(@Nullable Map<K,V> m, @Nullable IgnitePredicate<? super K>... p)Creates light-weight view on given map with provided predicates.static <K0,K extends K0,V0,V extends V0>
Map<K,V>viewAsMap(@Nullable Set<K> c, IgniteClosure<? super K,V> mapClo, @Nullable IgnitePredicate<? super K>... p)Read-only map view of a collection.static <T1,T2>
Collection<T2>viewReadOnly(@Nullable Collection<? extends T1> c, IgniteClosure<? super T1,T2> trans, @Nullable IgnitePredicate<? super T1>... p)Creates read-only light-weight view on given collection with transformation and provided predicates.static <K0,K extends K0,V0,V extends V0,V1>
Map<K,V1>viewReadOnly(@Nullable Map<K,V> m, IgniteClosure<V,V1> trans, @Nullable IgnitePredicate<? super K>... p)Read-only view on map that supports transformation of values and key filtering.static GridClosureExceptionwrap(Throwable e)Shortcut method that creates an instance ofGridClosureException.static <K,V>
Map<K,V>zip(Collection<? extends K> keys, V dfltVal)Converts collection to map using collection values as keys and passed in default value as values.
-
-
-
Method Detail
-
sumInt
public static int sumInt(Iterable<Integer> c)
Calculates sum of all elements.
- Parameters:
c- Collection of elements.- Returns:
- Sum of all elements.
-
identityReducer
public static <T> IgniteReducer<T,T> identityReducer(T elem)
Gets reducer which always returnstruefromIgniteReducer.collect(Object)method and passed inelementfromIgniteReducer.reduce()method.- Type Parameters:
T- Reducer element type.- Parameters:
elem- Element to return fromIgniteReducer.reduce()method.- Returns:
- Passed in element.
-
concat
public static String concat(Iterable<?> c, @Nullable @Nullable String delim)
Concatenates strings using provided delimiter.- Parameters:
c- Input collection.delim- Delimiter (optional).- Returns:
- Concatenated string.
-
rand
public static <T> T rand(Collection<? extends T> c)
Gets random value from given collection.- Type Parameters:
T- Type of the collection.- Parameters:
c- Input collection (nonulland not emtpy).- Returns:
- Random value from the input collection.
-
rand
public static <T> T rand(List<T> l)
Gets random value from given list. For random-access lists this operation is O(1), otherwise O(n).- Type Parameters:
T- Type of the list elements.- Parameters:
l- Input collection.- Returns:
- Random value from the input list.
-
concat
public static <T> Collection<T> concat(boolean cp, @Nullable T t, @Nullable @Nullable Collection<T> c)
Concatenates an element to a collection. Ifcopyflag istrue, then a new collection will be created and the element and passed in collection will be copied into the new one. The returned collection will be modifiable. Ifcopyflag isfalse, then a read-only view will be created over the element and given collections and no copying will happen.- Type Parameters:
T- Element type.- Parameters:
cp- Copy flag.t- First element.c- Second collection.- Returns:
- Concatenated collection.
-
concat
public static <T> Collection<T> concat(boolean cp, @Nullable @Nullable Collection<T> c1, @Nullable @Nullable Collection<T> c2)
Concatenates 2 collections into one. Ifcopyflag istrue, then a new collection will be created and these collections will be copied into the new one. The returned collection will be modifiable. Ifcopyflag isfalse, then a read-only view will be created over given collections and no copying will happen.- Type Parameters:
T- Element type.- Parameters:
cp- Copy flag.c1- First collection.c2- Second collection.- Returns:
- Concatenated
non-nullcollection.
-
concat
public static <T> T[] concat(@Nullable @Nullable T[] arr, T... obj)Concatenates an elements to an array.- Parameters:
arr- Array.obj- One or more elements.- Returns:
- Concatenated array.
-
concat
public static <T> Iterator<T> concat(Iterator<T>... iters)
Concatenates multiple iterators as single one.- Parameters:
iters- Iterators.- Returns:
- Single iterator.
-
concat
public static <T> Iterator<T> concat(Iterator<Iterator<T>> iters)
Concatenates multiple iterators as single one.- Parameters:
iters- Iterator over iterators.- Returns:
- Single iterator.
-
lose
public static <T> Collection<T> lose(Collection<T> c, boolean cp, @Nullable @Nullable IgnitePredicate<? super T>... p)
Loses all elements in input collection that are evaluated totrueby all given predicates.- Type Parameters:
T- Type of collections.- Parameters:
c- Input collection.cp- Iftruemethod creates new collection without modifying the input one, otherwise does in-place modifications.p- Predicates to filter by. If no predicates provided - no elements are lost.- Returns:
- Collection of remaining elements.
-
loseList
public static <T> List<T> loseList(List<T> c, boolean cp, @Nullable @Nullable Collection<? super T> filter)
Loses all elements in input list that are contained infiltercollection.- Type Parameters:
T- Type of list.- Parameters:
c- Input list.cp- Iftruemethod creates new list not modifying input, otherwise does in-place modifications.filter- Filter collection. Iffiltercollection is empty ornull- no elements are lost.- Returns:
- List of remaining elements
-
retain
public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable @Nullable IgnitePredicate<? super T>... p)
Retains all elements in input collection that are evaluated totrueby all given predicates.- Type Parameters:
T- Type of collections.- Parameters:
c- Input collection.cp- Iftruemethod creates collection not modifying input, otherwise does in-place modifications.p- Predicates to filter by. If no predicates provides - all elements will be retained.- Returns:
- Collection of retain elements.
-
asList
public static <T> List<T> asList(@Nullable @Nullable T... vals)
Converts array toList. Note that resulting list cannot be altered in size, as it it based on the passed in array - only current elements can be changed.Note that unlike
Arrays.asList(Object[]), this method isnull-safe. Ifnullis passed in, then empty list will be returned.- Type Parameters:
T- Array type.- Parameters:
vals- Array of values- Returns:
Listinstance for array.
-
emptyIterator
public static <T> GridIterator<T> emptyIterator()
Creates new empty iterator.- Type Parameters:
T- Type of the iterator.- Returns:
- Newly created empty iterator.
-
flatCollections
public static <T> Collection<T> flatCollections(@Nullable @Nullable Collection<? extends Collection<T>> c)
Flattens collection-of-collections and returns collection over the elements of the inner collections. This method doesn't create any new collections or copies any elements.Note that due to non-copying nature of implementation, the
size()method of resulting collection will have to iterate over all elements to produce size. MethodisEmpty(), however, is constant time and is much more preferable to use instead of'size()'method when checking if list is not empty.- Type Parameters:
T- Type of the inner collections.- Parameters:
c- Input collection of collections.- Returns:
- Iterable over the elements of the inner collections.
-
flat
public static <T> GridIterator<T> flat(@Nullable @Nullable Iterable<? extends Iterable<T>> c)
Flattens iterable-of-iterables and returns iterable over the elements of the inner collections. This method doesn't create any new collections or copies any elements.- Type Parameters:
T- Type of the inner collections.- Parameters:
c- Input collection of collections.- Returns:
- Iterable over the elements of the inner collections.
-
flatIterators
public static <T> Iterator<T> flatIterators(@Nullable @Nullable Iterable<Iterator<T>> c)
Flattens iterable-of-iterators and returns iterator over the elements of the inner collections. This method doesn't create any new collections or copies any elements.- Parameters:
c- Input iterable of iterators.- Returns:
- Iterator over the elements of given iterators.
-
size
public static <T> int size(@Nullable @Nullable Collection<? extends T> c, @Nullable @Nullable IgnitePredicate<? super T>... p)Gets size of the given collection with provided optional predicates.- Type Parameters:
T- Type of the iterator.- Parameters:
c- Collection to size.p- Optional predicates that filters out elements from count.- Returns:
- Number of elements in the collection for which all given predicates
evaluates to
true. If no predicates is provided - all elements are counted.
-
size
public static <T> int size(@Nullable @Nullable Iterator<? extends T> it, @Nullable @Nullable IgnitePredicate<? super T>... p)Gets size of the given iterator with provided optional predicates. Iterator will be traversed to get the count.- Type Parameters:
T- Type of the iterator.- Parameters:
it- Iterator to size.p- Optional predicates that filters out elements from count.- Returns:
- Number of elements in the iterator for which all given predicates
evaluates to
true. If no predicates is provided - all elements are counted.
-
view
@SafeVarargs public static <T> Collection<T> view(@Nullable @Nullable Collection<T> c, @Nullable @Nullable IgnitePredicate<? super T>... p)
Creates write-through light-weight view on given collection with provided predicates. Resulting collection will only "have" elements for which all provided predicates, if any, evaluate totrue. Note that only wrapping collection will be created and no duplication of data will occur. Also note that if array of given predicates is not empty then methodsize()uses full iteration through the collection.- Type Parameters:
T- Type of the collection.- Parameters:
c- Input collection that serves as a base for the view.p- Optional predicates. If predicates are not provided - all elements will be in the view.- Returns:
- Light-weight view on given collection with provided predicate.
-
viewReadOnly
@SafeVarargs public static <T1,T2> Collection<T2> viewReadOnly(@Nullable @Nullable Collection<? extends T1> c, IgniteClosure<? super T1,T2> trans, @Nullable @Nullable IgnitePredicate<? super T1>... p)
Creates read-only light-weight view on given collection with transformation and provided predicates. Resulting collection will only "have"transformedelements for which all provided predicate, if any, evaluates totrue. Note that only wrapping collection will be created and no duplication of data will occur. Also note that if array of given predicates is not empty then methodsize()uses full iteration through the collection.- Type Parameters:
T1- Type of the collection.- Parameters:
c- Input collection that serves as a base for the view.trans- Transformation closure.p- Optional predicated. If predicates are not provided - all elements will be in the view.- Returns:
- Light-weight view on given collection with provided predicate.
-
view
public static <K0,K extends K0,V0,V extends V0> Map<K,V> view(@Nullable @Nullable Map<K,V> m, @Nullable @Nullable IgnitePredicate<? super K>... p)
Creates light-weight view on given map with provided predicates. Resulting map will only "have" keys for which all provided predicates, if any, evaluates totrue. Note that only wrapping map will be created and no duplication of data will occur. Also note that if array of given predicates is not empty then methodsize()uses full iteration through the entry set.- Type Parameters:
K- Type of the key.V- Type of the value.- Parameters:
m- Input map that serves as a base for the view.p- Optional predicates. If predicates are not provided - all will be in the view.- Returns:
- Light-weight view on given map with provided predicate.
-
viewReadOnly
public static <K0,K extends K0,V0,V extends V0,V1> Map<K,V1> viewReadOnly(@Nullable @Nullable Map<K,V> m, IgniteClosure<V,V1> trans, @Nullable @Nullable IgnitePredicate<? super K>... p)
Read-only view on map that supports transformation of values and key filtering. Resulting map will only "have" keys for which all provided predicates, if any, evaluates totrue. Note that only wrapping map will be created and no duplication of data will occur. Also note that if array of given predicates is not empty then methodsize()uses full iteration through the entry set.- Type Parameters:
K- Type of the key.V- Type of the input map value.V1- Type of the output map value.- Parameters:
m- Input map that serves as a base for the view.trans- Transformer for map value transformation.p- Optional predicates. If predicates are not provided - all will be in the view.- Returns:
- Light-weight view on given map with provided predicate and transformer.
-
viewAsMap
public static <K0,K extends K0,V0,V extends V0> Map<K,V> viewAsMap(@Nullable @Nullable Set<K> c, IgniteClosure<? super K,V> mapClo, @Nullable @Nullable IgnitePredicate<? super K>... p)
Read-only map view of a collection. Resulting map is a lightweight view of an input collection, with filtered elements of an input collection as keys, and closure execution results as values. The map will only contain keys for which all provided predicates, if any, evaluate totrue. Note that only wrapping map will be created and no duplication of data will occur. Also note that if array of given predicates is not empty then methodsize()uses full iteration through the entry set.- Type Parameters:
K- Key type.V- Value type.- Parameters:
c- Input collection.mapClo- Mapping closure, that maps key to value.p- Optional predicates to filter input collection. If predicates are not provided - all elements will be in the view.- Returns:
- Light-weight view on given map with provided predicates and mapping.
-
isEmpty
public static boolean isEmpty(@Nullable @Nullable String s)Tests if given string isnullor empty.- Parameters:
s- String to test.- Returns:
- Whether or not the given string is
nullor empty.
-
isEmpty
public static <T> boolean isEmpty(@Nullable @Nullable T[] c)Tests if the given array is eithernullor empty.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
nullor empty.
-
isEmptyOrNulls
public static <T> boolean isEmptyOrNulls(@Nullable @Nullable T[] c)Tests if the given array isnull, empty or contains onlynullvalues.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
null, empty or contains onlynullvalues.
-
isEmpty
public static boolean isEmpty(@Nullable @org.jetbrains.annotations.Nullable int[] c)Tests if the given array is eithernullor empty.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @org.jetbrains.annotations.Nullable byte[] c)Tests if the given array is eithernullor empty.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @org.jetbrains.annotations.Nullable long[] c)Tests if the given array is eithernullor empty.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @org.jetbrains.annotations.Nullable char[] c)Tests if the given array is eithernullor empty.- Parameters:
c- Array to test.- Returns:
- Whether or not the given array is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @Nullable Iterable<?> c)Tests if the given collection is eithernullor empty.- Parameters:
c- Collection to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @Nullable Collection<?> c)Tests if the given collection is eithernullor empty.- Parameters:
c- Collection to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
isEmpty
public static boolean isEmpty(@Nullable @Nullable Map<?,?> m)Tests if the given map is eithernullor empty.- Parameters:
m- Map to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
newSet
public static <T> IgniteCallable<Set<T>> newSet()
Returns a factory closure that creates newSetinstance. Note that this method does not create a new closure but returns a static one.- Type Parameters:
T- Type parameters for the createdSet.- Returns:
- Factory closure that creates new
Setinstance every time itsIgniteOutClosure.apply()method is called.
-
newCMap
public static <K,V> IgniteCallable<ConcurrentMap<K,V>> newCMap()
Returns a factory closure that creates newConcurrentMapinstance. Note that this method does not create a new closure but returns a static one.- Type Parameters:
K- Type of the key for the createdConcurrentMap.V- Type of the value for the createdConcurrentMap.- Returns:
- Factory closure that creates new
Mapinstance every time itsIgniteOutClosure.apply()method is called.
-
newCSet
public static <E> IgniteCallable<Set<E>> newCSet()
Returns a factory closure that creates newGridConcurrentHashSetinstance. Note that this method does not create a new closure but returns a static one.- Returns:
- Factory closure that creates new
GridConcurrentHashSetinstance every time itsIgniteOutClosure.apply()method is called.
-
iterator0
public static <T> GridIterator<T> iterator0(Iterable<? extends T> c, boolean readOnly, IgnitePredicate<? super T>... p)
Creates and returns iterator from given collection and optional filtering predicates. Returned iterator will only have elements for which all given predicates evaluates totrue(if provided). Note that this method will not create new collection but will simply "skip" elements in the provided collection that given predicates doesn't evaluate totruefor.- Type Parameters:
T- Type of the collection elements.- Parameters:
c- Input collection.readOnly- Iftrue, then resulting iterator will not allow modifications to the underlying collection.p- Optional filtering predicates.- Returns:
- Iterator from given collection and optional filtering predicate.
-
iterator
public static <T1,T2> GridIterator<T2> iterator(Iterable<? extends T1> c, IgniteClosure<? super T1,T2> trans, boolean readOnly, @Nullable @Nullable IgnitePredicate<? super T1>... p)
Creates and returns transforming iterator from given collection and optional filtering predicates. Returned iterator will only have elements for which all given predicates evaluates totrue( if provided). Note that this method will not create new collection but will simply "skip" elements in the provided collection that given predicates doesn't evaluate totruefor.- Type Parameters:
T1- Type of the collection elements.T2- Type of returned elements.- Parameters:
c- Input collection.trans- Transforming closure to convert from T1 to T2.readOnly- Iftrue, then resulting iterator will not allow modifications to the underlying collection.p- Optional filtering predicates.- Returns:
- Iterator from given collection and optional filtering predicate.
-
iterator
@SafeVarargs public static <T1,T2> Iterator<T2> iterator(Iterator<? extends T1> c, IgniteClosure<? super T1,T2> trans, boolean readOnly, @Nullable @Nullable IgnitePredicate<? super T1>... p)
- Parameters:
c- Input iterator.trans- Transforming closure to convert from T1 to T2.readOnly- Iftrue, then resulting iterator will not allow modifications to the underlying collection.p- Optional filtering predicates.- Returns:
- Iterator from given iterator and optional filtering predicate.
-
alwaysTrue
public static <T> IgnitePredicate<T> alwaysTrue()
Gets predicate that always returnstrue. This method returns constant predicate.- Type Parameters:
T- Type of the free variable, i.e. the element the predicate is called on.- Returns:
- Predicate that always returns
true.
-
alwaysFalse
public static <T> IgnitePredicate<T> alwaysFalse()
Gets predicate that always returnsfalse. This method returns constant predicate.- Type Parameters:
T- Type of the free variable, i.e. the element the predicate is called on.- Returns:
- Predicate that always returns
false.
-
isAlwaysTrue
public static boolean isAlwaysTrue(IgnitePredicate p)
Tests whether or not given predicate is the one returned fromalwaysTrue()method.- Parameters:
p- Predicate to check.- Returns:
trueif given predicate isALWAYS_TRUEpredicate.
-
isAlwaysTrue
public static boolean isAlwaysTrue(@Nullable @Nullable IgnitePredicate[] p)Tests whether or not given set of predicates consists only of one predicate returned fromalwaysTrue()method.- Parameters:
p- Predicate to check.- Returns:
trueif given contains onlyALWAYS_TRUEpredicate.
-
isAlwaysFalse
public static boolean isAlwaysFalse(IgnitePredicate p)
Tests whether or not given predicate is the one returned fromalwaysFalse()method.- Parameters:
p- Predicate to check.- Returns:
trueif given predicate isALWAYS_FALSEpredicate.
-
isAlwaysFalse
public static boolean isAlwaysFalse(@Nullable @Nullable IgnitePredicate[] p)Tests whether or not given set of predicates consists only of one predicate returned fromalwaysFalse()method.- Parameters:
p- Predicate to check.- Returns:
trueif given contains onlyALWAYS_FALSEpredicate.
-
notNull
public static <T> IgnitePredicate<T> notNull()
Gets predicate that evaluates totrueif its free variable is notnull.- Type Parameters:
T- Type of the free variable, i.e. the element the predicate is called on.- Returns:
- Predicate that evaluates to
trueif its free variable is notnull.
-
not
@SafeVarargs public static <T> IgnitePredicate<T> not(@Nullable @Nullable IgnitePredicate<? super T>... p)
Negates given predicates.Gets predicate that evaluates to
trueif any of given predicates evaluates tofalse. If all predicates evaluate totruethe result predicate will evaluate tofalse.- Type Parameters:
T- Type of the free variable, i.e. the element the predicate is called on.- Parameters:
p- Predicate to negate.- Returns:
- Negated predicate.
-
notEqualTo
public static <T> IgnitePredicate<T> notEqualTo(@Nullable T target)
Gets predicate that evaluates totrueif its free variable is not equal totargetor both arenull.- Type Parameters:
T- Type of the free variable, i.e. the element the predicate is called on.- Parameters:
target- Object to compare free variable to.- Returns:
- Predicate that evaluates to
trueif its free variable is not equal totargetor both arenull.
-
first
public static <T> T first(@Nullable @Nullable Iterable<? extends T> c)Gets first element from given collection or returnsnullif the collection is empty.- Type Parameters:
T- Type of the collection.- Parameters:
c- A collection.- Returns:
- Collections' first element or
nullin case if the collection is empty.
-
first
public static <T> T first(List<? extends T> list)
Gets first element from given list or returnsnullif list is empty.- Parameters:
list- List.- Returns:
- List' first element or
nullin case if list is empty.
-
last
@Nullable public static <T> T last(@Nullable @Nullable Iterable<? extends T> c)Gets last element from given collection or returnsnullif the collection is empty.- Type Parameters:
T- Type of the collection.- Parameters:
c- A collection.- Returns:
- Collections' first element or
nullin case if the collection is empty.
-
firstValue
@Nullable public static <V> V firstValue(Map<?,V> m)
Gets first value from given map or returnsnullif the map is empty.- Type Parameters:
V- Value type.- Parameters:
m- A map.- Returns:
- Maps' first value or
nullin case if the map is empty.
-
firstEntry
@Nullable public static <K,V> Map.Entry<K,V> firstEntry(Map<K,V> m)
Gets first entry from given map or returnsnullif the map is empty.- Type Parameters:
K- Key type.V- Value type.- Parameters:
m- A map.- Returns:
- Map's first entry or
nullin case if the map is empty.
-
identity
public static <T> IgniteClosure<T,T> identity()
Gets identity closure, i.e. the closure that returns its variable value.- Type Parameters:
T- Type of the variable and return value for the closure.- Returns:
- Identity closure, i.e. the closure that returns its variable value.
-
notIn
public static <T> IgnitePredicate<T> notIn(@Nullable @Nullable Collection<? extends T> c)
Gets predicate that returnstrueif its free variable is not contained in given collection.- Type Parameters:
T- Type of the free variable for the predicate and type of the collection elements.- Parameters:
c- Collection to check for containment.- Returns:
- Predicate that returns
trueif its free variable is not contained in given collection.
-
addIfAbsent
public static <K,V> V addIfAbsent(ConcurrentMap<K,V> map, K key, @Nullable @Nullable Callable<V> c)
Gets the value with given key. If that value does not exist, calls given closure to get the default value, puts it into the map and returns it. If closure isnullreturnnull.- Type Parameters:
K- Key type.V- Value type.- Parameters:
map- Concurrent hash map.key- Key to get the value for.c- Default value producing closure.- Returns:
- Value for the key or the value produced by the closure if key
does not exist in the map. Return
nullif key is not found and closure isnull.
-
addIfAbsent
public static <K,V> V addIfAbsent(ConcurrentMap<K,V> map, K key, V val)
Gets the value with given key. If that value does not exist, puts given value into the map and returns it.- Type Parameters:
K- Key type.V- Value type.- Parameters:
map- Map.key- Key.val- Value to put if one does not exist.- Returns:
- Current mapping for a given key.
-
addIfAbsent
@Nullable public static <K,V> V addIfAbsent(Map<? super K,V> map, @Nullable K key, @Nullable @Nullable Callable<? extends V> c)
Utility map getter.- Type Parameters:
K- Map key type.V- Map value type.- Parameters:
map- Map to get value from.key- Map key (can benull).c- Optional factory closure for the default value to be put in whenkeyis not found. If closure is not provided -nullwill be put into the map.- Returns:
- Value for the
keyor default value produced bycif key is not found (ornullif key is not found and closure is not provided). Note that in case when key is not found the default value will be put into the map. - Throws:
GridClosureException- Thrown in case when callable throws exception.- See Also:
newSet()
-
addIfAbsent
@Nullable public static <K,V> V addIfAbsent(Map<K,V> map, @Nullable K key, @Nullable V v)
Utility map getter.- Type Parameters:
K- Map key type.V- Map value type.- Parameters:
map- Map to get value from.key- Map key (can benull).v- Optional value to be put in whenkeyis not found. If not provided -nullwill be put into the map.- Returns:
- Value for the
keyor default valuecif key is not found (ornullif key is not found and value is not provided). Note that in case when key is not found the default value will be put into the map.
-
transform
public static <X,Y> Collection<Y> transform(Collection<? extends X> c, IgniteClosure<? super X,Y> f)
Transforms one collection to another using provided closure. New collection will be created.- Type Parameters:
X- Type of the free variable for the closure and type of the collection elements.Y- Type of the closure's return value.- Parameters:
c- Initial collection to transform.f- Closure to use for transformation.- Returns:
- Transformed newly created collection.
-
isAll
public static <T> boolean isAll(@Nullable T t, @Nullable @Nullable IgnitePredicate<? super T>... p)Tests if all provided predicates evaluate totruefor given value. Note that evaluation will be short-circuit when first predicate evaluated tofalseis found.- Type Parameters:
T- Type of the value and free variable of the predicates.- Parameters:
t- Value to test.p- Optional set of predicates to use for evaluation. If no predicates provides this method will always returntrue.- Returns:
- Returns
trueif given set of predicates isnull, is empty, or all predicates evaluate totruefor given value,falseotherwise.
-
isAny
public static <T> boolean isAny(@Nullable T t, @Nullable @Nullable IgnitePredicate<? super T>... p)Tests if any of provided predicates evaluate totruefor given value. Note that evaluation will be short-circuit when first predicate evaluated totrueis found.- Type Parameters:
T- Type of the value and free variable of the predicates.- Parameters:
t- Value to test.p- Optional set of predicates to use for evaluation.- Returns:
- Returns
trueif any of predicates evaluates totruefor given value,falseotherwise. Returnsfalseif given set of predicates isnullor empty.
-
find
@SafeVarargs @Nullable public static <V> V find(Iterable<? extends V> c, @Nullable V dfltVal, @Nullable @Nullable IgnitePredicate<? super V>... p)
Finds and returns first element in given collection for which any of the provided predicates evaluates totrue.- Type Parameters:
V- Type of the collection elements.- Parameters:
c- Input collection.dfltVal- Default value to return when no element is found.p- Optional set of finder predicates.- Returns:
- First element in given collection for which predicate evaluates to
true- ornullif such element cannot be found.
-
containsAny
public static <T> boolean containsAny(@Nullable @Nullable Collection<? extends T> c1, @Nullable @Nullable T... c2)Checks if collectionc1contains any elements from arrayc2.- Type Parameters:
T- Type of the elements.- Parameters:
c1- Collection to check for containment. Ifnull- this method returnsfalse.c2- Collection of elements to check. Ifnull- this method returnsfalse.- Returns:
trueif collectionc1contains at least one element from collectionc2.
-
pair
public static <T> IgnitePair<T> pair(@Nullable T t1, @Nullable T t2)
Creates pair out of given two objects.- Type Parameters:
T- Type of objects in pair.- Parameters:
t1- First object in pair.t2- Second object in pair.- Returns:
- Pair of objects.
-
exist
public static <V> boolean exist(Iterable<? extends V> c, @Nullable @Nullable IgnitePredicate<? super V>... p)
Checks for existence of the element in input collection for which all provided predicates evaluate totrue.- Type Parameters:
V- Type of the collection elements.- Parameters:
c- Input collection.p- Optional set of checking predicates.- Returns:
trueif input collection contains element for which all the provided predicates evaluates totrue- otherwise returnsfalse.
-
fold
@Nullable public static <D,B> B fold(Iterable<? extends D> c, @Nullable B b, @Nullable @Nullable IgniteBiClosure<? super D,? super B,B>... fs)
Folds-right given collection using provided closure. If input collection contains a1, a2, ..., an result value will be ...f(f(f(b,a1),a2),a3)... wheref(x)is the result of applying each closure fromfsset to the elementxof the input collectionc.For example:
... Collection<Integer> nums = new ArrayList<Integer>(size); // Search max value. Integer max = F.fold(nums, F.first(nums), new C2<Integer, Integer, Integer>() { public Integer apply(Integer n, Integer max) { return Math.max(n, max); } }); ...- Type Parameters:
D- Type of the input collection elements and type of the free variable for the closure.B- Type of the folding value and return type of the closure.- Parameters:
c- Input collection.b- Optional first folding pair element.fs- Optional set of folding closures.- Returns:
- Value representing folded collection.
-
t
public static <V> GridTuple<V> t(@Nullable V v)
Factory method returning new tuple with given parameter.- Type Parameters:
V- Type of the tuple.- Parameters:
v- Parameter for tuple.- Returns:
- Newly created tuple.
-
t
public static <V1,V2> IgniteBiTuple<V1,V2> t(@Nullable V1 v1, @Nullable V2 v2)
Factory method returning new tuple with given parameters.- Type Parameters:
V1- Type of the 1st tuple parameter.V2- Type of the 2nd tuple parameter.- Parameters:
v1- 1st parameter for tuple.v2- 2nd parameter for tuple.- Returns:
- Newly created tuple.
-
t
public static <V1,V2,V3> GridTuple3<V1,V2,V3> t(@Nullable V1 v1, @Nullable V2 v2, @Nullable V3 v3)
Factory method returning new tuple with given parameters.- Type Parameters:
V1- Type of the 1st tuple parameter.V2- Type of the 2nd tuple parameter.V3- Type of the 3rd tuple parameter.- Parameters:
v1- 1st parameter for tuple.v2- 2nd parameter for tuple.v3- 3rd parameter for tuple.- Returns:
- Newly created tuple.
-
t
public static <V1,V2,V3,V4> GridTuple4<V1,V2,V3,V4> t(@Nullable V1 v1, @Nullable V2 v2, @Nullable V3 v3, @Nullable V4 v4)
Factory method returning new tuple with given parameters.- Type Parameters:
V1- Type of the 1st tuple parameter.V2- Type of the 2nd tuple parameter.V3- Type of the 3rd tuple parameter.V4- Type of the 4th tuple parameter.- Parameters:
v1- 1st parameter for tuple.v2- 2nd parameter for tuple.v3- 3rd parameter for tuple.v4- 4th parameter for tuple.- Returns:
- Newly created tuple.
-
t
public static <V1,V2,V3,V4,V5> GridTuple5<V1,V2,V3,V4,V5> t(@Nullable V1 v1, @Nullable V2 v2, @Nullable V3 v3, @Nullable V4 v4, @Nullable V5 v5)
Factory method returning new tuple with given parameters.- Type Parameters:
V1- Type of the 1st tuple parameter.V2- Type of the 2nd tuple parameter.V3- Type of the 3rd tuple parameter.V4- Type of the 4th tuple parameter.V5- Type of the 5th tuple parameter.- Parameters:
v1- 1st parameter for tuple.v2- 2nd parameter for tuple.v3- 3rd parameter for tuple.v4- 4th parameter for tuple.v5- 5th parameter for tuple.- Returns:
- Newly created tuple.
-
t
public static <V1,V2,V3,V4,V5,V6> GridTuple6<V1,V2,V3,V4,V5,V6> t(@Nullable V1 v1, @Nullable V2 v2, @Nullable V3 v3, @Nullable V4 v4, @Nullable V5 v5, @Nullable V6 v6)
Factory method returning new tuple with given parameters.- Type Parameters:
V1- Type of the 1st tuple parameter.V2- Type of the 2nd tuple parameter.V3- Type of the 3rd tuple parameter.V4- Type of the 4th tuple parameter.V5- Type of the 5th tuple parameter.V6- Type of the 6th tuple parameter.- Parameters:
v1- 1st parameter for tuple.v2- 2nd parameter for tuple.v3- 3rd parameter for tuple.v4- 4th parameter for tuple.v5- 5th parameter for tuple.v6- 5th parameter for tuple.- Returns:
- Newly created tuple.
-
zip
public static <K,V> Map<K,V> zip(Collection<? extends K> keys, V dfltVal)
Converts collection to map using collection values as keys and passed in default value as values.- Type Parameters:
K- Key type.V- Value type.- Parameters:
keys- Map keys.dfltVal- Default value.- Returns:
- Resulting map.
-
asMap
public static <K,V> Map<K,V> asMap(K k, V v)
Creates map with given values.- Type Parameters:
K- Key's type.V- Value's type.- Parameters:
k- Key.v- Value.- Returns:
- Created map.
-
asMap
public static <K,V> Map<K,V> asMap(K k1, V v1, K k2, V v2)
Creates map with given values.- Type Parameters:
K- Key's type.V- Value's type.- Parameters:
k1- Key 1.v1- Value 1.k2- Key 2.v2- Value 2.- Returns:
- Created map.
-
asMap
public static <K,V> Map<K,V> asMap(K k1, V v1, K k2, V v2, K k3, V v3)
Creates map with given values.- Type Parameters:
K- Key's type.V- Value's type.- Parameters:
k1- Key 1.v1- Value 1.k2- Key 2.v2- Value 2.k3- Key 3.v3- Value 3.- Returns:
- Created map.
-
asMap
public static <K,V> Map<K,V> asMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
Creates map with given values.- Type Parameters:
K- Key's type.V- Value's type.- Parameters:
k1- Key 1.v1- Value 1.k2- Key 2.v2- Value 2.k3- Key 3.v3- Value 3.k4- Key 4.v4- Value 4.- Returns:
- Created map.
-
asMap
public static <K,V> Map<K,V> asMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
Creates map with given values.- Type Parameters:
K- Key's type.V- Value's type.- Parameters:
k1- Key 1.v1- Value 1.k2- Key 2.v2- Value 2.k3- Key 3.v3- Value 3.k4- Key 4.v4- Value 4.k5- Key 5.v5- Value 5.- Returns:
- Created map.
-
asArray
public static <T> T[] asArray(T... t)
Convenience method to convert multiple elements into array.- Type Parameters:
T- Element type.- Parameters:
t- Elements to convert into array.- Returns:
- Array of elements.
-
asList
public static <T> List<T> asList(@Nullable T t)
Creates read-only list with given values.- Type Parameters:
T- Element's type.- Parameters:
t- Element (ifnull, then empty list is returned).- Returns:
- Created list.
-
asSet
public static <T> Set<T> asSet(@Nullable T t)
Creates read-only set with given value.- Type Parameters:
T- Element's type.- Parameters:
t- Element (ifnull, then empty set is returned).- Returns:
- Created set.
-
asSet
public static <T> Set<T> asSet(@Nullable @Nullable T... t)
Creates read-only set with given values.- Type Parameters:
T- Element's type.- Parameters:
t- Element (ifnull, then empty set is returned).- Returns:
- Created set.
-
contains
public static <T> boolean contains(@Nullable @Nullable Collection<T> c, @Nullable T t)Checks if value is contained in the collection passed in. If the collection isnull, thenfalseis returned.- Type Parameters:
T- Value type.- Parameters:
c- Collection to check.t- Value to check for containment.- Returns:
Trueif collection is notnulland contains given value,falseotherwise.
-
notContains
public static <T> IgnitePredicate<T> notContains(@Nullable @Nullable Collection<T> c)
Provides predicate which returnstrueif it receives an element that is not contained in the passed in collection.- Type Parameters:
T- Element type.- Parameters:
c- Collection used for predicate filter.- Returns:
- Predicate which returns
trueif it receives an element that is not contained in the passed in collection.
-
contains
public static boolean contains(int[] arr, int val)- Parameters:
arr- Array.val- Value to find.- Returns:
Trueif array contains given value.
-
mapContainsKey
public static <T> boolean mapContainsKey(@Nullable @Nullable Map<T,?> m, T k)Checks if key is contained in the map passed in. If the map isnull, thenfalseis returned.- Type Parameters:
T- Key type.- Parameters:
m- Map to check.k- Key to check for containment.- Returns:
trueif map is notnulland contains given key,falseotherwise.
-
contains
public static boolean contains(long[] arr, long val)- Parameters:
arr- Array.val- Value to find.- Returns:
Trueif array contains given value.
-
eqOrdered
public static boolean eqOrdered(@Nullable @Nullable Collection<?> c1, @Nullable @Nullable Collection<?> c2)Checks if both collections have equal elements in the same order.- Parameters:
c1- First collection.c2- Second collection.- Returns:
Trueif both collections have equal elements in the same order.
-
eqNotOrdered
public static boolean eqNotOrdered(@Nullable @Nullable Collection<?> c1, @Nullable @Nullable Collection<?> c2)Checks if both collections have equal elements in any order.Implementation of this method takes optimization steps based on the actual type of the collections. Dups are allowed in the collection. Note that if collections allow fixed-time random access (implementing
RandomAccessmarker interface - having them pre-sorted dramatically improves the performance.- Parameters:
c1- First collection.c2- Second collection.- Returns:
Trueif both collections have equal elements in any order.
-
cacheEntry2Get
public static <K,V> IgniteClosure<javax.cache.Cache.Entry<K,V>,V> cacheEntry2Get()
Gets closure that returns value for an entry. The closure internally delegates toCache.get(Object)method.- Type Parameters:
K- Key type.V- Value type.- Returns:
- Closure that returns value for an entry.
-
cacheHasPeekValue
public static <K,V> IgnitePredicate<javax.cache.Cache.Entry<K,V>> cacheHasPeekValue()
Gets predicate which returnstrueif entry has peek value.- Type Parameters:
K- Cache key type.V- Cache value type.- Returns:
- Predicate which returns
trueif entry has peek value.
-
wrap
public static GridClosureException wrap(Throwable e)
Shortcut method that creates an instance ofGridClosureException.- Parameters:
e- Exception to wrap.- Returns:
- Newly created instance of
GridClosureException.
-
isSorted
public static boolean isSorted(long[] arr)
- Parameters:
arr- Array to check.- Returns:
Trueif array sorted,falseotherwise.
-
isSorted
public static boolean isSorted(int[] arr)
- Parameters:
arr- Array to check.- Returns:
Trueif array sorted,falseotherwise.
-
isArray
public static boolean isArray(Object val)
- Parameters:
val- Value to check.- Returns:
Trueif not null and array.
-
compareArrays
public static int compareArrays(Object a1, Object a2)
Compare arrays.- Parameters:
a1- Value 1.a2- Value 2.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compareArrays
public static int compareArrays(byte[] a1, byte[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(boolean[] a1, boolean[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(short[] a1, short[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(char[] a1, char[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(int[] a1, int[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(long[] a1, long[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(float[] a1, float[] a2)Compare arrays.
-
compareArrays
public static int compareArrays(double[] a1, double[] a2)Compare arrays.
-
emptyIfNull
public static <T> Collection<T> emptyIfNull(@Nullable @Nullable Collection<T> col)
- Parameters:
col- Collection.
-
-