Class Match<I,​R>

  • Type Parameters:
    I - the input type, that this PartialFunction will be applied to
    R - the return type, that the results of the application will have

    public class Match<I,​R>
    extends java.lang.Object
    Version of PartialFunction that can be built during runtime from Java.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected scala.PartialFunction<I,​R> statements  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      scala.PartialFunction<I,​R> asPF()
      Turn this Match into a PartialFunction.
      static <F,​T>
      Match<F,​T>
      create​(PFBuilder<F,​T> builder)
      Create a Match from the builder.
      R match​(I i)
      Convenience function to make the Java code more readable.
      static <F,​T,​P>
      PFBuilder<F,​T>
      match​(java.lang.Class<P> type, FI.Apply<P,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      static <F,​T,​P>
      PFBuilder<F,​T>
      match​(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.Apply<P,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      static <F,​T>
      PFBuilder<F,​T>
      matchAny​(FI.Apply<F,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      static <F,​T,​P>
      PFBuilder<F,​T>
      matchEquals​(P object, FI.Apply<P,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      static <F,​T>
      PFBuilder<F,​T>
      matchUnchecked​(java.lang.Class<?> type, FI.Apply<?,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added without compile time type check of the parameters.
      static <F,​T>
      PFBuilder<F,​T>
      matchUnchecked​(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.Apply<?,​T> apply)
      Convenience function to create a PFBuilder with the first case statement added without compile time type check of the parameters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • statements

        protected final scala.PartialFunction<I,​R> statements
    • Method Detail

      • match

        public static <F,​T,​P> PFBuilder<F,​T> match​(java.lang.Class<P> type,
                                                                     FI.Apply<P,​T> apply)
        Convenience function to create a PFBuilder with the first case statement added.
        Parameters:
        type - a type to match the argument against
        apply - an action to apply to the argument if the type matches
        Returns:
        a builder with the case statement added
        See Also:
        PFBuilder.match(Class, FI.Apply)
      • matchUnchecked

        public static <F,​T> PFBuilder<F,​T> matchUnchecked​(java.lang.Class<?> type,
                                                                      FI.Apply<?,​T> apply)
        Convenience function to create a PFBuilder with the first case statement added without compile time type check of the parameters. Should normally not be used, but when matching on class with generic type argument it can be useful, e.g. List.class and (List<String> list) -> {}.
        See Also:
        PFBuilder.matchUnchecked(Class, FI.Apply)
      • match

        public static <F,​T,​P> PFBuilder<F,​T> match​(java.lang.Class<P> type,
                                                                     FI.TypedPredicate<P> predicate,
                                                                     FI.Apply<P,​T> apply)
        Convenience function to create a PFBuilder with the first case statement added.
        Parameters:
        type - a type to match the argument against
        predicate - a predicate that will be evaluated on the argument if the type matches
        apply - an action to apply to the argument if the type matches
        Returns:
        a builder with the case statement added
        See Also:
        PFBuilder.match(Class, FI.TypedPredicate, FI.Apply)
      • matchEquals

        public static <F,​T,​P> PFBuilder<F,​T> matchEquals​(P object,
                                                                           FI.Apply<P,​T> apply)
        Convenience function to create a PFBuilder with the first case statement added.
        Parameters:
        object - the object to compare equals with
        apply - an action to apply to the argument if the object compares equal
        Returns:
        a builder with the case statement added
        See Also:
        PFBuilder.matchEquals(Object, FI.Apply)
      • matchAny

        public static <F,​T> PFBuilder<F,​T> matchAny​(FI.Apply<F,​T> apply)
        Convenience function to create a PFBuilder with the first case statement added.
        Parameters:
        apply - an action to apply to the argument
        Returns:
        a builder with the case statement added
        See Also:
        PFBuilder.matchAny(FI.Apply)
      • create

        public static final <F,​T> Match<F,​T> create​(PFBuilder<F,​T> builder)
        Create a Match from the builder.
        Parameters:
        builder - a builder representing the partial function
        Returns:
        a Match that can be reused
      • match

        public R match​(I i)
                throws scala.MatchError
        Convenience function to make the Java code more readable.

        
           Match<X, Y> matcher = Match.create(...);
        
           Y someY = matcher.match(obj);
         
        Parameters:
        i - the argument to apply the match to
        Returns:
        the result of the application
        Throws:
        scala.MatchError - if there is no match
      • asPF

        public scala.PartialFunction<I,​R> asPF()
        Turn this Match into a PartialFunction.
        Returns:
        a partial function representation ot his Match