Class Pair<L,R>
- java.lang.Object
-
- so.dang.cool.Pair<L,R>
-
- Type Parameters:
L- The left typeR- The right type The identical class (source identical) is vended as two versions:Pairand itsgetLeft()andgetRight()methods are fine to use forever. (Although, I'd recommend an immutable type instead if you can get/make it, and to give better context than left/right)Pairand itsgetLeft()andgetRight()methods are a band-aid forClassNotFoundExceptionerrors encountered when upgrading to JDK 11 or higher.The
ClassNotFoundExceptionis tricky.Pairis part of a JavaFX visual effects framework, and that was part of many JDK distributions for a while. The Pair type in particular attracted a bit of usage, but in ways that are unmodeled in package management. (Hey it makes sense, it was just part of the JDK after all.) Now, it's easy enough to upgrade your own code, but if some other dependency was trying to use this tempting little pair class... failure! There's a similar story for library vendors when trying to raise the version required and the effect on your consumers.Unless you're trying to get Unless you intend to do visual effects, bringing in the whole JavaFX project will be too much size/hassle/etc for many cases. Therefore, we can use this tiny little dependency as a shim until unneeded.
A no-dependency alternative is the "Entry" type of Map classes. For example
java.util.AbstractMap.SimpleEntry<K,V>orjava.util.AbstractMap.SimpleImmutableEntry<K,V>
- All Implemented Interfaces:
java.io.Serializable
public class Pair<L,R> extends java.lang.Object implements java.io.SerializableA pair of two values, a left and a right.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object that)LgetKey()Deprecated.LgetLeft()Get the left value.RgetRight()Get the right value.LgetValue()Deprecated.inthashCode()static <L,R>
Pair<L,R>of(L left, R right)Make a Pair of things.java.lang.StringtoString()
-
-
-
Method Detail
-
of
public static final <L,R> Pair<L,R> of(L left, R right)
Make a Pair of things.- Type Parameters:
L- The left typeR- The right type- Parameters:
left- The left thingright- The right thing- Returns:
- a new Pair
-
getLeft
public L getLeft()
Get the left value.- Returns:
- the left value
-
getKey
@Deprecated public L getKey()
Deprecated.Get the left value. An alias for thegetLeft()method, the "getKey" convention is to support use cases wherePairwas used and may be difficult to untangle.- Returns:
- the left value
-
getRight
public R getRight()
Get the right value.- Returns:
- the right value
-
getValue
@Deprecated public L getValue()
Deprecated.Get the right value. An alias for thegetRight()method, the "getKey" convention is to support use cases wherePairwas used and may be difficult to untangle.- Returns:
- the right value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equalsin classjava.lang.Object
-
-