Class OneOf4<A,​B,​C,​D>


  • public abstract class OneOf4<A,​B,​C,​D>
    extends java.lang.Object
    Holds one of 4 values. See OneOf2 for a full description. If you're passing the same type, you probably want a tuple instead.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected OneOf4​(java.lang.Object o, java.lang.Class<A> aClass, java.lang.Class<B> bClass, java.lang.Class<C> cClass, java.lang.Class<D> dClass, int index)
      Protected constructor for subclassing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object other)  
      int hashCode()  
      <R> R match​(Fn1<A,​R> fa, Fn1<B,​R> fb, Fn1<C,​R> fc, Fn1<D,​R> fd)
      Languages that have union types built in have a match statement that works like this method.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • OneOf4

        protected OneOf4​(java.lang.Object o,
                         java.lang.Class<A> aClass,
                         java.lang.Class<B> bClass,
                         java.lang.Class<C> cClass,
                         java.lang.Class<D> dClass,
                         int index)
        Protected constructor for subclassing.
        Parameters:
        o - the item (may be null)
        aClass - class 0 (to have at runtime for descriptive error messages and toString()).
        bClass - class 1 (to have at runtime for descriptive error messages and toString()).
        cClass - class 2 (to have at runtime for descriptive error messages and toString()).
        dClass - class 3 (to have at runtime for descriptive error messages and toString()).
        index - 0 means this represents an A, 1 represents a B, 2 represents a C, 3 means D
    • Method Detail

      • match

        public <R> R match​(Fn1<A,​R> fa,
                           Fn1<B,​R> fb,
                           Fn1<C,​R> fc,
                           Fn1<D,​R> fd)
        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 - the function to be executed if this OneOf stores the first type.
        fb - the function to be executed if this OneOf stores the second type.
        fc - the function to be executed if this OneOf stores the third type.
        fd - the function to be executed if this OneOf stores the fourth type.
        Returns:
        the return value of whichever function is executed.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object