com.emarsys.ecommon.collections.fuzzy
Class FuzzyFingerPrint<T>

java.lang.Object
  extended by com.emarsys.ecommon.collections.fuzzy.FuzzyFingerPrint<T>
All Implemented Interfaces:
FuzzyComparable<FuzzyFingerPrint<T>>, FuzzyComparator<FuzzyFingerPrint<T>>, java.io.Serializable
Direct Known Subclasses:
TextFingerprint

public abstract class FuzzyFingerPrint<T>
extends java.lang.Object
implements FuzzyComparable<FuzzyFingerPrint<T>>, FuzzyComparator<FuzzyFingerPrint<T>>, java.io.Serializable

A FuzzyFingerPrint represents kind of a signature of its wrapped object of type T which can be used for fuzzy comparisons.

FuzzyFingerPrints should be much smaller in terms of memory consumption than their wrapped content objects.

Note: Concrete FuzzyFingerPrint classes must provide a public default constructor. If not getInstance(Class, Object) will throw a InvocationTargetException or some similar, maybe unchecked, reflection originated exception.

FuzzyFingerPrints must be Serializable.

Author:
Michael "kULO" Kulovits
See Also:
FuzzyComparable, FuzzyComparator, Serialized Form

Field Summary
protected  T content
           
 
Constructor Summary
FuzzyFingerPrint()
           
 
Method Summary
abstract  float compare(FuzzyFingerPrint<T> o1, FuzzyFingerPrint<T> o2)
          Compares its two arguments for similarity.
abstract  float compareTo(FuzzyFingerPrint<T> o)
          Compares its two arguments for similarity.
 T getContent()
           
static
<T> FuzzyFingerPrint<T>
getInstance(java.lang.Class<? extends FuzzyFingerPrint<T>> clazz, T newContent)
          Factory method.
protected abstract  void init()
          Initializes the FuzzyFingerPrint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

content

protected T content
Constructor Detail

FuzzyFingerPrint

public FuzzyFingerPrint()
Method Detail

getInstance

public static <T> FuzzyFingerPrint<T> getInstance(java.lang.Class<? extends FuzzyFingerPrint<T>> clazz,
                                                  T newContent)
                                       throws FingerPrintException
Factory method.

Ensure that clazz implements a public default constructor.

Type Parameters:
T -
Parameters:
clazz -
newContent -
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
FingerPrintException

getContent

public T getContent()
Returns:
the wrapped content object.

init

protected abstract void init()
                      throws java.lang.NullPointerException
Initializes the FuzzyFingerPrint. Called by getInstance(Class, Object).

Throws:
java.lang.NullPointerException - - if content is null

compare

public abstract float compare(FuzzyFingerPrint<T> o1,
                              FuzzyFingerPrint<T> o2)
Description copied from interface: FuzzyComparator
Compares its two arguments for similarity. Returns a floating point number between zero and one representing the degree of similarity.

The implementor should strive for ensuring that the following properties:

  • Pseudo reflexivity: compare(x, x) >= 1-E
  • Pseudo symetry: abs(compare(x, y) - compare(y, x)) <= E
  • Pseudo transitivity: compare(x,y) <= 1-E and compare(y,z) <= 1-E implies compare(x,z) < 1-E with E as small as possible for all x, y, z >= 0.

    Furthermore compare(x, y) must throw an exception iff compare(y, x) throws an exception.

    It is strongly recommended (though not required) that the comparison is consistent with equals. So it is generally the case, but not strictly required that (compare(x, y)==1) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact.

    Specified by:
    compare in interface FuzzyComparator<FuzzyFingerPrint<T>>
    Parameters:
    o1 - the first object to be compared.
    o2 - the second object to be compared.
    Returns:
    a float between 0 and 1 where the latter means "very similar" and the first "not similar".
    See Also:
    FuzzyComparator.compare(java.lang.Object, java.lang.Object)

  • compareTo

    public abstract float compareTo(FuzzyFingerPrint<T> o)
    Description copied from interface: FuzzyComparable
    Compares its two arguments for similarity. Returns a floating point number between zero and one representing the degree of similarity.

    The implementor should strive for ensuring that the following properties:

  • Pseudo reflexivity: compare(x, x) >= 1-E
  • Pseudo symetry: abs(compare(x, y) - compare(y, x)) <= E
  • Pseudo transitivity: compare(x,y) <= 1-E and compare(y,z) <= 1-E implies compare(x,z) < 1-E with E as small as possible for all x, y, z.

    Furhtermore compare(x, y) must throw an exception iff compare(y, x) throws an exception.

    It is strongly recommended (though not required) that the comparison is consistent with equals. So it is generally the case, but not strictly required that (compare(x, y)==1) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact.

    Specified by:
    compareTo in interface FuzzyComparable<FuzzyFingerPrint<T>>
    Returns:
    a float between 0 and 1 where the latter means "very similar" and the first "not similar".
    See Also:
    FuzzyComparable.compareTo(java.lang.Object)


  • Copyright © 2010 emarsys AG. All Rights Reserved.