org.planx.msd.lang
Class RecursionDiscriminator<T>

java.lang.Object
  extended by org.planx.msd.util.AbstractDiscriminator<T>
      extended by org.planx.msd.lang.RecursionDiscriminator<T>
All Implemented Interfaces:
Discriminator<T>

public class RecursionDiscriminator<T>
extends AbstractDiscriminator<T>

A Discriminator that enables discrimination of recursive datatypes. To do this, first create an instance of RecursionDiscriminator. Then, define the discriminator for the datatype by using this instance as a discriminator symbolizing the point where recursion is desired, i.e. where the whole discriminator expression is to be repeated. Finally, when the discriminator has been defined, use setRecursion(org.planx.msd.Discriminator) with the discriminator as argument to complete the RecursionDiscriminator.

In practice, for the recursion to be finite the most common case is to use a PolymorphicDiscriminator that chooses between the RecursionDiscriminator and some non-recursive discriminator based on the input.

Author:
Thomas Ambus

Constructor Summary
RecursionDiscriminator()
          Creates a new uninitialized RecursionDiscriminator.
 
Method Summary
<U,S> Collection<List<S>>
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.
 void setRecursion(Discriminator<T> d)
          Initialize the recursive discriminator.
 
Methods inherited from class org.planx.msd.util.AbstractDiscriminator
discriminate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecursionDiscriminator

public RecursionDiscriminator()
Creates a new uninitialized RecursionDiscriminator. The discriminator can be used as a recursion token and must be initialized by setRecursion(org.planx.msd.Discriminator) before use.

Method Detail

setRecursion

public void setRecursion(Discriminator<T> d)
Initialize the recursive discriminator. For recursion to actually occur, the argument must contain a (possibly nested) reference to this RecursionDiscriminator.


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>


Copyright © 2010. All Rights Reserved.