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
      • first

        @Contract(mutates="this")
        public Pair<F,​S> first​(F first)
        Use to set the first value.
        Parameters:
        first - first value
        Returns:
        current instance of Pair
      • 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
      • clear

        public Pair<F,​S> clear()
        Remove both values to null from the Pair.
        Returns:
        current instance of Pair
      • deleteFirst

        @Contract(mutates="this")
        public Pair<F,​S> deleteFirst()
        Reset the first value to null.
        Returns:
        current instance of Pair
      • deleteSecond

        @Contract(mutates="this")
        public Pair<F,​S> deleteSecond()
        Reset the second value to null.
        Returns:
        current instance of Pair
      • getSecond

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

        @Contract(value=" -> new",
                  pure=true)
        @NotNull
        public @NotNull Pair<S,​F> swap()
        Swap the first and second values.
        Returns:
        instance of Pair with swapped values
      • second

        @Contract(mutates="this")
        public Pair<F,​S> second​(S second)
        Use to set the second value.
        Parameters:
        second - second value
        Returns:
        current instance of Pair
      • 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