Clone wiki

dollar / Home

Dollar

Dollar is 100% Java6 (no bytecode manipulation) with no dependencies besides JDK6. It has fluent builders for Lists, Sets and Maps, boxing and (null-safe) unboxing of primitive arrays, and advanced array boxing (e.g. int[] -> List<Integer>). It's open-source (LGPL version 3).

Dollar also has:

  • Lazy filtering and mapping.
  • A bunch of additional core methods: `min, max, each, any, all, find, indexOf, reduce`
  • Simple DSL for creating random numbers.
  • Ranges: $(begin, end)
  • pull requests are welcome and encouraged
import static org.bitbucket.dollar.Dollar.*;
// yes, $ is a valid Java identifier! 
// repeat a String
String repeat = $("abc").repeat(3).join(" "); // "abc abc abc"

// convert and sort a Long[] to long[] 
Long[] aLongArray = { 42L, 84L };
long[] longs = $(aLongArray).sort().toLongArray();

// fluent interface: convert a primitive int array to java.util.List, in the reversed order
int[] array = { 4, 2, -5 };
List<Integer> list = $(array).sort().reverse().toList();

// you can even unbox a short[] array to long[] (since it doesn't cause a loss of precision)
short[] shorts = { 42, 42, 42 };
long[] longs = $(shorts).toLongArray();

// build a sorted random list of 50 integers up to 100
List<Integer> randomIntegers = $(new Random(), 100).samples(50).sort().toList();

// syntactic sugar
$("a string").size();    // "a string".length()
$(aCollection).size();  //  aCollection.size()
$(anArray).size();       // anArray.length
$(array).toString();     // calls Arrays.toString()
int max = $(array).max(); // finds maximum value

Using Maven

Dollar uses Maven and is in Maven Central. Here's how to include it:

Gradle: compile 'org.bitbucket.dollar:dollar:1.0-beta3'

Maven:

	<dependency>
		<groupId>org.bitbucket.dollar</groupId>
		<artifactId>dollar</artifactId>
		<version>1.0-beta3</version>
	</dependency>

TODO

  • 1.0-beta4: more javadocs, remove deprecated methods

Updated