See: Description
| Interface | Description |
|---|---|
| ComparablePair<First extends Comparable<? super First>,Second extends Comparable<? super Second>> |
A
Pair which is Comparable. |
| ComparableSerializablePair<First extends Serializable & Comparable<? super First>,Second extends Serializable & Comparable<? super Second>> | |
| Pair<First,Second> |
A pair consisting of a first (left) and a second (right) component.
|
| SerializablePair<First extends Serializable,Second extends Serializable> |
A
Pair which is Serializable. |
| Class | Description |
|---|---|
| Pairs |
Static methods for dealing with all sorts of pairs.
|
This package provides ordered pairs that consist of a first (left) and a second (right) component. There are four pair types defined as the following interfaces:
Instances of this classes can be created using the
Pairs utility class. For every interface
there is a static builder function:
Pairs.from(Object, Object)
- creates a simple Pair.
Pairs.fromComparables(Comparable, Comparable)
- creates a Pair from Comparables. The Pair is itself comparable.
Pairs.fromSerializables(java.io.Serializable, java.io.Serializable)
- creates a Pair from Serializables. The Pair is itself serializable.
Pairs.fromComparableSerializables(java.io.Serializable, java.io.Serializable)
- creates a Pair from components that are both Comparable and Serializable.
The Pair is itself comparable and serializable.
All instances that can be created using this package are immutable and
defining interfaces do not suggest setters/mutability. This is also the reason
why the Pairs here do not extend Map.Entry (unlinke e.g. the
Apache Commons Pair).
Every know and then I found myself badly needing (wanting?) a Pair. A lot of libraries ship with either their own definition of a pair or pull in other libraries that provide one. But why should I use yet-another-utility-belt (most probably in addition to the one I already pulled in) just for having a Pair class when I do not need anything else from it?
Copyright © 2015. All rights reserved.