java.lang.Object
ushiosan.jvm_utilities.lang.collection.elements.Pair<T,K>
Type Parameters:
T - first element type
K - second element type
Direct Known Subclasses:
Trio

public class Pair<T,K> extends Object
Immutable object used to represent elements with 2 values (element pair). It is an alternative to "input" type objects because its value is read-only.
  • Field Details

    • first

      public final T first
      First pair element
    • second

      public final K second
      Second pair element
  • Constructor Details

    • Pair

      public Pair(T first, K second)
      Default constructor
      Parameters:
      first - first element
      second - second element
  • Method Details

    • of

      @Contract(value="_, _ -> new", pure=true) @NotNull public static <T, K> @NotNull Pair<T,K> of(T first, K second)
      Shortcut pair instance
      Type Parameters:
      T - generic first type
      K - generic second type
      Parameters:
      first - first value
      second - second value
      Returns:
      instance of Pair class
    • copyOf

      @Contract("_ -> new") @NotNull public static <T, K> @NotNull Pair<T,K> copyOf(@NotNull Map.Entry<T,K> entry)
      Copies the content of a map entry and converts it to a Pair object.
      Type Parameters:
      T - first element type
      K - second element type
      Parameters:
      entry - the entry to copy
      Returns:
      an instance of Pair with entry content
    • extractPairs

      public static <T, K> Pair<T,K> @NotNull [] extractPairs(@NotNull @NotNull Map<T,K> map)
      Extracts all map entries and converts them to Pair objects.
      Type Parameters:
      T - first element type
      K - second element type
      Parameters:
      map - the map to inspect
      Returns:
      an array with all map pairs
    • extractPairs

      public static Pair<String,String> @NotNull [] extractPairs(@NotNull @NotNull Properties props)
      Extracts all properties entries and converts them to Pair objects.
      Parameters:
      props - the properties to inspect
      Returns:
      an array with all property pairs
    • toString

      public String toString()
      Object string representation
      Overrides:
      toString in class Object
      Returns:
      object string representation