Class Pair<F,​S>

  • Type Parameters:
    F - first value type
    S - second value type

    public final class Pair<F,​S>
    extends Object
    A pair of values. Two heads are better than one—sometimes.
    Since:
    2.0
    Author:
    Bobai Kato
    • Method Detail

      • of

        @Contract(value="_, _ -> new",
                  pure=true)
        @NotNull
        public static <F,​S> @NotNull Pair<F,​S> of​(F first,
                                                              S second)
        Creates a pair of values.
        Parameters:
        first - first value, can be null.
        second - second value, can be null.
        Returns:
        a pair of values
      • empty

        @Contract(value=" -> new",
                  pure=true)
        @NotNull
        public static <F,​S> @NotNull Pair<F,​S> empty()
        Create and empty pair.
        Type Parameters:
        F - first value type
        S - second value type
        Returns:
        new instance of empty pair
      • getFirst

        @Contract(pure=true)
        public F getFirst()
        Returns the first value.
        Returns:
        the first value
      • setFirst

        @Contract(mutates="this")
        public void setFirst​(F first)
        Use to set the first value.
        Parameters:
        first - first value
      • setFirstAndSecond

        @Contract(mutates="this")
        public void setFirstAndSecond​(F first,
                                      S second)
        Use to set the first and second values.
        Parameters:
        first - first value
        second - second value
      • reset

        public void reset()
        Reset both values to null.
      • deleteFirst

        @Contract(mutates="this")
        public void deleteFirst()
        Reset the first value to null.
      • deleteSecond

        @Contract(mutates="this")
        public void deleteSecond()
        Reset the second value to null.
      • getSecond

        @Contract(pure=true)
        public S getSecond()
        Returns the second value.
        Returns:
        the second value
      • setSecond

        @Contract(mutates="this")
        public void setSecond​(S second)
        Use to set the second value.
        Parameters:
        second - second value
      • isNotEmpty

        @Contract(pure=true)
        public boolean isNotEmpty()
        Returns true if both values are not null.
        Returns:
        true if both values are not null
      • isEmpty

        @Contract(pure=true)
        public boolean isEmpty()
        Returns true if both values are null.
        Returns:
        true if both values are null
      • notHasFirst

        @Contract(pure=true)
        public boolean notHasFirst()
        Check Pair not have the first value.
        Returns:
        true if Pair has no first value
      • hasFirst

        @Contract(pure=true)
        public boolean hasFirst()
        Check Pair has the first value.
        Returns:
        true if Pair has first value
      • notHasSecond

        @Contract(pure=true)
        public boolean notHasSecond()
        Check Pair not have the second value.
        Returns:
        true if Pair has no second value
      • hasSecond

        @Contract(pure=true)
        public boolean hasSecond()
        Check Pair has the second value.
        Returns:
        true if Pair has second value
      • hashCode

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

        @Contract(value="null -> false",
                  pure=true)
        public boolean equals​(Object o)
        Overrides:
        equals in class Object
      • toString

        @Contract(pure=true)
        @NotNull
        public @NotNull String toString()
        Overrides:
        toString in class Object