org.planx.msd.lang
Class PolymorphicDiscriminator<T>
java.lang.Object
org.planx.msd.util.AbstractDiscriminator<T>
org.planx.msd.lang.PolymorphicDiscriminator<T>
- All Implemented Interfaces:
- Discriminator<T>
public class PolymorphicDiscriminator<T>
- extends AbstractDiscriminator<T>
A Discriminator capable of discriminating objects of
different types. Discriminators for types to be handled are added
using addDiscriminator(java.lang.Class, org.planx.msd.Discriminator super E>).
When discriminating a list of input values, the values are first
separated by type. That is, by the specific Class they
are instance of. This is done using a ClassDiscriminator.
Next, objects of each type are discriminated by looking up a
discriminator for the type based on the class. Note, that a discriminator
is associated with a specific Class and not subclasses.
- Author:
- Thomas Ambus
|
Method Summary |
|
addDiscriminator(Class<E> cls,
Discriminator<? super E> d)
|
|
discriminate(List<? extends U> values,
Extractor<U,? extends T,S> e)
Discriminates a List of values using an Extractor,
and returns a Collection of Lists, each
representing an equivalence class containing elements from
values that are equivalent. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PolymorphicDiscriminator
public PolymorphicDiscriminator()
addDiscriminator
public <E extends T> void addDiscriminator(Class<E> cls,
Discriminator<? super E> d)
discriminate
public <U,S> Collection<List<S>> discriminate(List<? extends U> values,
Extractor<U,? extends T,S> e)
- Description copied from interface:
Discriminator
- Discriminates a
List of values using an Extractor,
and returns a Collection of Lists, each
representing an equivalence class containing elements from
values that are equivalent.
The Extractor performs the task of extracting two kinds
of objects from the input values: The label which
is the object equivalence is defined upon, and the value which
is the object that will be returned. That is, the label
determines which equivalence class the value goes into.
The Collection of Lists returned should be
considered unmodifiable (though, in some cases they might actually be
modifiable, but this behaviour should not be relied upon).
- Specified by:
discriminate in interface Discriminator<T>- Specified by:
discriminate in class AbstractDiscriminator<T>
- Throws:
NonDiscriminableObjectException - if an object was
encountered for which
no discriminator was registered
Copyright © 2010. All Rights Reserved.