sdr 0.7

net.cscott.sdr.util
Class Tools

java.lang.Object
  extended by net.cscott.sdr.util.Tools

public abstract class Tools
extends Object

Utility functions to facilitate map and list creation.

Author:
C. Scott Ananian

Nested Class Summary
static class Tools.F<A,B>
          Convenience alias for FilterIterator.Filter.
static interface Tools.ListMultiMap<K,V>
          An instance of a MultiMap where the contained collections are Lists.
static interface Tools.SetMultiMap<K,V>
          An instance of a MultiMap where the contained collections are Sets.
 
Method Summary
static
<A,B> List<B>
foreach(List<A> list, FilterIterator.Filter<A,B> filter)
          Quasi-list comprehension.
static
<A> List<A>
l()
           
static
<A> List<A>
l(A... items)
          Convenience constructor for lists.
static
<A> List<A>
l(A item1)
           
static
<A> List<A>
l(A item1, A item2)
           
static
<A> List<A>
l(A item1, A item2, A item3)
           
static
<A,B> Map<A,B>
m()
           
static
<A,B> Map<A,B>
m(Map.Entry<A,B>... items)
          Convenience constructor for maps, specified as a list of pairs.
static
<A,B> Map<A,B>
m(Map.Entry<A,B> item)
           
static
<A,B> Map<A,B>
m(Map.Entry<A,B> item1, Map.Entry<A,B> item2)
           
static
<A,B> Map<A,B>
m(Map.Entry<A,B> item1, Map.Entry<A,B> item2, Map.Entry<A,B> item3)
           
static
<A,B> Map<A,B>
m(Map.Entry<A,B> item1, Map.Entry<A,B> item2, Map.Entry<A,B> item3, Map.Entry<A,B> item4)
           
static
<K,V> Tools.ListMultiMap<K,V>
mml()
           
static
<K,V> Tools.ListMultiMap<K,V>
mml(Map.Entry<K,V>... items)
          Multimaps of lists.
static
<K,V> Tools.ListMultiMap<K,V>
mml(Map.Entry<K,V> item1)
           
static
<K,V> Tools.ListMultiMap<K,V>
mml(Map.Entry<K,V> item1, Map.Entry<K,V> item2)
           
static
<K,V> Tools.SetMultiMap<K,V>
mms()
           
static
<K,V> Tools.SetMultiMap<K,V>
mms(Map.Entry<K,V>... items)
          Multimaps of sets.
static
<K,V> Tools.SetMultiMap<K,V>
mms(Map.Entry<K,V> item1)
           
static
<K,V> Tools.SetMultiMap<K,V>
mms(Map.Entry<K,V> item1, Map.Entry<K,V> item2)
           
static
<A,B> PairMapEntry<A,B>
p(A a, B b)
          Convenience constructor for pairs.
static
<A> Set<A>
s()
           
static
<A> Set<A>
s(A... items)
          Convenience constructor for sets.
static
<A> Set<A>
s(A item1)
           
static
<A> Set<A>
s(A item1, A item2)
           
static
<A> Set<A>
s(A item1, A item2, A item3)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

p

public static <A,B> PairMapEntry<A,B> p(A a,
                                        B b)
Convenience constructor for pairs.

Tests:
js> Tools.p(1,2)
1.0=2.0
js> pair=Tools.p('asd',4)
asd=4.0
js> pair.getKey()
asd
js> pair.getValue()
4.0

m

public static <A,B> Map<A,B> m(Map.Entry<A,B>... items)
Convenience constructor for maps, specified as a list of pairs.

See Also:
p(A, B)
Tests:
js> map = Tools.m()
{}
js> map.isEmpty()
true
js> map = Tools.m(Tools.p(1,2), Tools.p(3,4), Tools.p(5,6))
{1.0=2.0, 3.0=4.0, 5.0=6.0}
js> map.get(3)
4.0
Only the last entry is kept for duplicate keys:
js> map = Tools.m(Tools.p(1,2), Tools.p(1,3), Tools.p(1,4))
{1.0=4.0}

m

public static <A,B> Map<A,B> m()
See Also:
m(java.util.Map.Entry[])

m

public static <A,B> Map<A,B> m(Map.Entry<A,B> item)
See Also:
m(java.util.Map.Entry[])

m

public static <A,B> Map<A,B> m(Map.Entry<A,B> item1,
                               Map.Entry<A,B> item2)
See Also:
m(java.util.Map.Entry[])

m

public static <A,B> Map<A,B> m(Map.Entry<A,B> item1,
                               Map.Entry<A,B> item2,
                               Map.Entry<A,B> item3)
See Also:
m(java.util.Map.Entry[])

m

public static <A,B> Map<A,B> m(Map.Entry<A,B> item1,
                               Map.Entry<A,B> item2,
                               Map.Entry<A,B> item3,
                               Map.Entry<A,B> item4)
See Also:
m(java.util.Map.Entry[])

l

public static <A> List<A> l(A... items)
Convenience constructor for lists.

Tests:
js> Tools.l()
[]
js> ll = Tools.l()
[]
js> ll.isEmpty()
true
js> ll = Tools.l('foo')
[foo]
js> ll.get(0)
foo
js> ll = Tools.l(1,2,3,2,1)
[1.0, 2.0, 3.0, 2.0, 1.0]
js> ll.size()
5

l

public static <A> List<A> l()
See Also:
l(Object[])

l

public static <A> List<A> l(A item1)
See Also:
l(Object[])

l

public static <A> List<A> l(A item1,
                            A item2)
See Also:
l(Object[])

l

public static <A> List<A> l(A item1,
                            A item2,
                            A item3)
See Also:
l(Object[])

s

public static <A> Set<A> s(A... items)
Convenience constructor for sets.

Tests:
js> Tools.s()
[]
js> ss = Tools.s()
[]
js> ss.isEmpty()
true
js> ss = Tools.s('foo')
[foo]
js> ss.contains('foo')
true
js> ss = Tools.s(1,2,3,2,1)
[1.0, 2.0, 3.0]
js> ss.size()
3

s

public static <A> Set<A> s()
See Also:
s(Object[])

s

public static <A> Set<A> s(A item1)
See Also:
s(Object[])

s

public static <A> Set<A> s(A item1,
                           A item2)
See Also:
s(Object[])

s

public static <A> Set<A> s(A item1,
                           A item2,
                           A item3)
See Also:
s(Object[])

mms

public static <K,V> Tools.SetMultiMap<K,V> mms(Map.Entry<K,V>... items)
Multimaps of sets.

Tests:
js> map = Tools.mms()
{}
js> map.isEmpty()
true
js> map = Tools.mms(Tools.p(1,2), Tools.p(3,4), Tools.p(5,6))
{1.0=2.0, 3.0=4.0, 5.0=6.0}
js> map.get(3)
4.0
js> map = Tools.mms(Tools.p(1,2), Tools.p(1,3), Tools.p(1,4))
{1.0=[2.0, 3.0, 4.0]}
The collection is a set; duplicate entries are ignored.
js> map = Tools.mms(Tools.p(1,2), Tools.p(1,3), Tools.p(1,2))
{1.0=[2.0, 3.0]}

mms

public static <K,V> Tools.SetMultiMap<K,V> mms()
See Also:
mml(java.util.Map.Entry[])

mms

public static <K,V> Tools.SetMultiMap<K,V> mms(Map.Entry<K,V> item1)
See Also:
mml(java.util.Map.Entry[])

mms

public static <K,V> Tools.SetMultiMap<K,V> mms(Map.Entry<K,V> item1,
                                               Map.Entry<K,V> item2)
See Also:
mml(java.util.Map.Entry[])

mml

public static <K,V> Tools.ListMultiMap<K,V> mml(Map.Entry<K,V>... items)
Multimaps of lists.

Tests:
js> map = Tools.mml()
{}
js> map.isEmpty()
true
js> map = Tools.mml(Tools.p(1,2), Tools.p(3,4), Tools.p(5,6))
{1.0=2.0, 3.0=4.0, 5.0=6.0}
js> map.get(3)
4.0
js> map = Tools.mml(Tools.p(1,2), Tools.p(1,3), Tools.p(1,4))
{1.0=[2.0, 3.0, 4.0]}
The collection is a list; duplicate entries are kept:
js> map = Tools.mml(Tools.p(1,2), Tools.p(1,3), Tools.p(1,2))
{1.0=[2.0, 3.0, 2.0]}

mml

public static <K,V> Tools.ListMultiMap<K,V> mml()
See Also:
mml(java.util.Map.Entry[])

mml

public static <K,V> Tools.ListMultiMap<K,V> mml(Map.Entry<K,V> item1)
See Also:
mml(java.util.Map.Entry[])

mml

public static <K,V> Tools.ListMultiMap<K,V> mml(Map.Entry<K,V> item1,
                                                Map.Entry<K,V> item2)
See Also:
mml(java.util.Map.Entry[])

foreach

public static <A,B> List<B> foreach(List<A> list,
                                    FilterIterator.Filter<A,B> filter)
Quasi-list comprehension.


sdr 0.7

Copyright © 2006-2009 C. Scott Ananian