Skip to content

Latest commit

 

History

History
103 lines (87 loc) · 2.85 KB

README.md

File metadata and controls

103 lines (87 loc) · 2.85 KB

Java More Primitive Pairs

Provides pair classes with the same interface as the Apache Commons Pair classes, but with versions specialized to boolean, byte, char, and float, allowing users to avoid the cost of working with boxed types. This library supplements Java Primitive Pairs, adding to its double, int, and long pair classes.

To include the library in your project (Java 7+ supported), add the following to your POM:

<project>
...
    <dependencies>
        ...
        <dependency>
            <groupId>net.mintern</groupId>
            <artifactId>more-primitive-pairs</artifactId>
            <version>1.0</version>
        </dependency>
        ...
    </dependencies>
...
</project>

Sample usage

List<CharIntPair> enumerated = new ArrayList<>();
int i = 0;
for (char c: myString.toCharArray()) {
    enumerated.add(CharIntPair.of(c, i++));
}

Pair types

As with the Apache Commons Pair, each pair type is comprised of a base FooPair, an ImmutableFooPair, and a MutableFooPair. The supported combinations are:

  • ObjFloatPair
  • ObjCharPair
  • ObjBytePair
  • ObjBooleanPair
  • DoubleFloatPair
  • DoubleCharPair
  • DoubleBytePair
  • DoubleBooleanPair
  • LongFloatPair
  • LongCharPair
  • LongBytePair
  • LongBooleanPair
  • IntFloatPair
  • IntCharPair
  • IntBytePair
  • IntBooleanPair
  • FloatLongPair
  • FloatIntPair
  • FloatPair (two floats)
  • FloatCharPair
  • FloatBytePair
  • FloatBooleanPair
  • CharLongPair
  • CharIntPair
  • CharPair (two chars)
  • CharBytePair
  • CharBooleanPair
  • ByteLongPair
  • ByteIntPair
  • BytePair (two bytes)
  • ByteBooleanPair
  • BooleanLongPair
  • BooleanIntPair
  • BooleanPair (two booleans)

In concert with primitive-pairs, this library provides all possible combinations for these 8 types. If you order the types as Object, Double, Long, Int, Float, Char, Byte, Boolean, then the widest type comes first.

The *IntPairs and *LongPairs are the only exceptions to this pattern. Because of the shape of classes like ObjIntPair and ObjLongPair, a pair that consists of a value and its corresponding index would typically have the index second. By providing pairs with int and long as the second item, the (value, index) pattern can be used consistently for all types.

Contributing

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.

Building

In the root directory, run mvn install. That will build everything.

Related projects

All of my Java libraries are available in the mintern-java organization.