[concurrency-interest] Re: AtomicInteger and AtomicLong should implement Number

Tim Peierls tim@peierls.net
Wed, 14 Jan 2004 09:51:02 -0500

Gregg Wonderly wrote:
> Dawid, you are failing to understand the argument.  You have some kind 
> of myopic view of this issue clouded by the fact that any API that does 
> have just native integer values and Maps that are non-value keyed is 
> foreign and probably not useful or meaningful.

How did this get to be such an emotional topic? If you really want to
use AtomicX instances as keys based on their mutable values instead of
their identities, no one is stopping you:

   class ComparableAtomicInteger extends AtomicInteger
                                 implements Comparable<ComparableAtomicInteger> {
       public ComparableAtomicInteger() {}
       public ComparableAtomicInteger(int value) { super(value); }
       public int hashCode() { return get(); }
       public boolean equals(Object o) {
           if (this == o)
               return true;
           if (!(o instanceof ComparableAtomicInteger))
               return false;
           return this.get() == ((ComparableAtomicInteger) o).get();
       public int compareTo(ComparableAtomicInteger that) {
           int i1 = this.get();
           int i2 = that.get();
           return i1 < i2 ? -1 : (i1 == i2 ? 0 : 1);

Caveat emptor.