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 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.
Note that contrary to the usual design this class has substantial number of methods (over 200). This design is chosen to simulate a global namespace (like a 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 Details

    • GridFunc

      public GridFunc()
  • Method Details

    • emptyIterator

      @Deprecated public static <T> GridIterator<T> emptyIterator()
      Deprecated.
      Creates new empty iterator.
      Type Parameters:
      T - Type of the iterator.
      Returns:
      Newly created empty iterator.
    • eq

      public static boolean eq(Object o1, Object o2)
      Tests whether specified arguments are equal, or both null.
      Parameters:
      o1 - Object to compare.
      o2 - Object to compare.
      Returns:
      Returns true if the specified arguments are equal, or both null.
    • isAll

      public static <T> boolean isAll(T t, IgnitePredicate<? super T>... p)
      Tests if all provided predicates evaluate to true for given value. Note that evaluation will be short-circuit when first predicate evaluated to false is 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 return true.
      Returns:
      Returns true if given set of predicates is null, is empty, or all predicates evaluate to true for given value, false otherwise.
    • isAlwaysFalse

      @Deprecated public static boolean isAlwaysFalse(IgnitePredicate[] p)
      Deprecated.
      Tests whether or not given set of predicates consists only of one predicate returned from #alwaysFalse() method.
      Parameters:
      p - Predicate to check.
      Returns:
      true if given contains only ALWAYS_FALSE predicate.
    • isAlwaysFalse

      @Deprecated public static boolean isAlwaysFalse(IgnitePredicate p)
      Deprecated.
      Tests whether or not given predicate is the one returned from #alwaysFalse() method.
      Parameters:
      p - Predicate to check.
      Returns:
      true if given predicate is ALWAYS_FALSE predicate.
    • isEmpty

      public static boolean isEmpty(String s)
      Tests if given string is null or empty.
      Parameters:
      s - String to test.
      Returns:
      Whether or not the given string is null or empty.
    • isEmpty

      public static <T> boolean isEmpty(T[] c)
      Tests if the given array is either null or empty.
      Parameters:
      c - Array to test.
      Returns:
      Whether or not the given array is null or empty.
    • isEmptyOrNulls

      public static <T> boolean isEmptyOrNulls(T[] c)
      Tests if the given array is null, empty or contains only null values.
      Parameters:
      c - Array to test.
      Returns:
      Whether or not the given array is null, empty or contains only null values.
    • isEmpty

      public static boolean isEmpty(int[] c)
      Tests if the given array is either null or empty.
      Parameters:
      c - Array to test.
      Returns:
      Whether or not the given array is null or empty.
    • isEmpty

      public static boolean isEmpty(byte[] c)
      Tests if the given array is either null or empty.
      Parameters:
      c - Array to test.
      Returns:
      Whether or not the given array is null or empty.
    • isEmpty

      public static boolean isEmpty(long[] c)
      Tests if the given array is either null or empty.
      Parameters:
      c - Array to test.
      Returns:
      Whether or not the given array is null or empty.
    • isEmpty

      public static boolean isEmpty(Iterable<?> c)
      Tests if the given collection is either null or empty.
      Parameters:
      c - Collection to test.
      Returns:
      Whether or not the given collection is null or empty.
    • isEmpty

      public static boolean isEmpty(Collection<?> c)
      Tests if the given collection is either null or empty.
      Parameters:
      c - Collection to test.
      Returns:
      Whether or not the given collection is null or empty.
    • isEmpty

      public static boolean isEmpty(Map<?,?> m)
      Tests if the given map is either null or empty.
      Parameters:
      m - Map to test.
      Returns:
      Whether or not the given collection is null or 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 to true ( 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 to true for.
      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 - If true, 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

      public static <T> int size(Iterator<? extends T> it, 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.
    • t

      public static <V1, V2> IgniteBiTuple<V1,V2> t(V1 v1, 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.
    • 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" transformed elements for which all provided predicate, if any, evaluates to true. 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 method size() 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

      public static GridClosureException wrap(Throwable e)
      Shortcut method that creates an instance of GridClosureException.
      Parameters:
      e - Exception to wrap.
      Returns:
      Newly created instance of GridClosureException.