|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.foundation.Maps
public abstract class Maps
Constructor Summary | |
---|---|
Maps()
|
Method Summary | ||
---|---|---|
static
|
arrayToMap(java.lang.Object[] nameValuePairs)
makes a Map from an array key-value pairs |
|
static
|
compose(java.util.Map<X,Y> f,
java.util.Map<Y,Z> g)
composes two Maps (like functions, see Functions#compose) |
|
static
|
inverse(java.util.Map<X,Y> f)
Inverses a Map |
|
static
|
map(java.util.Map<X,Y> m,
java.util.Collection<X> domain)
Maps a Collection using Map. |
|
static
|
map(java.util.Map<X,Y> m,
java.lang.Iterable<X> iterable)
Maps an Iterable using Map. |
|
static
|
map(java.util.Map<X,Y> m,
java.util.Iterator<X> iterator)
Maps an Iterator using Map. |
|
static
|
map(java.util.Map<X,Y> m,
java.util.List<X> domain)
Maps a List using Map. |
|
static
|
resolve(java.util.Map<X,Y> f,
Y y)
finds all map keys that map to a specified value |
|
static
|
restrict(java.util.Map<X,Y> map,
java.util.Collection<X> keys)
Restricts a Map to a Collection Resulting Map is a virtual map that has an intersection of map's keyset and keys as a keyset, and maps them to the same values as the original map does. |
|
static
|
revert(java.util.Map<X,Y> f)
reverts a Map f, producing a new one that maps values of f to sets of keys of f |
|
static
|
toMap(java.util.Map.Entry<X,Y>... pairs)
makes a Map from key-value pairs |
|
static
|
toMap(java.lang.Object... pairs)
makes a Map from a vararg of key-value pairs |
|
static
|
toMap(X key,
Y value)
makes a singleton Map<X,Y> from a key-value pair |
|
static
|
toMap(X key1,
Y value1,
X key2,
Y value2)
makes a Map<X,Y> from two key-value pairs |
|
static
|
toMap(X key1,
Y value1,
X key2,
Y value2,
X key3,
Y value3)
makes a Map<X,Y> from three key-value pairs |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Maps()
Method Detail |
---|
public static <X,Y,Z> java.util.Map<X,Z> compose(java.util.Map<X,Y> f, java.util.Map<Y,Z> g)
f
- Map<X,Y> first Mapg
- Map<Y,Z> second Map
Suppose we have the following:
Map<Integer,String> f = toMap(new Object[] {1, "one", 2, "two", 3, "three"});
Map<String,String> g = toMap(new String[] {"one", "uno", "two", "dos", "three", "tres"});
Then compose(f, g)
returns the same map as produced by
toMap(new Object[] {1, "uno", 2, "dos", 3, "tres"});
public static <X,Y> java.util.Set<X> resolve(java.util.Map<X,Y> f, Y y)
f
- Map<X,Y>y
- Y - the key
public static <X,Y> java.util.Map<Y,java.util.Set<X>> revert(java.util.Map<X,Y> f)
f
- Map<X,Y> original map
Suppose we have the following: Then
Map<String,String> f = toMap(new String[] {"1", "odd", "2", "even", "3", "odd"});
revert(f)
returns the same map as produced by
Map<String,Collection<String>> g = new Map<String,Collection<String>>;
g.put("even", new HashSet(Arrays.asList("2")));
g.put("odd", new HashSet(Arrays.asList("1", "3")));
public static <X,Y> java.util.Map<Y,X> inverse(java.util.Map<X,Y> f) throws java.lang.InstantiationException
f
- Map<X,Y> to inverse, must be monomorphic (one-to-one)
Suppose we have the following: Then
Map f = toMap(new String[] {"1", "one", "2", "two", "3", "three"});
inverse(f)
returns the same map as produced by
toMap(new String[] {"one", "1", "two", "2", "three", "3"});
java.lang.InstantiationException
- in case f is not one-to-one
public static final <X,Y> java.util.List<Y> map(java.util.Map<X,Y> m, java.util.List<X> domain)
m
- Map<X,Y> the mapdomain
- List<X> the domain list
Suppose we have the following: Map m = new HashMap();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}))
returns a List that contains "ValueOfB", null, and "ValueOfB".
public static final <X,Y> java.util.Map<X,Y> restrict(java.util.Map<X,Y> map, java.util.Collection<X> keys)
map
- Mapkeys
- Collection
public static final <X,Y> java.util.Collection<Y> map(java.util.Map<X,Y> m, java.util.Collection<X> domain)
m
- Map<X,Y> the mapdomain
- Colection<X> the domain list
Suppose we have the following: Map<String,String> m = new HashMap<String,String>();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}))
returns a Collection that contains just "ValueOfB".
public static final <X,Y> java.util.Iterator<Y> map(java.util.Map<X,Y> m, java.util.Iterator<X> iterator)
m
- Map<X,Y> the mapiterator
- Iterator<X> the domain iterator
Suppose we have the following: Map<String,String> m = new HashMap<String,String>();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}).iterator())
returns an Iterator that consequently returns "ValueOfB", null, and "ValueOfB".
public static final <X,Y> java.lang.Iterable<Y> map(java.util.Map<X,Y> m, java.lang.Iterable<X> iterable)
m
- Map<X,Y> the mapiterable
- Iterable<X> the domain iterator
Suppose we have the following: Map<String,String> m = new HashMap<String,String>();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}))
returns an Iterable that contains "ValueOfB", null, and "ValueOfB".
public static <X,Y> java.util.Map<X,Y> toMap(X key, Y value)
key
- Xvalue
- Y
toMap("the key", "This is the value").get("the key");
returns "This is the value";public static <X,Y> java.util.Map<X,Y> toMap(X key1, Y value1, X key2, Y value2)
key1
- X first keyvalue1
- Y first valuekey2
- X second keyvalue2
- Y second value
toMap(2, "kaksi", 3, "kolmi").get(3);
returns "kolmi";public static <X,Y> java.util.Map<X,Y> toMap(X key1, Y value1, X key2, Y value2, X key3, Y value3)
key1
- X first keyvalue1
- Y first valuekey2
- X second keyvalue2
- Y second valuekey3
- X third keyvalue3
- Y third value
toMap("1", "un", "2", "deux", "3", "troix").get("2");
returns "deux";public static <X,Y> java.util.Map<X,Y> toMap(java.util.Map.Entry<X,Y>... pairs)
pairs
- Pair<X,Y>[] the array of key-value pairs
pairs
array to right elements;
if pairs is null, returns null
toMap(new Pair<Integer, String>[] {
new Pair<Integer, String>(1, "un"),
new Pair<Integer, String>(2, "deux"),
new Pair<Integer, String>(3, "troix")}).get(2);
returns "deux";public static <X,Y> java.util.Map<X,Y> toMap(java.lang.Object... pairs)
pairs
- Object... odd elements of the array are keys, and even elements are values
pairs
array to even elements;
if pairs is null, returns null
toMap(new Integer(1), "un", new Integer(2), "deux", new Integer(3), "troix"}).get(2);
returns "deux";public static <X,Y> java.util.Map<X,Y> arrayToMap(java.lang.Object[] nameValuePairs)
nameValuePairs
- Object[] odd elements of the array are keys, and even elements are values
pairs
array to even elements;
if pairs is null, returns null
arrayToMap(new Object[] {1, "un", 2, "deux", 3, "troix"}).get(2);
returns "deux";
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |