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

java.lang.Object
  extended by org.jgrapht.experimental.equivalence.EquivalenceSet<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

public class EquivalenceSet<E,C>
extends Object

EquivalenceSet is a Set of elements which have been determined to be equivalent using EquivalenceComparator. The class makes sure the set size will be one or more.

  • The group can only be created using the factory method createGroupWithElement().
  • The equals and hashcode of a group uses the EquivalenceComparator on one of the group members, thus it is actually checking whether the "other" is in the same group.

    Since:
    Jul 21, 2005
    Author:
    Assaf

    Field Summary
    protected  C comparatorContext
               
    protected  Set<E> elementsSet
              Contains the current elements of the group
    protected  EquivalenceComparator<? super E,? super C> eqComparator
              The comparator used to define the group
     
    Constructor Summary
    EquivalenceSet(E aElement, EquivalenceComparator<? super E,? super C> aEqComparator, C aComparatorContext)
              Constructs a new EquivalenceSet, filled with the aElement parameter and a reference to the comparator which is used.
     
    Method Summary
     void add(E element)
              Adds an element to the group.
     boolean equals(Object other)
              Uses the equivalenceCompare() of the comparator to compare a representation of this group, taken using this.getRepresentative(), and a representation of the other object, which may be the object itself, or, if it is an equivalence group too, other.getRepresentative()
     boolean equivalentTo(E aOther, C aOtherContext)
               
     C getContext()
               
     E getRepresentative()
              Returns an arbitrary object from the group.
     int hashCode()
              Uses a representative to calculate the group hashcode using equivalenceHashcode().
     int size()
               
     Object[] toArray()
              Returns the elements of the group.
     String toString()
               
     
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
     

    Field Detail

    eqComparator

    protected EquivalenceComparator<? super E,? super C> eqComparator
    The comparator used to define the group


    comparatorContext

    protected C comparatorContext

    elementsSet

    protected Set<E> elementsSet
    Contains the current elements of the group

    Constructor Detail

    EquivalenceSet

    public EquivalenceSet(E aElement,
                          EquivalenceComparator<? super E,? super C> aEqComparator,
                          C aComparatorContext)
    Constructs a new EquivalenceSet, filled with the aElement parameter and a reference to the comparator which is used.

    Method Detail

    getRepresentative

    public E getRepresentative()
    Returns an arbitrary object from the group. There is no guarantee as to which will be returned, and whether the same will be returned on the next call.


    getContext

    public C getContext()

    size

    public int size()

    add

    public void add(E element)
    Adds an element to the group. It does not check it for equivalance . You must make sure it does, using equals().


    equivalentTo

    public boolean equivalentTo(E aOther,
                                C aOtherContext)

    equals

    public boolean equals(Object other)
    Uses the equivalenceCompare() of the comparator to compare a representation of this group, taken using this.getRepresentative(), and a representation of the other object, which may be the object itself, or, if it is an equivalence group too, other.getRepresentative()

    Overrides:
    equals in class Object

    hashCode

    public int hashCode()
    Uses a representative to calculate the group hashcode using equivalenceHashcode().

    Overrides:
    hashCode in class Object
    See Also:
    Object.hashCode()

    toString

    public String toString()
    Overrides:
    toString in class Object

    toArray

    public Object[] toArray()
    Returns the elements of the group. The order of the elements in the returned array is not guaranteed. In other words, two calls to the same object may return different order.



    Copyright © 2013. All rights reserved.