Class Variant6<T1,​T2,​T3,​T4,​T5,​T6>

  • Type Parameters:
    T1 - Represents the variants first type.
    T2 - Represents the variants second type.
    T3 - Represents the variants third type.
    T4 - Represents the variants fourth type.
    T5 - Represents the variants fifth type.
    T6 - Represents the variants sixth type.

    public class Variant6<T1,​T2,​T3,​T4,​T5,​T6>
    extends VariantBase
    Represents a 6-type discriminate union.
    
     class Sample {
         static void Example() {
             // A variant can hold a value of any of its generic types
             Variant3<Integer, String, Double> variant = new Variant3<Integer, String, Double>(42);
    
             // Can reassign variant with another of its generic types
             variant.set("Hello world!");
    
             // Check the type of the value currently inhabiting the variant
             if (variant.is(String.class)) {
                 System.out.println("The string is: " + variant.<String>get());
             }
    
             variant.set(0.5);
    
             // The right function will get picked depending on the value
             // currently inhabiting the variant
             variant.apply(
                 (i) -> System.out.println(i + 1),
                 (s) -> System.out.println(s + "!"),
                 (d) -> System.out.println(d / 2));
         }
     }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Variant6​(T1 item, TypeGuard1... guard)
      Creates a new Variant instance from an item of type T1.
      Variant6​(T2 item, TypeGuard2... guard)
      Creates a new Variant instance from an item of type T2.
      Variant6​(T3 item, TypeGuard3... guard)
      Creates a new Variant instance from an item of type T3.
      Variant6​(T4 item, TypeGuard4... guard)
      Creates a new Variant instance from an item of type T4.
      Variant6​(T5 item, TypeGuard5... guard)
      Creates a new Variant instance from an item of type T5.
      Variant6​(T6 item, TypeGuard6... guard)
      Creates a new Variant instance from an item of type T6.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void apply​(java.util.function.Consumer<T1> consumer1, java.util.function.Consumer<T2> consumer2, java.util.function.Consumer<T3> consumer3, java.util.function.Consumer<T4> consumer4, java.util.function.Consumer<T5> consumer5, java.util.function.Consumer<T6> consumer6)
      Applies one of the given consumers to the variant depending on the type currently inhabiting the variant.
      <R> R apply​(java.util.function.Function<T1,​R> func1, java.util.function.Function<T2,​R> func2, java.util.function.Function<T3,​R> func3, java.util.function.Function<T4,​R> func4, java.util.function.Function<T5,​R> func5, java.util.function.Function<T6,​R> func6)
      Applies one of the given functions to the variant depending on the type currently inhabiting the variant.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T1 item, TypeGuard1... guard)
      Creates a new Variant given an item of type T1.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T2 item, TypeGuard2... guard)
      Creates a new Variant given an item of type T2.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T3 item, TypeGuard3... guard)
      Creates a new Variant given an item of type T3.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T4 item, TypeGuard4... guard)
      Creates a new Variant given an item of type T4.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T5 item, TypeGuard5... guard)
      Creates a new Variant given an item of type T5.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make​(T6 item, TypeGuard6... guard)
      Creates a new Variant given an item of type T6.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make1​(T1 item)
      Creates a new Variant given an item of type T1 explicitly placed at index 0.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make2​(T2 item)
      Creates a new Variant given an item of type T2 explicitly placed at index 1.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make3​(T3 item)
      Creates a new Variant given an item of type T3 explicitly placed at index 2.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make4​(T4 item)
      Creates a new Variant given an item of type T4 explicitly placed at index 3.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make5​(T5 item)
      Creates a new Variant given an item of type T5 explicitly placed at index 4.
      static <T1,​T2,​T3,​T4,​T5,​T6>
      Variant6<T1,​T2,​T3,​T4,​T5,​T6>
      make6​(T6 item)
      Creates a new Variant given an item of type T6 explicitly placed at index 5.
      <U1,​U2,​U3,​U4,​U5,​U6>
      Variant6<U1,​U2,​U3,​U4,​U5,​U6>
      map​(java.util.function.Function<T1,​U1> func1, java.util.function.Function<T2,​U2> func2, java.util.function.Function<T3,​U3> func3, java.util.function.Function<T4,​U4> func4, java.util.function.Function<T5,​U5> func5, java.util.function.Function<T6,​U6> func6)
      Applies one of the given functions to the variant depending on the type currently inhabiting the variant.
      void set​(T1 item, TypeGuard1... guard)
      Assigns an item of type T1 to the variant.
      void set​(T2 item, TypeGuard2... guard)
      Assigns an item of type T2 to the variant.
      void set​(T3 item, TypeGuard3... guard)
      Assigns an item of type T3 to the variant.
      void set​(T4 item, TypeGuard4... guard)
      Assigns an item of type T4 to the variant.
      void set​(T5 item, TypeGuard5... guard)
      Assigns an item of type T5 to the variant.
      void set​(T6 item, TypeGuard6... guard)
      Assigns an item of type T6 to the variant.
      void set1​(T1 item)
      Explicitly assigns an item of type T1 at index 0.
      void set2​(T2 item)
      Explicitly assigns an item of type T2 at index 1.
      void set3​(T3 item)
      Explicitly assigns an item of type T3 at index 2.
      void set4​(T4 item)
      Explicitly assigns an item of type T4 at index 3.
      void set5​(T5 item)
      Explicitly assigns an item of type T5 at index 4.
      void set6​(T6 item)
      Explicitly assigns an item of type T6 at index 5.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Variant6

        public Variant6​(T1 item,
                        TypeGuard1... guard)
        Creates a new Variant instance from an item of type T1.
        Parameters:
        item - Item of type T1.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • Variant6

        public Variant6​(T2 item,
                        TypeGuard2... guard)
        Creates a new Variant instance from an item of type T2.
        Parameters:
        item - Item of type T2.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • Variant6

        public Variant6​(T3 item,
                        TypeGuard3... guard)
        Creates a new Variant instance from an item of type T3.
        Parameters:
        item - Item of type T3.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • Variant6

        public Variant6​(T4 item,
                        TypeGuard4... guard)
        Creates a new Variant instance from an item of type T4.
        Parameters:
        item - Item of type T4.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • Variant6

        public Variant6​(T5 item,
                        TypeGuard5... guard)
        Creates a new Variant instance from an item of type T5.
        Parameters:
        item - Item of type T5.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • Variant6

        public Variant6​(T6 item,
                        TypeGuard6... guard)
        Creates a new Variant instance from an item of type T6.
        Parameters:
        item - Item of type T6.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
    • Method Detail

      • set

        public void set​(T1 item,
                        TypeGuard1... guard)
        Assigns an item of type T1 to the variant.
        Parameters:
        item - Item of type T1.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set

        public void set​(T2 item,
                        TypeGuard2... guard)
        Assigns an item of type T2 to the variant.
        Parameters:
        item - Item of type T2.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set

        public void set​(T3 item,
                        TypeGuard3... guard)
        Assigns an item of type T3 to the variant.
        Parameters:
        item - Item of type T3.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set

        public void set​(T4 item,
                        TypeGuard4... guard)
        Assigns an item of type T4 to the variant.
        Parameters:
        item - Item of type T4.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set

        public void set​(T5 item,
                        TypeGuard5... guard)
        Assigns an item of type T5 to the variant.
        Parameters:
        item - Item of type T5.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set

        public void set​(T6 item,
                        TypeGuard6... guard)
        Assigns an item of type T6 to the variant.
        Parameters:
        item - Item of type T6.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
      • set1

        public void set1​(T1 item)
        Explicitly assigns an item of type T1 at index 0.
        Parameters:
        item - Item of type T1.
      • set2

        public void set2​(T2 item)
        Explicitly assigns an item of type T2 at index 1.
        Parameters:
        item - Item of type T2.
      • set3

        public void set3​(T3 item)
        Explicitly assigns an item of type T3 at index 2.
        Parameters:
        item - Item of type T3.
      • set4

        public void set4​(T4 item)
        Explicitly assigns an item of type T4 at index 3.
        Parameters:
        item - Item of type T4.
      • set5

        public void set5​(T5 item)
        Explicitly assigns an item of type T5 at index 4.
        Parameters:
        item - Item of type T5.
      • set6

        public void set6​(T6 item)
        Explicitly assigns an item of type T6 at index 5.
        Parameters:
        item - Item of type T6.
      • apply

        public <R> R apply​(java.util.function.Function<T1,​R> func1,
                           java.util.function.Function<T2,​R> func2,
                           java.util.function.Function<T3,​R> func3,
                           java.util.function.Function<T4,​R> func4,
                           java.util.function.Function<T5,​R> func5,
                           java.util.function.Function<T6,​R> func6)
        Applies one of the given functions to the variant depending on the type currently inhabiting the variant.
        Type Parameters:
        R - Represents the return type of all functions.
        Parameters:
        func1 - Function to apply on type T1.
        func2 - Function to apply on type T2.
        func3 - Function to apply on type T3.
        func4 - Function to apply on type T4.
        func5 - Function to apply on type T5.
        func6 - Function to apply on type T6.
        Returns:
        Result of applying function.
      • apply

        public void apply​(java.util.function.Consumer<T1> consumer1,
                          java.util.function.Consumer<T2> consumer2,
                          java.util.function.Consumer<T3> consumer3,
                          java.util.function.Consumer<T4> consumer4,
                          java.util.function.Consumer<T5> consumer5,
                          java.util.function.Consumer<T6> consumer6)
        Applies one of the given consumers to the variant depending on the type currently inhabiting the variant.
        Parameters:
        consumer1 - Consumer to apply on type T1.
        consumer2 - Consumer to apply on type T2.
        consumer3 - Consumer to apply on type T3.
        consumer4 - Consumer to apply on type T4.
        consumer5 - Consumer to apply on type T5.
        consumer6 - Consumer to apply on type T6.
      • map

        public <U1,​U2,​U3,​U4,​U5,​U6> Variant6<U1,​U2,​U3,​U4,​U5,​U6> map​(java.util.function.Function<T1,​U1> func1,
                                                                                                                               java.util.function.Function<T2,​U2> func2,
                                                                                                                               java.util.function.Function<T3,​U3> func3,
                                                                                                                               java.util.function.Function<T4,​U4> func4,
                                                                                                                               java.util.function.Function<T5,​U5> func5,
                                                                                                                               java.util.function.Function<T6,​U6> func6)
        Applies one of the given functions to the variant depending on the type currently inhabiting the variant.
        Type Parameters:
        U1 - Represents the return type of func1.
        U2 - Represents the return type of func2.
        U3 - Represents the return type of func3.
        U4 - Represents the return type of func4.
        U5 - Represents the return type of func5.
        U6 - Represents the return type of func6.
        Parameters:
        func1 - Function to apply on type T1.
        func2 - Function to apply on type T2.
        func3 - Function to apply on type T3.
        func4 - Function to apply on type T4.
        func5 - Function to apply on type T5.
        func6 - Function to apply on type T6.
        Returns:
        Variant containing the result of applying the selected function.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T1 item,
                                                                                                                                       TypeGuard1... guard)
        Creates a new Variant given an item of type T1.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T1.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T2 item,
                                                                                                                                       TypeGuard2... guard)
        Creates a new Variant given an item of type T2.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T2.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T3 item,
                                                                                                                                       TypeGuard3... guard)
        Creates a new Variant given an item of type T3.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T3.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T4 item,
                                                                                                                                       TypeGuard4... guard)
        Creates a new Variant given an item of type T4.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T4.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T5 item,
                                                                                                                                       TypeGuard5... guard)
        Creates a new Variant given an item of type T5.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T5.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make​(T6 item,
                                                                                                                                       TypeGuard6... guard)
        Creates a new Variant given an item of type T6.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T6.
        guard - TypeGuards are used to disambiguate methods after type erasure, no argument should be supplied.
        Returns:
        A Variant containing the given item.
      • make1

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make1​(T1 item)
        Creates a new Variant given an item of type T1 explicitly placed at index 0.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T1.
        Returns:
        A Variant containing the given item at index 0.
      • make2

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make2​(T2 item)
        Creates a new Variant given an item of type T2 explicitly placed at index 1.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T2.
        Returns:
        A Variant containing the given item at index 1.
      • make3

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make3​(T3 item)
        Creates a new Variant given an item of type T3 explicitly placed at index 2.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T3.
        Returns:
        A Variant containing the given item at index 2.
      • make4

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make4​(T4 item)
        Creates a new Variant given an item of type T4 explicitly placed at index 3.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T4.
        Returns:
        A Variant containing the given item at index 3.
      • make5

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make5​(T5 item)
        Creates a new Variant given an item of type T5 explicitly placed at index 4.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T5.
        Returns:
        A Variant containing the given item at index 4.
      • make6

        public static <T1,​T2,​T3,​T4,​T5,​T6> Variant6<T1,​T2,​T3,​T4,​T5,​T6> make6​(T6 item)
        Creates a new Variant given an item of type T6 explicitly placed at index 5.
        Type Parameters:
        T1 - Represents the variants first type.
        T2 - Represents the variants second type.
        T3 - Represents the variants third type.
        T4 - Represents the variants fourth type.
        T5 - Represents the variants fifth type.
        T6 - Represents the variants sixth type.
        Parameters:
        item - Item of type T6.
        Returns:
        A Variant containing the given item at index 5.