|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.collections15.functors.closure.SwitchMapClosure<E>
public class SwitchMapClosure<E>
Closure
implementation that executes one of a number of
Closure
s in a map depending on which key in the map matches the
input object.
Constructor Summary | |
---|---|
protected |
SwitchMapClosure(java.util.Map<E,Closure<? super E>> objectsAndClosures,
Closure<? super E> defaultClosure)
Creates a new instance that executes one of a number of Closure s in a map depending on which key in the map matches
the input object. |
Method Summary | ||
---|---|---|
void |
execute(E input)
Executes one of the Closure s on the input object, using the
input object to look up which Closure to execute. |
|
Closure<? super E> |
getDefaultClosure()
Returns the default Closure . |
|
static
|
getInstance(java.util.Map<T,Closure<? super T>> objectsAndClosures)
Creates a new instance of a SwitchMapClosure that executes
one of a number of Closure s in a map depending on which key
in the map matches the input object, throwing an exception if the input
object doesn't match any of the keys. |
|
static
|
getInstance(java.util.Map<T,Closure<? super T>> objectsAndClosures,
Closure<? super T> defaultClosure)
Creates a new instance of a SwitchMapClosure that executes
one of a number of Closure s in a map depending on which key
in the map matches the input object, or the default Closure
if the input object doesn't match any of the keys. |
|
java.util.Map<E,Closure<? super E>> |
getMappings()
Returns the mappings defined by this SwitchMapClosure . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected SwitchMapClosure(java.util.Map<E,Closure<? super E>> objectsAndClosures, Closure<? super E> defaultClosure)
Closure
s in a map depending on which key in the map matches
the input object.
The map consists of Object
keys and Closure
values. If the input object is mapped to a Closure
, that
Closure
is executed on the input object. In addition, a
default Closure
can be specified that will be executed on an
input object if it doesn't match any of the keys in the map.
objectsAndClosures
- A map of Objects
s to
Closure
s. If an input object is
mapped to a Closure
in the map,
that Closure
is executed.
This map is defensively copied into either a
TreeMap
(if this map is sorted) or
a HashMap
(if it's not).defaultClosure
- If an input object doesn't map to a
Closure
, then this Closure
,
if non-null
, will be executed on
the input object. If this default is
null
then the execute(E)
method will throw an IllegalArgumentException
.
java.lang.IllegalArgumentException
- If the map is null
.
java.lang.IllegalArgumentException
- If any Closure
in the map
is null
.Method Detail |
---|
public static <T> SwitchMapClosure<T> getInstance(java.util.Map<T,Closure<? super T>> objectsAndClosures)
SwitchMapClosure
that executes
one of a number of Closure
s in a map depending on which key
in the map matches the input object, throwing an exception if the input
object doesn't match any of the keys.
The map consists of Object
keys and Closure
values. If the input object is mapped to a Closure
, that
Closure
is executed on the input object. In addition, a
default Closure
can be specified that will be executed on an
input object if it doesn't match any of the keys in the map.
objectsAndClosures
- A map of Objects
s to
Closure
s. If an input object is
mapped to a Closure
in the map,
that Closure
is executed.
This map is defensively copied into either a
TreeMap
(if this map is sorted) or
a HashMap
(if it's not).
SwitchMapClosure
that executes
one of a number of Closure
s in a map depending on
which key in the map matches the input object, throwing an
exception if the input object doesn't match any of the keys.
java.lang.IllegalArgumentException
- If the map is null
.
java.lang.IllegalArgumentException
- If any Closure
in the map
is null
.public static <T> SwitchMapClosure<T> getInstance(java.util.Map<T,Closure<? super T>> objectsAndClosures, Closure<? super T> defaultClosure)
SwitchMapClosure
that executes
one of a number of Closure
s in a map depending on which key
in the map matches the input object, or the default Closure
if the input object doesn't match any of the keys.
The map consists of Object
keys and Closure
values. If the input object is mapped to a Closure
, that
Closure
is executed on the input object. In addition, a
default Closure
can be specified that will be executed on an
input object if it doesn't match any of the keys in the map.
objectsAndClosures
- A map of Objects
s to
Closure
s. If an input object is
mapped to a Closure
in the map,
that Closure
is executed.
This map is defensively copied into either a
TreeMap
(if this map is sorted) or
a HashMap
(if it's not).defaultClosure
- If an input object doesn't map to a
Closure
, then this Closure
,
if non-null
, will be executed on
the input object. If this default is
null
then the execute(E)
method will throw an IllegalArgumentException
.
SwitchMapClosure
that executes
one of a number of Closure
s in a map depending on
which key in the map matches the input object, or the default
Closure
if the input object doesn't match any of the
keys.
java.lang.IllegalArgumentException
- If the map is null
.
java.lang.IllegalArgumentException
- If any Closure
in the map
is null
.public void execute(E input) throws FunctorException
Closure
s on the input object, using the
input object to look up which Closure
to execute.
execute
in interface Closure<E>
input
- The input to execute the Closure
on.
FunctorException
- Thrown if the input object doesn't match any of
the keys and no default Closure
is
defined.public java.util.Map<E,Closure<? super E>> getMappings()
SwitchMapClosure
.
SwitchMapClosure
.getDefaultClosure()
public Closure<? super E> getDefaultClosure()
Closure
.
Closure
applied to an input object if it
doesn't satisfy any of the cases defined for this
SwitchClosure
. May be null
if no
default is defined.getMappings()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |