Class Functions

java.lang.Object
com.atlassian.jira.util.Functions

public class Functions extends Object
Useful standard functions.
  • Constructor Details

    • Functions

      public Functions()
  • Method Details

    • memoize

      public static <T, R> Function<T,R> memoize(Function<T,R> function, ConcurrentMap<T,R> map)
      Memoizer maps an input to an output and always returns the mapped result rather than calling the wrapped function every time. Useful when the wrapped function is expensive to call.

      Note, once mapped the input and the result can only be externally removed. Also, if the supplied function returns nulls then no memoization will occur.

      Type Parameters:
      T - the input type. MUST be immutable.
      R - the result type.
      Parameters:
      function - for supplying the initial value that gets mapped
      map - for storing the key-value mappings
      Returns:
      a memoizing function.
    • identity

      public static <T> Function<T,T> identity()
      Get a function that always returns the input.
      Type Parameters:
      T - the type of the input and the output for the function.
      Returns:
      the identity function.
    • mappedVisitor

      public static <T, V> Visitor<T> mappedVisitor(Function<T,V> mappingFunction, Visitor<V> delegate)
      Get a visitor that will apply the given function before delegating to another visitor.
      Type Parameters:
      T - the inferred type of the function's input
      V - the inferred type of the function's output, which will be passed to the delegate visitor
      Parameters:
      mappingFunction - the mapping function to apply
      delegate - the visitor to call with the function output values
      Returns:
      a visitor that will accept input values for the function
    • downcast

      public static <T, R extends T> Function<T,R> downcast(Class<R> subclass)
      Get a function that always the input downcast to the supplied class.
      Type Parameters:
      T - the type of the input and the output for the function.
      Returns:
      the identity function.
    • coerceToSuper

      public static <S, T extends S> Function<T,S> coerceToSuper()
      Transform to a super class. Usually needs to be called with explicit type parameters, eg: Functions.<SuperClass, SubClass> coerceToSuper();
      Type Parameters:
      S - the super class.
      T - the sub class.
    • toGoogleFunction

      public static <T, R> com.google.common.base.Function<T,R> toGoogleFunction(Function<T,R> function)
      Map to a google-collections Function.
      Type Parameters:
      T - input type
      R - output type
      Parameters:
      function - the function to map
      Returns:
      the mapped function.