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; |
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 |
|
|
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);} |
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 |
|
|
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) |
2220 |
|
public Object[] toArray() { return c.toArray(); } |
2221 |
|
public <T> T[] toArray(T[] a) { return c.toArray(a); } |
2222 |
|
public String toString() { return c.toString(); } |
2224 |
– |
public Iterator<E> iterator() { return c.iterator(); } |
2223 |
|
public boolean remove(Object o) { return c.remove(o); } |
2224 |
|
public boolean containsAll(Collection<?> coll) { |
2225 |
|
return c.containsAll(coll); |
2234 |
|
c.clear(); |
2235 |
|
} |
2236 |
|
|
2237 |
< |
public boolean add(E e){ |
2237 |
> |
public Iterator<E> iterator() { |
2238 |
> |
return new Iterator<E>() { |
2239 |
> |
private final Iterator<E> it = c.iterator(); |
2240 |
> |
public boolean hasNext() { return it.hasNext(); } |
2241 |
> |
public E next() { return it.next(); } |
2242 |
> |
public void remove() { it.remove(); }}; |
2243 |
> |
} |
2244 |
> |
|
2245 |
> |
public boolean add(E e){ |
2246 |
|
typeCheck(e); |
2247 |
|
return c.add(e); |
2248 |
|
} |
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 |
|
|
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); } |
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 |
|
|
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 |
|
/** |
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 |
|
} |
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); } |
3569 |
– |
public Iterator<E> iterator() { return keySet.iterator(); } |
3570 |
– |
public Object[] toArray() { return keySet.toArray(); } |
3571 |
– |
public <T> T[] toArray(T[] a) { return keySet.toArray(a); } |
3572 |
– |
public boolean add(E e) { |
3573 |
– |
return m.put(e, Boolean.TRUE) == null; |
3574 |
– |
} |
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 |
|
|
3605 |
|
* view can be useful when you would like to use a method |
3606 |
|
* requiring a <tt>Queue</tt> but you need Lifo ordering. |
3607 |
|
* |
3608 |
+ |
* <p>Each method invocation on the queue returned by this method |
3609 |
+ |
* results in exactly one method invocation on the backing deque, with |
3610 |
+ |
* one exception. The {@link Queue#addAll addAll} method is |
3611 |
+ |
* implemented as a sequence of {@link Deque#addFirst addFirst} |
3612 |
+ |
* invocations on the backing deque. |
3613 |
+ |
* |
3614 |
|
* @param deque the deque |
3615 |
|
* @return the queue |
3616 |
|
* @since 1.6 |
3623 |
|
implements Queue<E>, Serializable { |
3624 |
|
private static final long serialVersionUID = 1802017725587941708L; |
3625 |
|
private final Deque<E> q; |
3626 |
< |
AsLIFOQueue(Deque<E> q) { this.q = q; } |
3627 |
< |
public boolean offer(E e) { return q.offerFirst(e); } |
3628 |
< |
public E poll() { return q.pollFirst(); } |
3629 |
< |
public E remove() { return q.removeFirst(); } |
3630 |
< |
public E peek() { return q.peekFirst(); } |
3631 |
< |
public E element() { return q.getFirst(); } |
3632 |
< |
public int size() { return q.size(); } |
3633 |
< |
public boolean isEmpty() { return q.isEmpty(); } |
3634 |
< |
public boolean contains(Object o) { return q.contains(o); } |
3635 |
< |
public Iterator<E> iterator() { return q.iterator(); } |
3636 |
< |
public Object[] toArray() { return q.toArray(); } |
3637 |
< |
public <T> T[] toArray(T[] a) { return q.toArray(a); } |
3638 |
< |
public boolean add(E e) { return q.offerFirst(e); } |
3639 |
< |
public boolean remove(Object o) { return q.remove(o); } |
3640 |
< |
public void clear() { q.clear(); } |
3626 |
> |
AsLIFOQueue(Deque<E> q) { this.q = q; } |
3627 |
> |
public boolean add(E e) { q.addFirst(e); return true; } |
3628 |
> |
public boolean offer(E e) { return q.offerFirst(e); } |
3629 |
> |
public E poll() { return q.pollFirst(); } |
3630 |
> |
public E remove() { return q.removeFirst(); } |
3631 |
> |
public E peek() { return q.peekFirst(); } |
3632 |
> |
public E element() { return q.getFirst(); } |
3633 |
> |
public void clear() { q.clear(); } |
3634 |
> |
public int size() { return q.size(); } |
3635 |
> |
public boolean isEmpty() { return q.isEmpty(); } |
3636 |
> |
public boolean contains(Object o) { return q.contains(o); } |
3637 |
> |
public boolean remove(Object o) { return q.remove(o); } |
3638 |
> |
public Iterator<E> iterator() { return q.iterator(); } |
3639 |
> |
public Object[] toArray() { return q.toArray(); } |
3640 |
> |
public <T> T[] toArray(T[] a) { return q.toArray(a); } |
3641 |
> |
public String toString() { return q.toString(); } |
3642 |
> |
public boolean containsAll(Collection<?> c) {return q.containsAll(c);} |
3643 |
> |
public boolean removeAll(Collection<?> c) {return q.removeAll(c);} |
3644 |
> |
public boolean retainAll(Collection<?> c) {return q.retainAll(c);} |
3645 |
> |
// We use inherited addAll; forwarding addAll would be wrong |
3646 |
|
} |
3647 |
|
} |