Provides pair classes with the same interface as the Apache Commons Pair
classes,
but with versions specialized to double, int, and long, allowing users
to avoid the cost of working with boxed types. If additional types are needed,
More Primitive Pairs
includes float, char, byte, and boolean specializations.
To include the library in your project (Java 7+ supported), add the following to your POM:
<project>
...
<dependencies>
...
<dependency>
<groupId>net.mintern</groupId>
<artifactId>primitive-pairs</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
...
</project>List<ObjIntPair<String>> enumerated = new ArrayList<>();
int i = 0;
for (String s: myStrings) {
enumerated.add(ObjIntPair.of(s, i++));
}As with the Apache Commons Pair, each pair type is comprised of a base
FooPair, an ImmutableFooPair, and a MutableFooPair. The supported
combinations are:
ObjDoublePairObjLongPairObjIntPairDoublePair(twodoubles)DoubleLongPairDoubleIntPairLongPair(twolongs)LongIntPairIntLongPairIntPair(twoints)
For these four types, this provides all possible combinations. (The
ObjPair, of course, is simply Apache's Pair.) If you order the types as
Object, Double, Long, Int, then the widest type comes first.
IntLongPair is the only exception to this pattern. Because of the shape of
classes like ObjIntPair and DoubleIntPair, a pair that consists of a value
and its corresponding index would typically have the index second. Since
long can also be used to number sequences, it seemed useful to provide an
IntLongPair for numbering a series of int values without reversing the
typical (value, index) pattern encouraged by the rest of this library.
I will happily accept Pull Requests. If you have any questions, ask away. Please keep changes to a minimum; do not make gratuitous style changes.
In the root directory, run mvn install. That will build everything.
All of my Java libraries are available in the mintern-java organization.