public abstract class Mapper
extends java.lang.Object
//create a collection of Strings from some objects
Collection c = Mapper.map(new Mapper(){
public Object map(Object o){
return o.toString();
}, someIterator);
//simply perform some action and discard the results
Mapper.map(new Mapper(){
public Object map(Object o){
((MyTaskThread)o).performTask();
return null;
}, someIterator);
| Modifier and Type | Field and Description |
|---|---|
static Mapper |
identity
Maps an object to itself.
|
static Mapper |
toString
Maps an object to the results of the toString() method.
|
| Constructor and Description |
|---|
Mapper() |
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection |
apply(java.util.Collection c) |
java.util.Collection |
apply(java.util.Enumeration en) |
java.util.Collection |
apply(java.util.Iterator i) |
java.util.Collection |
apply(java.lang.Object[] arr) |
java.util.Map |
applyToEntries(java.util.Map map) |
java.util.Map |
applyToKeys(java.util.Map map) |
java.util.Map |
applyToValues(java.util.Map map) |
static java.util.Collection |
beanMap(java.lang.String property,
java.util.Collection c)
Map dynamically using a bean property name.
|
static java.util.Collection |
beanMap(java.lang.String property,
java.util.Collection c,
boolean includeNull)
Map dynamically using a bean property name.
|
static java.util.Collection |
beanMap(java.lang.String property,
java.util.Iterator i)
Map dynamically using a bean property name.
|
static java.util.Collection |
beanMap(java.lang.String property,
java.util.Iterator i,
boolean includeNull)
Map dynamically using a bean property name.
|
static java.util.Collection |
beanMap(java.lang.String property,
java.lang.Object[] objs)
Map dynamically using a bean property name.
|
static Mapper |
beanMapper(java.lang.String property)
Create a mapper for bean properties
|
static java.util.Comparator |
comparator(Mapper mapper)
Create a Comparator which compares two objects by first mapping
each object with a mapper and then comparing the result objects.
|
static java.util.Comparator |
comparator(Mapper mapper,
boolean reverse)
|
Mapper |
concat(Mapper mapper)
Concatenate another mapper onto this one.
|
static Mapper |
concat(Mapper[] arr)
Concatenate more than two Mappers.
|
static Mapper |
concat(Mapper first,
Mapper second)
Concatenate two Mappers.
|
static Mapper |
filterMapper(org.apache.commons.collections.Predicate pred)
Return a mapper than maps an object to itself if the predicate evaluates to true,
and to null otherwise.
|
java.util.Map |
makeMap(java.util.Collection c) |
java.util.Map |
makeMap(java.util.Enumeration en) |
java.util.Map |
makeMap(java.util.Iterator i) |
static java.util.Map |
makeMap(Mapper mapper,
java.util.Collection c)
Create a new Map by using the collection objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.util.Collection c,
boolean includeNull)
Create a new Map by using the collection objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.util.Enumeration en)
Create a new Map by using the enumeration objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.util.Enumeration en,
boolean includeNull)
Create a new Map by using the enumeration objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.util.Iterator i)
Create a new Map by using the iterator objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.util.Iterator i,
boolean includeNull)
Create a new Map by using the iterator objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.lang.Object[] a)
Create a new Map by using the array objects as keys, and the mapping result as values.
|
static java.util.Map |
makeMap(Mapper mapper,
java.lang.Object[] a,
boolean includeNull)
Create a new Map by using the array objects as keys, and the mapping result as values.
|
java.util.Map |
makeMap(java.lang.Object[] a) |
static java.util.Collection |
map(Mapper mapper,
java.util.Collection c)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.util.Collection c,
boolean allowNull)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.util.Enumeration en)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.util.Enumeration en,
boolean allowNull)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.util.Iterator i)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.util.Iterator i,
boolean includeNull)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.lang.Object o)
Trivial case of a single object.
|
static java.util.Collection |
map(Mapper mapper,
java.lang.Object[] arr)
Return the results of mapping all objects with the mapper.
|
static java.util.Collection |
map(Mapper mapper,
java.lang.Object[] arr,
boolean allowNull)
Return the results of mapping all objects with the mapper.
|
abstract java.lang.Object |
map(java.lang.Object a)
Map one object to another.
|
static java.util.Map |
mapEntries(Mapper mapper,
java.util.Map map)
Create a new Map by mapping all values from the original map and mapping all keys.
|
static java.util.Map |
mapEntries(Mapper mapper,
java.util.Map map,
boolean includeNull)
Create a new Map by mapping all values from the original map, and mapping all keys.
|
static java.util.Map |
mapKeys(Mapper mapper,
java.util.Map map)
Create a new Map by mapping all keys from the original map and maintaining the original value.
|
static java.util.Map |
mapKeys(Mapper mapper,
java.util.Map map,
boolean allowNull)
Create a new Map by mapping all keys from the original map and maintaining the original value.
|
static Mapper |
mapMapper(java.util.Map map)
Return a mapper that uses a
Map instance, and maps keys of that Map to the values. |
static java.util.Map |
mapValues(Mapper mapper,
java.util.Map map)
Create a new Map by mapping all values from the original map and maintaining the original key.
|
static java.util.Map |
mapValues(Mapper mapper,
java.util.Map map,
boolean includeNull)
Create a new Map by mapping all values from the original map and maintaining the original key.
|
static Mapper |
uniqueMapper() |
static java.util.Map |
zip(java.util.Iterator keys,
java.util.Iterator values)
Creates a map where the object at index N from the first Iterator is the key for the object at index N of the
second Iterator.
|
static java.util.Map |
zip(java.util.Iterator keys,
java.util.Iterator values,
boolean includeNull)
Creates a map where the object at index N from the first Iterator is the key for the object at index N of the
second Iterator.
|
static java.util.Map |
zip(java.util.List keys,
java.util.List values)
Creates a map where the object at index N from the first List is the key for the object at index N of the second
List.
|
static java.util.Map |
zip(java.util.List keys,
java.util.List values,
boolean includeNull)
Creates a map where the object at index N from the first List is the key for the object at index N of the second
List.
|
static java.util.Map |
zip(java.lang.Object[] keys,
java.lang.Object[] values)
Creates a map where the object at index N from the first Iterator is the key for the object at index N of the
second Iterator.
|
static java.util.Map |
zip(java.lang.Object[] keys,
java.lang.Object[] values,
boolean includeNull)
Creates a map where the object at index N from the first Iterator is the key for the object at index N of the
second Iterator.
|
public static final Mapper toString
public static final Mapper identity
public static java.util.Comparator comparator(Mapper mapper)
Comparable interface, otherwise the two
objects cannot be compared. (All of the java.lang.* wrapper types will work.)mapper - mapperpublic static java.util.Comparator comparator(Mapper mapper, boolean reverse)
mapper - mapperreverse - if true, reverse the order of comparisonpublic Mapper concat(Mapper mapper)
mapper - mapperpublic static Mapper concat(Mapper[] arr)
arr - array of Mapper instances. a null array will return the identity Mapper.public static Mapper concat(Mapper first, Mapper second)
first - first mapper to applysecond - second mapper to applypublic static java.util.Map zip(java.util.List keys,
java.util.List values)
keys - List of keysvalues - List of valuespublic static java.util.Map zip(java.util.List keys,
java.util.List values,
boolean includeNull)
keys - List of keysvalues - List of valuesincludeNull - allow null values and keyspublic static java.util.Map zip(java.lang.Object[] keys,
java.lang.Object[] values)
keys - array of keysvalues - array of valuespublic static java.util.Map zip(java.lang.Object[] keys,
java.lang.Object[] values,
boolean includeNull)
keys - array of keysvalues - array of valuesincludeNull - allow null values and keyspublic static java.util.Map zip(java.util.Iterator keys,
java.util.Iterator values)
keys - Iterator of keysvalues - Iterator of valuespublic static java.util.Map zip(java.util.Iterator keys,
java.util.Iterator values,
boolean includeNull)
keys - Iterator of keysvalues - Iterator of valuesincludeNull - allow null values and keyspublic static java.util.Collection map(Mapper mapper, java.lang.Object o)
mapper - an Mappero - an Objectpublic static java.util.Collection map(Mapper mapper, java.util.Collection c)
mapper - an Mapperc - a Collectionpublic java.util.Collection apply(java.util.Collection c)
public static java.util.Collection map(Mapper mapper, java.util.Collection c, boolean allowNull)
mapper - an Mapperc - a CollectionallowNull - allow null valuespublic static java.util.Collection map(Mapper mapper, java.lang.Object[] arr)
mapper - an Mapperarr - an array of objectspublic java.util.Collection apply(java.lang.Object[] arr)
public static java.util.Collection map(Mapper mapper, java.lang.Object[] arr, boolean allowNull)
mapper - an Mapperarr - an array of objectsallowNull - allow null valuespublic static java.util.Collection map(Mapper mapper, java.util.Enumeration en)
mapper - an Mapperen - an Enumerationpublic java.util.Collection apply(java.util.Enumeration en)
public static java.util.Collection map(Mapper mapper, java.util.Enumeration en, boolean allowNull)
mapper - an Mapperen - an EnumerationallowNull - allow null valuespublic static java.util.Map mapKeys(Mapper mapper, java.util.Map map)
mapper - a Mapper to map the keysmap - a Mappublic java.util.Map applyToKeys(java.util.Map map)
public static java.util.Map mapKeys(Mapper mapper, java.util.Map map, boolean allowNull)
mapper - a Mapper to map the keysmap - a MapallowNull - allow null valuespublic static java.util.Map mapValues(Mapper mapper, java.util.Map map)
mapper - a Mapper to map the valuesmap - an Mappublic java.util.Map applyToValues(java.util.Map map)
public static java.util.Map mapValues(Mapper mapper, java.util.Map map, boolean includeNull)
mapper - a Mapper to map the valuesmap - an MapincludeNull - true to include nullpublic static java.util.Map mapEntries(Mapper mapper, java.util.Map map)
mapper - a Mapper to map the values and keysmap - a Mappublic java.util.Map applyToEntries(java.util.Map map)
public static java.util.Map mapEntries(Mapper mapper, java.util.Map map, boolean includeNull)
mapper - a Mapper to map both values and keysmap - Map inputincludeNull - if true, allow null as either key or value after mappingpublic static java.util.Map makeMap(Mapper mapper, java.lang.Object[] a)
mapper - a Mapper to map the valuesa - array of itemspublic java.util.Map makeMap(java.lang.Object[] a)
public static java.util.Map makeMap(Mapper mapper, java.lang.Object[] a, boolean includeNull)
mapper - a Mapper to map the valuesa - array of itemsincludeNull - true to include nullpublic static java.util.Map makeMap(Mapper mapper, java.util.Collection c)
mapper - a Mapper to map the valuesc - Collection of itemspublic java.util.Map makeMap(java.util.Collection c)
public static java.util.Map makeMap(Mapper mapper, java.util.Collection c, boolean includeNull)
mapper - a Mapper to map the valuesc - Collection of itemsincludeNull - true to include nullpublic static java.util.Map makeMap(Mapper mapper, java.util.Iterator i)
mapper - a Mapper to map the valuesi - Iteratorpublic java.util.Map makeMap(java.util.Iterator i)
public static java.util.Map makeMap(Mapper mapper, java.util.Iterator i, boolean includeNull)
mapper - a Mapper to map the valuesi - IteratorincludeNull - true to include nullpublic static java.util.Map makeMap(Mapper mapper, java.util.Enumeration en)
mapper - a Mapper to map the valuesen - Enumerationpublic java.util.Map makeMap(java.util.Enumeration en)
public static java.util.Map makeMap(Mapper mapper, java.util.Enumeration en, boolean includeNull)
mapper - a Mapper to map the valuesen - EnumerationincludeNull - true to include nullpublic static java.util.Collection map(Mapper mapper, java.util.Iterator i)
mapper - an Mapperi - an Iteratorpublic java.util.Collection apply(java.util.Iterator i)
public static java.util.Collection map(Mapper mapper, java.util.Iterator i, boolean includeNull)
mapper - an Mapperi - an IteratorincludeNull - specify whether nulls are includedpublic static java.util.Collection beanMap(java.lang.String property,
java.lang.Object[] objs)
property - the name of a bean propertyobjs - an array of objectsjava.lang.ClassCastException - if there is an error invoking the method on any object.public static java.util.Collection beanMap(java.lang.String property,
java.util.Iterator i)
property - the name of a bean propertyi - an iterator of objectsjava.lang.ClassCastException - if there is an error invoking the method on any object.public static java.util.Collection beanMap(java.lang.String property,
java.util.Collection c,
boolean includeNull)
property - the name of a bean propertyc - an Collection of objectsincludeNull - true to include null results in the responsejava.lang.ClassCastException - if there is an error invoking the method on any object.public static java.util.Collection beanMap(java.lang.String property,
java.util.Collection c)
property - the name of a bean propertyc - a collection of objectsjava.lang.ClassCastException - if there is an error invoking the method on any object.public static Mapper beanMapper(java.lang.String property)
property - name of the bean propertypublic static java.util.Collection beanMap(java.lang.String property,
java.util.Iterator i,
boolean includeNull)
property - the name of a bean propertyi - an iterator of objectsincludeNull - true to include null results in the responsejava.lang.ClassCastException - if there is an error invoking the method on any object.public static Mapper filterMapper(org.apache.commons.collections.Predicate pred)
pred - predicatepublic static Mapper uniqueMapper()
public static Mapper mapMapper(java.util.Map map)
Map instance, and maps keys of that Map to the values.map - a Map instancepublic abstract java.lang.Object map(java.lang.Object a)
a - object