Class OneOf5<A,​B,​C,​D,​E>


  • public abstract class OneOf5<A,​B,​C,​D,​E>
    extends Object
    Holds one of 5 types of value. See OneOf2 for a full description.
    • Field Detail

      • item

        @NotNull
        protected final @NotNull Object item
    • Constructor Detail

      • OneOf5

        protected OneOf5​(@NotNull
                         @NotNull Object o,
                         @NotNull
                         @NotNull Class<A> aClass,
                         @NotNull
                         @NotNull Class<B> bClass,
                         @NotNull
                         @NotNull Class<C> cClass,
                         @NotNull
                         @NotNull Class<D> dClass,
                         @NotNull
                         @NotNull Class<E> eClass,
                         int index)
        Protected constructor for subclassing.
        Parameters:
        o - the item
        aClass - class 0
        bClass - class 1
        cClass - class 2
        dClass - class 3
        eClass - class 4
        index - 0 means this represents an A, 1 a B, 2 a C, 3 a D, and 4 an E.
    • Method Detail

      • match

        public <R> R match​(@NotNull
                           @NotNull Fn1<A,​R> fa,
                           @NotNull
                           @NotNull Fn1<B,​R> fb,
                           @NotNull
                           @NotNull Fn1<C,​R> fc,
                           @NotNull
                           @NotNull Fn1<D,​R> fd,
                           @NotNull
                           @NotNull Fn1<E,​R> fe)
        Languages that have union types built in have a match statement that works like this method. Exactly one of these functions will be executed - determined by which type of item this object holds.
        Parameters:
        fa - applied iff this stores the first type.
        fb - applied iff this stores the second type.
        fc - applied iff this stores the third type.
        fd - applied iff this stores the fourth type.
        fe - applied iff this stores the fifth type.
        Returns:
        the return value of whichever function is executed.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object