|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object util.Builders
public final class Builders
Utility methods for specifying data concisely in code. The next-best thing to map and collection literals.
The purpose is easiest to see by example:
Mapnumbers = Builders.buildMap( new TreeMap ()) .put(0, "zero") .put(1, "one") .put(2, "two") .put(3, "three") .finishMap();
Nested Class Summary | |
---|---|
static interface |
Builders.Builder<C>
An object with methods that add to a collection and can be chained together. |
static interface |
Builders.CollectionBuilder<E,C extends Collection<?>>
The return type of buildCollection(C) . |
static interface |
Builders.MapBuilder<K,V,C extends Map<?,?>>
The return type of buildMap(C) . |
static interface |
Builders.MultiMapBuilder<K,V,C extends Map<?,?>>
The return type of buildMultiMap(C) . |
Constructor Summary | |
---|---|
Builders()
|
Method Summary | ||
---|---|---|
static
|
buildCollection(C coll)
Build a collection in one line of code. |
|
static
|
buildMap(C map)
Build a map in one line of code. |
|
static
|
buildMultiMap(C map)
Build a map from things to immutable lists in one line of code. |
|
static
|
makeCollection(C coll,
E... elems)
Build a collection in one function call. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Builders()
Method Detail |
---|
public static <K,V,C extends Map<? super K,? super V>> Builders.MapBuilder<K,V,C> buildMap(C map)
K
- The type of the keys.V
- The type of the values.C
- The type of the map.map
- The map to build onto.
Builders.MapBuilder
whose put() method adds an entry to the
map and returns itself so that calls can be chained together.public static <K,V,C extends Map<? super K,? super List<V>>> Builders.MultiMapBuilder<K,V,C> buildMultiMap(C map)
K
- The type of the keys.V
- The type of the (individual) values.C
- The type of the map.map
- The map to build onto.
Builders.MapBuilder
whose put() method adds an entry to the
map and returns itself so that calls can be chained together.
All values in the map will be immutable lists.public static <E,C extends Collection<? super E>> Builders.CollectionBuilder<E,C> buildCollection(C coll)
E
- The type of the elements.C
- The type of the collection.coll
- The collection to build onto.
Builders.CollectionBuilder
whose add() method adds an
element to the collection and returns itself so that calls can be
chained together.public static <E,C extends Collection<? super E>> C makeCollection(C coll, E... elems)
E
- The type of the elements.C
- The type of the collection.coll
- The collection to build onto.elems
- Zero or more values to add to the collection.
coll
, having had each element in elems
added to
it in order.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |