org.jgrapht.experimental.equivalence
Class EquivalenceComparatorChainBase<E,C>

java.lang.Object
  extended by org.jgrapht.experimental.equivalence.EquivalenceComparatorChainBase<E,C>
Type Parameters:
E - the type of the elements in the set
C - the type of the context the element is compared against, e.g. a Graph
All Implemented Interfaces:
EquivalenceComparator<E,C>, EquivalenceComparatorChain<E,C>

public class EquivalenceComparatorChainBase<E,C>
extends Object
implements EquivalenceComparatorChain<E,C>

This class implements comparator chaining.

Usage examples:

  • graph-theory, node equivalence: You can create a comparator for the inDegree of a node, another for the total weight of outDegree edges, and a third which checks the business content of the node. You know that the first topological comparators has dozens of different groups, but the buisness comparator has only two, and they are hard to check . The best performance will be gained by:

    EquivalenceComparatorChainBase eqChain = new EquivalenceComparatorChainBase(fastNodesDegreeComparator);

    eqChain.addComparatorAfter(ABitSlowerEdgeWeightComparator);

    eqChain.addComparatorAfter(slowestBuisnessContentsComparator);

    Since:
    Jul 22, 2005
    Author:
    Assaf

    Constructor Summary
    EquivalenceComparatorChainBase(EquivalenceComparator<E,C> firstComaparator)
               
     
    Method Summary
     void appendComparator(EquivalenceComparator comparatorAfter)
              Adds a comparator which will also test equivalence.
     boolean equivalenceCompare(E arg1, E arg2, C context1, C context2)
              Implements logical AND between the comparators results.
     int equivalenceHashcode(E arg1, C context)
              Rehashes the concatenation of the results of all single hashcodes.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    EquivalenceComparatorChainBase

    public EquivalenceComparatorChainBase(EquivalenceComparator<E,C> firstComaparator)
    Method Detail

    appendComparator

    public void appendComparator(EquivalenceComparator comparatorAfter)
    Description copied from interface: EquivalenceComparatorChain
    Adds a comparator which will also test equivalence. For equivalenceCompare(), the return value is a logical AND of the two comparators. The first check will use the first comparator before the next one. Make sure to put the one which has better performance first. For equivalenceHashcode(), the resulting hashes will be rehashed together. This method may be used multiple times to create a long "chain" of comparators.

    Specified by:
    appendComparator in interface EquivalenceComparatorChain<E,C>

    equivalenceCompare

    public boolean equivalenceCompare(E arg1,
                                      E arg2,
                                      C context1,
                                      C context2)
    Implements logical AND between the comparators results. Iterates through the comparators chain until one of them returns false. If none returns false, this method returns true.

    Specified by:
    equivalenceCompare in interface EquivalenceComparator<E,C>
    See Also:
    EquivalenceComparator.equivalenceCompare(Object, Object, Object, Object)

    equivalenceHashcode

    public int equivalenceHashcode(E arg1,
                                   C context)
    Rehashes the concatenation of the results of all single hashcodes.

    Specified by:
    equivalenceHashcode in interface EquivalenceComparator<E,C>
    See Also:
    EquivalenceComparator.equivalenceHashcode(Object, Object)


    Copyright © 2013. All rights reserved.