Class Pair<A,​B>

  • Type Parameters:
    A - first object in pair
    B - second object in pair

    public class Pair<A,​B>
    extends Object
    Custom pair class similar to C++. By default we compare based on the first value
    Author:
    markr
    • Field Detail

      • first

        protected final A first
        The first object in this Pair
      • second

        protected final B second
        The second object in this Pair
    • Constructor Detail

      • Pair

        protected Pair​(A first,
                       B second)
        Constructor
        Parameters:
        first - first object in pair
        second - second object in pair
    • Method Detail

      • create

        public static <A,​B> Pair<A,​B> create​(A valueA,
                                                         B valueB)
        Factory method
        Type Parameters:
        A - type of valueA
        B - type of valueB
        Parameters:
        valueA - first
        valueB - second
        Returns:
        new pair
      • first

        public A first()
        Get first object in pair
        Returns:
        first object in pair
      • second

        public B second()
        Get second object in pair
        Returns:
        second object in pair
      • anyIsNotNull

        public boolean anyIsNotNull()
        check if any of the two values is not null
        Returns:
        true when one of the entries is not null
      • bothNotNull

        public boolean bothNotNull()
        check if both values are not null
        Returns:
        true when both entries are not null
      • isExactlyOneNonNull

        public boolean isExactlyOneNonNull()
        Returns:
        true when exactly one of the two is not null
      • getEarliestNonNull

        public Object getEarliestNonNull()
        Returns:
        earliest entry (first before second) that is nonNull, when both are null, null is returned