Class GridFunc
java.lang.Object
org.apache.ignite.internal.util.lang.GridFunc
- Direct Known Subclasses:
F
Contains factory and utility methods for
closures, predicates, and tuples.
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.
Predef in Scala) to provide general utility and functional
programming functionality in a shortest syntactical context using F
typedef.
Also note, that in all methods with predicates, null predicate has a true meaning. So does
the empty predicate array.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> GridIterator<T>Deprecated.static booleanTests whether specified arguments are equal, or bothnull.static <T> booleanisAll(T t, IgnitePredicate<? super T>... p) Tests if all provided predicates evaluate totruefor given value.static booleanDeprecated.static booleanDeprecated.static booleanisEmpty(byte[] c) Tests if the given array is eithernullor empty.static booleanisEmpty(int[] c) Tests if the given array is eithernullor empty.static booleanisEmpty(long[] c) Tests if the given array is eithernullor empty.static booleanTests if the given collection is eithernullor empty.static booleanTests if given string isnullor empty.static booleanisEmpty(Collection<?> c) Tests if the given collection is eithernullor empty.static booleanTests if the given map is eithernullor empty.static <T> booleanisEmpty(T[] c) Tests if the given array is eithernullor empty.static <T> booleanisEmptyOrNulls(T[] c) Tests if the given array isnull, empty or contains onlynullvalues.static <T1,T2> GridIterator<T2> iterator(Iterable<? extends T1> c, IgniteClosure<? super T1, T2> trans, boolean readOnly, IgnitePredicate<? super T1>... p) Creates and returns transforming iterator from given collection and optional filtering predicates.static <T> intsize(Iterator<? extends T> it, IgnitePredicate<? super T>... p) Gets size of the given iterator with provided optional predicates.static <V1,V2> IgniteBiTuple<V1, V2> t(V1 v1, V2 v2) Factory method returning new tuple with given parameters.static <T1,T2> Collection<T2> viewReadOnly(Collection<? extends T1> c, IgniteClosure<? super T1, T2> trans, IgnitePredicate<? super T1>... p) Creates read-only light-weight view on given collection with transformation and provided predicates.static GridClosureExceptionShortcut method that creates an instance ofGridClosureException.
-
Constructor Details
-
GridFunc
public GridFunc()
-
-
Method Details
-
emptyIterator
Deprecated.Creates new empty iterator.- Type Parameters:
T- Type of the iterator.- Returns:
- Newly created empty iterator.
-
eq
Tests whether specified arguments are equal, or bothnull.- Parameters:
o1- Object to compare.o2- Object to compare.- Returns:
- Returns
trueif the specified arguments are equal, or bothnull.
-
isAll
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.
-
isAlwaysFalse
Deprecated.Tests whether or not given set of predicates consists only of one predicate returned from#alwaysFalse()method.- Parameters:
p- Predicate to check.- Returns:
trueif given contains onlyALWAYS_FALSEpredicate.
-
isAlwaysFalse
Deprecated.Tests whether or not given predicate is the one returned from#alwaysFalse()method.- Parameters:
p- Predicate to check.- Returns:
trueif given predicate isALWAYS_FALSEpredicate.
-
isEmpty
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(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(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(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(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(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
Tests if the given collection is eithernullor empty.- Parameters:
c- Collection to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
isEmpty
Tests if the given collection is eithernullor empty.- Parameters:
c- Collection to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
isEmpty
Tests if the given map is eithernullor empty.- Parameters:
m- Map to test.- Returns:
- Whether or not the given collection is
nullor empty.
-
iterator
public static <T1,T2> GridIterator<T2> iterator(Iterable<? extends T1> c, IgniteClosure<? super T1, T2> trans, boolean readOnly, 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.
-
size
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.
-
t
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.
-
viewReadOnly
@SafeVarargs public static <T1,T2> Collection<T2> viewReadOnly(Collection<? extends T1> c, IgniteClosure<? super T1, T2> trans, 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.
-
wrap
Shortcut method that creates an instance ofGridClosureException.- Parameters:
e- Exception to wrap.- Returns:
- Newly created instance of
GridClosureException.
-