1. glazedlists

Make UniqueList support grouping by equality


    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.7.0
    • Fix Version/s: milestone 1
    • Component/s: core
    • Labels:
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:


      As of now UniqueList requires a Comparator (or a source of Comparables) to
      enable grouping.
      However, in order to identify duplicates and remove them, I think the concept of
      equality (without the need of ordering) should be enough.

      So, I think it would be useful if UniqueList could actually be used to get a set
      from a source list, even when this is made of non comparable objects.

      A first attempt is to internally use a comparator like the following:

      public class EqualityComparator implements Comparator<Object>
      public int compare(Object o1, Object o2)

      { if(o1 == o2 || o1.equals(o2))) return 0; return System.identityHashCode(o1) - System.identityHashCode(o2); }


      This comparator:

      • returns 0 if and only if two objects are the same or equal
      • returns a positive or negative integer when two objects are different and not
        equal (see note)
        So, it satisfies the contract of java.util.Comparator, although defining an
        ordering that is not meaningful for our purposes.

      Note: I would however make an extra check while performing the grouping
      operation using Object.equals method, because I'm not a VM expert and I don't
      know what can happen in 64 bit systems... I mean, AFAIK the calculation of the
      hash code based on identity, maps to the memory address of an object, but on 64
      bit systems addresses can be 64-bit long, while the hashcode is a 32-bit number.
      So, using the criteria ",o2)==0" to identify
      duplicates might fail in recognizing two actually different objects if they have
      the same identity hash code (I know this is very unlikely to happen, but maybe

      So, this request enhancement is to enable UniqueList to explicitely and
      appropriately support this scenario.


        There are no comments yet on this issue.


          • Assignee:
          • Votes:
            1 Vote for this issue
            1 Start watching this issue


            • Created: