eu.semaine.util
Class FuzzySort

java.lang.Object
  extended by eu.semaine.util.FuzzySort

public class FuzzySort
extends java.lang.Object

This class implements an approximate sort operation on data for which only the following information is known:

The class computes a mean square error approximation of the solution.

Author:
marc

Nested Class Summary
static class FuzzySort.FuzzySortable
           
static class FuzzySort.FuzzySortableRelation
           
 
Constructor Summary
FuzzySort()
           
 
Method Summary
static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations, boolean enforceInitialFinal)
          For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc.
static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations, boolean enforceInitialFinal, double threshold)
          For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc.
static java.lang.String toString(java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sortedResults)
          Convert the sorted results into a human-readable string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FuzzySort

public FuzzySort()
Method Detail

sort

public static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
                                                                          boolean enforceInitialFinal)
For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc. A heuristic will be used to determine the threshold below which two items will be considered to be "equal" with respect to sorting.

Parameters:
relations - a non-null, non-empty set of relations
enforceInitialFinal - whether to interpret the initial/final requests by FuzzySortable as a soft or a hard constraint. If set to true, we guarantee that the first set in the returned list contains all initial items, and the last set in the list contains all final items.
Returns:
a non-null, non-empty set of non-null, non-empty sets of sortables.
Throws:
NullPointerException, - IllegalArgumentException if relations is null or empty

sort

public static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
                                                                          boolean enforceInitialFinal,
                                                                          double threshold)
For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc.

Parameters:
relations - a non-null, non-empty set of relations
enforceInitialFinal - whether to interpret the initial/final requests by FuzzySortable as a soft or a hard constraint. If set to true, we guarantee that the first set in the returned list contains all initial items, and the last set in the list contains all final items.
threshold - the threshold below which two sortables are considered equal, given that each relation represents a requested distance of 1. This must be a non-negative value, or Float.NaN. If a value of 0 is given, a very small threshold is used; if NaN is given, a heuristic threshold is computed.
Returns:
a non-null, non-empty set of non-null, non-empty sets of sortables.
Throws:
NullPointerException, - IllegalArgumentException if relations is null or empty, or if threshold is invalid

toString

public static java.lang.String toString(java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sortedResults)
Convert the sorted results into a human-readable string. Each line contains one set of sortables; items in each line are separated by a white space character.

Parameters:
sortedResults - non-null, non-empty list of non-null, non-empty sets of fuzzy sortables
Returns:
a non-null string representing sortedResult
Throws:
IllegalArgumentException, - NullPointerException when the parameter is not conformant