Class Either.OfTwo<A,​B>

  • Type Parameters:
    A - the type of the first possible value
    B - the type of the second possible value
    Enclosing class:
    Either

    public static class Either.OfTwo<A,​B>
    extends Object
    Represents an exclusive choice between two possible types.
    • Constructor Detail

      • OfTwo

        protected OfTwo​(A first,
                        B second,
                        Either.Selector selector)
        Constructs an OfTwo object with the specified values and selector.
        Parameters:
        first - the value of the first option
        second - the value of the second option
        selector - the selector indicating the current choice
    • Method Detail

      • first

        public static <A,​B> Either.OfTwo<A,​B> first​(A first)
        Creates an OfTwo instance with the first value selected.
        Type Parameters:
        A - the type of the first value
        B - the type of the second value
        Parameters:
        first - the value of the first option
        Returns:
        an OfTwo instance with the first value selected
      • second

        public static <A,​B> Either.OfTwo<A,​B> second​(B second)
        Creates an OfTwo instance with the second value selected.
        Type Parameters:
        A - the type of the first value
        B - the type of the second value
        Parameters:
        second - the value of the second option
        Returns:
        an OfTwo instance with the second value selected
      • getFirst

        public A getFirst()
        Gets the first value if selected.
        Returns:
        the first value
        Throws:
        IllegalStateException - if the current selection is not First
      • getSecond

        public B getSecond()
        Gets the second value if selected.
        Returns:
        the second value
        Throws:
        IllegalStateException - if the current selection is not Second
      • getSelector

        public Either.Selector getSelector()
        Gets the current selector.
        Returns:
        the Selector indicating the current selection