ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/Collections.java
(Generate patch)

Comparing jsr166/src/main/java/util/Collections.java (file contents):
Revision 1.20 by jsr166, Wed Jan 11 00:57:12 2006 UTC vs.
Revision 1.23 by jsr166, Sun Mar 19 01:02:59 2006 UTC

# Line 6 | Line 6
6   */
7  
8   package java.util;
9 import java.util.*; // for javadoc (till 6280605 is fixed)
9   import java.io.Serializable;
10   import java.io.ObjectOutputStream;
11   import java.io.IOException;
# Line 1067 | Line 1066 | public class Collections {
1066          private static final long serialVersionUID = -9215047833775013803L;
1067  
1068          UnmodifiableSet(Set<? extends E> s)     {super(s);}
1069 <        public boolean equals(Object o) {return c.equals(o);}
1069 >        public boolean equals(Object o) {return o == this || c.equals(o);}
1070          public int hashCode()           {return c.hashCode();}
1071      }
1072  
# Line 1152 | Line 1151 | public class Collections {
1151              this.list = list;
1152          }
1153  
1154 <        public boolean equals(Object o) {return list.equals(o);}
1154 >        public boolean equals(Object o) {return o == this || list.equals(o);}
1155          public int hashCode()           {return list.hashCode();}
1156  
1157          public E get(int index) {return list.get(index);}
# Line 1320 | Line 1319 | public class Collections {
1319              return values;
1320          }
1321  
1322 <        public boolean equals(Object o) {return m.equals(o);}
1322 >        public boolean equals(Object o) {return o == this || m.equals(o);}
1323          public int hashCode()           {return m.hashCode();}
1324          public String toString()        {return m.toString();}
1325  
# Line 1543 | Line 1542 | public class Collections {
1542          // use serialVersionUID from JDK 1.2.2 for interoperability
1543          private static final long serialVersionUID = 3053995032091335093L;
1544  
1545 <        final Collection<E> c;     // Backing Collection
1546 <        final Object       mutex;  // Object on which to synchronize
1545 >        final Collection<E> c;  // Backing Collection
1546 >        final Object mutex;     // Object on which to synchronize
1547  
1548          SynchronizedCollection(Collection<E> c) {
1549              if (c==null)
# Line 2318 | Line 2317 | public class Collections {
2317  
2318          CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
2319  
2320 <        public boolean equals(Object o) { return c.equals(o); }
2320 >        public boolean equals(Object o) { return o == this || c.equals(o); }
2321          public int hashCode()           { return c.hashCode(); }
2322      }
2323  
# Line 2421 | Line 2420 | public class Collections {
2420              this.list = list;
2421          }
2422  
2423 <        public boolean equals(Object o)  { return list.equals(o); }
2423 >        public boolean equals(Object o)  { return o == this || list.equals(o); }
2424          public int hashCode()            { return list.hashCode(); }
2425          public E get(int index)          { return list.get(index); }
2426          public E remove(int index)       { return list.remove(index); }
# Line 2575 | Line 2574 | public class Collections {
2574          public void clear()                    { m.clear(); }
2575          public Set<K> keySet()                 { return m.keySet(); }
2576          public Collection<V> values()          { return m.values(); }
2577 <        public boolean equals(Object o)        { return m.equals(o);  }
2577 >        public boolean equals(Object o)        { return o == this || m.equals(o); }
2578          public int hashCode()                  { return m.hashCode(); }
2579          public String toString()               { return m.toString(); }
2580  
# Line 3320 | Line 3319 | public class Collections {
3319          public int compare(Comparable<Object> c1, Comparable<Object> c2) {
3320              return c2.compareTo(c1);
3321          }
3322 +
3323 +        private Object readResolve() { return reverseOrder(); }
3324      }
3325  
3326      /**
# Line 3338 | Line 3339 | public class Collections {
3339       */
3340      public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
3341          if (cmp == null)
3342 <            return new ReverseComparator();  // Unchecked warning!!
3342 >            return reverseOrder();
3343  
3344          return new ReverseComparator2<T>(cmp);
3345      }
# Line 3561 | Line 3562 | public class Collections {
3562          implements Set<E>, Serializable
3563      {
3564          private final Map<E, Boolean> m;  // The backing map
3565 <        private transient Set<E> keySet;  // Its keySet
3565 >        private transient Set<E> s;       // Its keySet
3566  
3567          SetFromMap(Map<E, Boolean> map) {
3568              if (!map.isEmpty())
3569                  throw new IllegalArgumentException("Map is non-empty");
3570              m = map;
3571 <            keySet = map.keySet();
3571 >            s = map.keySet();
3572          }
3573  
3574 +        public void clear()               {        m.clear(); }
3575          public int size()                 { return m.size(); }
3576          public boolean isEmpty()          { return m.isEmpty(); }
3577          public boolean contains(Object o) { return m.containsKey(o); }
3576        public Iterator<E> iterator()     { return keySet.iterator(); }
3577        public Object[] toArray()         { return keySet.toArray(); }
3578        public <T> T[] toArray(T[] a)     { return keySet.toArray(a); }
3579        public boolean add(E e) {
3580            return m.put(e, Boolean.TRUE) == null;
3581        }
3578          public boolean remove(Object o)   { return m.remove(o) != null; }
3579 <
3580 <        public boolean removeAll(Collection<?> c) {
3581 <            return keySet.removeAll(c);
3582 <        }
3583 <        public boolean retainAll(Collection<?> c) {
3584 <            return keySet.retainAll(c);
3585 <        }
3586 <        public void clear()               { m.clear(); }
3587 <        public boolean equals(Object o)   { return keySet.equals(o); }
3588 <        public int hashCode()             { return keySet.hashCode(); }
3579 >        public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; }
3580 >        public Iterator<E> iterator()     { return s.iterator(); }
3581 >        public Object[] toArray()         { return s.toArray(); }
3582 >        public <T> T[] toArray(T[] a)     { return s.toArray(a); }
3583 >        public String toString()          { return s.toString(); }
3584 >        public int hashCode()             { return s.hashCode(); }
3585 >        public boolean equals(Object o)   { return o == this || s.equals(o); }
3586 >        public boolean containsAll(Collection<?> c) {return s.containsAll(c);}
3587 >        public boolean removeAll(Collection<?> c)   {return s.removeAll(c);}
3588 >        public boolean retainAll(Collection<?> c)   {return s.retainAll(c);}
3589 >        // addAll is the only inherited implementation
3590  
3591          private static final long serialVersionUID = 2454657854757543876L;
3592  
3593 <        private void readObject(java.io.ObjectInputStream s)
3593 >        private void readObject(java.io.ObjectInputStream stream)
3594              throws IOException, ClassNotFoundException
3595          {
3596 <            s.defaultReadObject();
3597 <            keySet = m.keySet();
3596 >            stream.defaultReadObject();
3597 >            s = m.keySet();
3598          }
3599      }
3600  
# Line 3620 | Line 3617 | public class Collections {
3617          implements Queue<E>, Serializable {
3618          private static final long serialVersionUID = 1802017725587941708L;
3619          private final Deque<E> q;
3620 <        AsLIFOQueue(Deque<E> q)            { this.q = q; }
3621 <        public boolean add(E e)            { q.addFirst(e); return true; }
3622 <        public boolean offer(E e)          { return q.offerFirst(e); }
3623 <        public E poll()                    { return q.pollFirst(); }
3624 <        public E remove()                  { return q.removeFirst(); }
3625 <        public E peek()                    { return q.peekFirst(); }
3626 <        public E element()                 { return q.getFirst(); }
3627 <        public int size()                  { return q.size(); }
3628 <        public boolean isEmpty()           { return q.isEmpty(); }
3629 <        public boolean contains(Object o)  { return q.contains(o); }
3630 <        public Iterator<E> iterator()      { return q.iterator(); }
3631 <        public Object[] toArray()          { return q.toArray(); }
3632 <        public <T> T[] toArray(T[] a)      { return q.toArray(a); }
3633 <        public boolean remove(Object o)    { return q.remove(o); }
3634 <        public void clear()                { q.clear(); }
3620 >        AsLIFOQueue(Deque<E> q)           { this.q = q; }
3621 >        public boolean add(E e)           { q.addFirst(e); return true; }
3622 >        public boolean offer(E e)         { return q.offerFirst(e); }
3623 >        public E poll()                   { return q.pollFirst(); }
3624 >        public E remove()                 { return q.removeFirst(); }
3625 >        public E peek()                   { return q.peekFirst(); }
3626 >        public E element()                { return q.getFirst(); }
3627 >        public void clear()               {        q.clear(); }
3628 >        public int size()                 { return q.size(); }
3629 >        public boolean isEmpty()          { return q.isEmpty(); }
3630 >        public boolean contains(Object o) { return q.contains(o); }
3631 >        public boolean remove(Object o)   { return q.remove(o); }
3632 >        public Iterator<E> iterator()     { return q.iterator(); }
3633 >        public Object[] toArray()         { return q.toArray(); }
3634 >        public <T> T[] toArray(T[] a)     { return q.toArray(a); }
3635 >        public String toString()          { return q.toString(); }
3636 >        public boolean containsAll(Collection<?> c) {return q.containsAll(c);}
3637 >        public boolean removeAll(Collection<?> c)   {return q.removeAll(c);}
3638 >        public boolean retainAll(Collection<?> c)   {return q.retainAll(c);}
3639 >        // We use inherited addAll; forwarding addAll would be wrong
3640      }
3641   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines