1 |
|
/* |
2 |
< |
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 |
> |
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
18 |
|
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
* |
21 |
< |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 |
< |
* CA 95054 USA or visit www.sun.com if you need additional information or |
23 |
< |
* have any questions. |
21 |
> |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
> |
* or visit www.oracle.com if you need additional information or have any |
23 |
> |
* questions. |
24 |
|
*/ |
25 |
|
|
26 |
|
package java.util; |
100 |
|
|
101 |
|
/** |
102 |
|
* Sorts the specified list into ascending order, according to the |
103 |
< |
* <i>natural ordering</i> of its elements. All elements in the list must |
104 |
< |
* implement the <tt>Comparable</tt> interface. Furthermore, all elements |
105 |
< |
* in the list must be <i>mutually comparable</i> (that is, |
106 |
< |
* <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt> |
107 |
< |
* for any elements <tt>e1</tt> and <tt>e2</tt> in the list).<p> |
108 |
< |
* |
109 |
< |
* This sort is guaranteed to be <i>stable</i>: equal elements will |
110 |
< |
* not be reordered as a result of the sort.<p> |
111 |
< |
* |
112 |
< |
* The specified list must be modifiable, but need not be resizable.<p> |
113 |
< |
* |
114 |
< |
* The sorting algorithm is a modified mergesort (in which the merge is |
115 |
< |
* omitted if the highest element in the low sublist is less than the |
116 |
< |
* lowest element in the high sublist). This algorithm offers guaranteed |
117 |
< |
* n log(n) performance. |
103 |
> |
* {@linkplain Comparable natural ordering} of its elements. |
104 |
> |
* All elements in the list must implement the {@link Comparable} |
105 |
> |
* interface. Furthermore, all elements in the list must be |
106 |
> |
* <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)} |
107 |
> |
* must not throw a {@code ClassCastException} for any elements |
108 |
> |
* {@code e1} and {@code e2} in the list). |
109 |
> |
* |
110 |
> |
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will |
111 |
> |
* not be reordered as a result of the sort. |
112 |
> |
* |
113 |
> |
* <p>The specified list must be modifiable, but need not be resizable. |
114 |
> |
* |
115 |
> |
* <p>Implementation note: This implementation is a stable, adaptive, |
116 |
> |
* iterative mergesort that requires far fewer than n lg(n) comparisons |
117 |
> |
* when the input array is partially sorted, while offering the |
118 |
> |
* performance of a traditional mergesort when the input array is |
119 |
> |
* randomly ordered. If the input array is nearly sorted, the |
120 |
> |
* implementation requires approximately n comparisons. Temporary |
121 |
> |
* storage requirements vary from a small constant for nearly sorted |
122 |
> |
* input arrays to n/2 object references for randomly ordered input |
123 |
> |
* arrays. |
124 |
> |
* |
125 |
> |
* <p>The implementation takes equal advantage of ascending and |
126 |
> |
* descending order in its input array, and can take advantage of |
127 |
> |
* ascending and descending order in different parts of the same |
128 |
> |
* input array. It is well-suited to merging two or more sorted arrays: |
129 |
> |
* simply concatenate the arrays and sort the resulting array. |
130 |
> |
* |
131 |
> |
* <p>The implementation was adapted from Tim Peters's list sort for Python |
132 |
> |
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt"> |
133 |
> |
* TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic |
134 |
> |
* Sorting and Information Theoretic Complexity", in Proceedings of the |
135 |
> |
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, |
136 |
> |
* January 1993. |
137 |
|
* |
138 |
< |
* This implementation dumps the specified list into an array, sorts |
138 |
> |
* <p>This implementation dumps the specified list into an array, sorts |
139 |
|
* the array, and iterates over the list resetting each element |
140 |
|
* from the corresponding position in the array. This avoids the |
141 |
|
* n<sup>2</sup> log(n) performance that would result from attempting |
145 |
|
* @throws ClassCastException if the list contains elements that are not |
146 |
|
* <i>mutually comparable</i> (for example, strings and integers). |
147 |
|
* @throws UnsupportedOperationException if the specified list's |
148 |
< |
* list-iterator does not support the <tt>set</tt> operation. |
149 |
< |
* @see Comparable |
148 |
> |
* list-iterator does not support the {@code set} operation. |
149 |
> |
* @throws IllegalArgumentException (optional) if the implementation |
150 |
> |
* detects that the natural ordering of the list elements is |
151 |
> |
* found to violate the {@link Comparable} contract |
152 |
|
*/ |
153 |
|
public static <T extends Comparable<? super T>> void sort(List<T> list) { |
154 |
|
Object[] a = list.toArray(); |
164 |
|
* Sorts the specified list according to the order induced by the |
165 |
|
* specified comparator. All elements in the list must be <i>mutually |
166 |
|
* comparable</i> using the specified comparator (that is, |
167 |
< |
* <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> |
168 |
< |
* for any elements <tt>e1</tt> and <tt>e2</tt> in the list).<p> |
167 |
> |
* {@code c.compare(e1, e2)} must not throw a {@code ClassCastException} |
168 |
> |
* for any elements {@code e1} and {@code e2} in the list). |
169 |
|
* |
170 |
< |
* This sort is guaranteed to be <i>stable</i>: equal elements will |
171 |
< |
* not be reordered as a result of the sort.<p> |
170 |
> |
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will |
171 |
> |
* not be reordered as a result of the sort. |
172 |
|
* |
173 |
< |
* The sorting algorithm is a modified mergesort (in which the merge is |
153 |
< |
* omitted if the highest element in the low sublist is less than the |
154 |
< |
* lowest element in the high sublist). This algorithm offers guaranteed |
155 |
< |
* n log(n) performance. |
173 |
> |
* <p>The specified list must be modifiable, but need not be resizable. |
174 |
|
* |
175 |
< |
* The specified list must be modifiable, but need not be resizable. |
176 |
< |
* This implementation dumps the specified list into an array, sorts |
175 |
> |
* <p>Implementation note: This implementation is a stable, adaptive, |
176 |
> |
* iterative mergesort that requires far fewer than n lg(n) comparisons |
177 |
> |
* when the input array is partially sorted, while offering the |
178 |
> |
* performance of a traditional mergesort when the input array is |
179 |
> |
* randomly ordered. If the input array is nearly sorted, the |
180 |
> |
* implementation requires approximately n comparisons. Temporary |
181 |
> |
* storage requirements vary from a small constant for nearly sorted |
182 |
> |
* input arrays to n/2 object references for randomly ordered input |
183 |
> |
* arrays. |
184 |
> |
* |
185 |
> |
* <p>The implementation takes equal advantage of ascending and |
186 |
> |
* descending order in its input array, and can take advantage of |
187 |
> |
* ascending and descending order in different parts of the same |
188 |
> |
* input array. It is well-suited to merging two or more sorted arrays: |
189 |
> |
* simply concatenate the arrays and sort the resulting array. |
190 |
> |
* |
191 |
> |
* <p>The implementation was adapted from Tim Peters's list sort for Python |
192 |
> |
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt"> |
193 |
> |
* TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic |
194 |
> |
* Sorting and Information Theoretic Complexity", in Proceedings of the |
195 |
> |
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, |
196 |
> |
* January 1993. |
197 |
> |
* |
198 |
> |
* <p>This implementation dumps the specified list into an array, sorts |
199 |
|
* the array, and iterates over the list resetting each element |
200 |
|
* from the corresponding position in the array. This avoids the |
201 |
|
* n<sup>2</sup> log(n) performance that would result from attempting |
203 |
|
* |
204 |
|
* @param list the list to be sorted. |
205 |
|
* @param c the comparator to determine the order of the list. A |
206 |
< |
* <tt>null</tt> value indicates that the elements' <i>natural |
206 |
> |
* {@code null} value indicates that the elements' <i>natural |
207 |
|
* ordering</i> should be used. |
208 |
|
* @throws ClassCastException if the list contains elements that are not |
209 |
|
* <i>mutually comparable</i> using the specified comparator. |
210 |
|
* @throws UnsupportedOperationException if the specified list's |
211 |
< |
* list-iterator does not support the <tt>set</tt> operation. |
212 |
< |
* @see Comparator |
211 |
> |
* list-iterator does not support the {@code set} operation. |
212 |
> |
* @throws IllegalArgumentException (optional) if the comparator is |
213 |
> |
* found to violate the {@link Comparator} contract |
214 |
|
*/ |
215 |
|
public static <T> void sort(List<T> list, Comparator<? super T> c) { |
216 |
|
Object[] a = list.toArray(); |
823 |
|
i -= size; |
824 |
|
displaced = list.set(i, displaced); |
825 |
|
nMoved ++; |
826 |
< |
} while(i != cycleStart); |
826 |
> |
} while (i != cycleStart); |
827 |
|
} |
828 |
|
} |
829 |
|
|
1452 |
|
* when o is a Map.Entry, and calls o.setValue. |
1453 |
|
*/ |
1454 |
|
public boolean containsAll(Collection<?> coll) { |
1455 |
< |
Iterator<?> e = coll.iterator(); |
1456 |
< |
while (e.hasNext()) |
1416 |
< |
if (!contains(e.next())) // Invokes safe contains() above |
1455 |
> |
for (Object e : coll) { |
1456 |
> |
if (!contains(e)) // Invokes safe contains() above |
1457 |
|
return false; |
1458 |
+ |
} |
1459 |
|
return true; |
1460 |
|
} |
1461 |
|
public boolean equals(Object o) { |
1482 |
|
|
1483 |
|
UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;} |
1484 |
|
|
1485 |
< |
public K getKey() {return e.getKey();} |
1486 |
< |
public V getValue() {return e.getValue();} |
1485 |
> |
public K getKey() {return e.getKey();} |
1486 |
> |
public V getValue() {return e.getValue();} |
1487 |
|
public V setValue(V value) { |
1488 |
|
throw new UnsupportedOperationException(); |
1489 |
|
} |
1490 |
< |
public int hashCode() {return e.hashCode();} |
1490 |
> |
public int hashCode() {return e.hashCode();} |
1491 |
|
public boolean equals(Object o) { |
1492 |
|
if (!(o instanceof Map.Entry)) |
1493 |
|
return false; |
1495 |
|
return eq(e.getKey(), t.getKey()) && |
1496 |
|
eq(e.getValue(), t.getValue()); |
1497 |
|
} |
1498 |
< |
public String toString() {return e.toString();} |
1498 |
> |
public String toString() {return e.toString();} |
1499 |
|
} |
1500 |
|
} |
1501 |
|
} |
1562 |
|
* <pre> |
1563 |
|
* Collection c = Collections.synchronizedCollection(myCollection); |
1564 |
|
* ... |
1565 |
< |
* synchronized(c) { |
1565 |
> |
* synchronized (c) { |
1566 |
|
* Iterator i = c.iterator(); // Must be in the synchronized block |
1567 |
|
* while (i.hasNext()) |
1568 |
|
* foo(i.next()); |
1611 |
|
} |
1612 |
|
|
1613 |
|
public int size() { |
1614 |
< |
synchronized(mutex) {return c.size();} |
1614 |
> |
synchronized (mutex) {return c.size();} |
1615 |
|
} |
1616 |
|
public boolean isEmpty() { |
1617 |
< |
synchronized(mutex) {return c.isEmpty();} |
1617 |
> |
synchronized (mutex) {return c.isEmpty();} |
1618 |
|
} |
1619 |
|
public boolean contains(Object o) { |
1620 |
< |
synchronized(mutex) {return c.contains(o);} |
1620 |
> |
synchronized (mutex) {return c.contains(o);} |
1621 |
|
} |
1622 |
|
public Object[] toArray() { |
1623 |
< |
synchronized(mutex) {return c.toArray();} |
1623 |
> |
synchronized (mutex) {return c.toArray();} |
1624 |
|
} |
1625 |
|
public <T> T[] toArray(T[] a) { |
1626 |
< |
synchronized(mutex) {return c.toArray(a);} |
1626 |
> |
synchronized (mutex) {return c.toArray(a);} |
1627 |
|
} |
1628 |
|
|
1629 |
|
public Iterator<E> iterator() { |
1631 |
|
} |
1632 |
|
|
1633 |
|
public boolean add(E e) { |
1634 |
< |
synchronized(mutex) {return c.add(e);} |
1634 |
> |
synchronized (mutex) {return c.add(e);} |
1635 |
|
} |
1636 |
|
public boolean remove(Object o) { |
1637 |
< |
synchronized(mutex) {return c.remove(o);} |
1637 |
> |
synchronized (mutex) {return c.remove(o);} |
1638 |
|
} |
1639 |
|
|
1640 |
|
public boolean containsAll(Collection<?> coll) { |
1641 |
< |
synchronized(mutex) {return c.containsAll(coll);} |
1641 |
> |
synchronized (mutex) {return c.containsAll(coll);} |
1642 |
|
} |
1643 |
|
public boolean addAll(Collection<? extends E> coll) { |
1644 |
< |
synchronized(mutex) {return c.addAll(coll);} |
1644 |
> |
synchronized (mutex) {return c.addAll(coll);} |
1645 |
|
} |
1646 |
|
public boolean removeAll(Collection<?> coll) { |
1647 |
< |
synchronized(mutex) {return c.removeAll(coll);} |
1647 |
> |
synchronized (mutex) {return c.removeAll(coll);} |
1648 |
|
} |
1649 |
|
public boolean retainAll(Collection<?> coll) { |
1650 |
< |
synchronized(mutex) {return c.retainAll(coll);} |
1650 |
> |
synchronized (mutex) {return c.retainAll(coll);} |
1651 |
|
} |
1652 |
|
public void clear() { |
1653 |
< |
synchronized(mutex) {c.clear();} |
1653 |
> |
synchronized (mutex) {c.clear();} |
1654 |
|
} |
1655 |
|
public String toString() { |
1656 |
< |
synchronized(mutex) {return c.toString();} |
1656 |
> |
synchronized (mutex) {return c.toString();} |
1657 |
|
} |
1658 |
|
private void writeObject(ObjectOutputStream s) throws IOException { |
1659 |
< |
synchronized(mutex) {s.defaultWriteObject();} |
1659 |
> |
synchronized (mutex) {s.defaultWriteObject();} |
1660 |
|
} |
1661 |
|
} |
1662 |
|
|
1671 |
|
* <pre> |
1672 |
|
* Set s = Collections.synchronizedSet(new HashSet()); |
1673 |
|
* ... |
1674 |
< |
* synchronized(s) { |
1674 |
> |
* synchronized (s) { |
1675 |
|
* Iterator i = s.iterator(); // Must be in the synchronized block |
1676 |
|
* while (i.hasNext()) |
1677 |
|
* foo(i.next()); |
1709 |
|
} |
1710 |
|
|
1711 |
|
public boolean equals(Object o) { |
1712 |
< |
synchronized(mutex) {return c.equals(o);} |
1712 |
> |
synchronized (mutex) {return c.equals(o);} |
1713 |
|
} |
1714 |
|
public int hashCode() { |
1715 |
< |
synchronized(mutex) {return c.hashCode();} |
1715 |
> |
synchronized (mutex) {return c.hashCode();} |
1716 |
|
} |
1717 |
|
} |
1718 |
|
|
1728 |
|
* <pre> |
1729 |
|
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); |
1730 |
|
* ... |
1731 |
< |
* synchronized(s) { |
1731 |
> |
* synchronized (s) { |
1732 |
|
* Iterator i = s.iterator(); // Must be in the synchronized block |
1733 |
|
* while (i.hasNext()) |
1734 |
|
* foo(i.next()); |
1739 |
|
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); |
1740 |
|
* SortedSet s2 = s.headSet(foo); |
1741 |
|
* ... |
1742 |
< |
* synchronized(s) { // Note: s, not s2!!! |
1742 |
> |
* synchronized (s) { // Note: s, not s2!!! |
1743 |
|
* Iterator i = s2.iterator(); // Must be in the synchronized block |
1744 |
|
* while (i.hasNext()) |
1745 |
|
* foo(i.next()); |
1766 |
|
{ |
1767 |
|
private static final long serialVersionUID = 8695801310862127406L; |
1768 |
|
|
1769 |
< |
final private SortedSet<E> ss; |
1769 |
> |
private final SortedSet<E> ss; |
1770 |
|
|
1771 |
|
SynchronizedSortedSet(SortedSet<E> s) { |
1772 |
|
super(s); |
1778 |
|
} |
1779 |
|
|
1780 |
|
public Comparator<? super E> comparator() { |
1781 |
< |
synchronized(mutex) {return ss.comparator();} |
1781 |
> |
synchronized (mutex) {return ss.comparator();} |
1782 |
|
} |
1783 |
|
|
1784 |
|
public SortedSet<E> subSet(E fromElement, E toElement) { |
1785 |
< |
synchronized(mutex) { |
1785 |
> |
synchronized (mutex) { |
1786 |
|
return new SynchronizedSortedSet<E>( |
1787 |
|
ss.subSet(fromElement, toElement), mutex); |
1788 |
|
} |
1789 |
|
} |
1790 |
|
public SortedSet<E> headSet(E toElement) { |
1791 |
< |
synchronized(mutex) { |
1791 |
> |
synchronized (mutex) { |
1792 |
|
return new SynchronizedSortedSet<E>(ss.headSet(toElement), mutex); |
1793 |
|
} |
1794 |
|
} |
1795 |
|
public SortedSet<E> tailSet(E fromElement) { |
1796 |
< |
synchronized(mutex) { |
1796 |
> |
synchronized (mutex) { |
1797 |
|
return new SynchronizedSortedSet<E>(ss.tailSet(fromElement),mutex); |
1798 |
|
} |
1799 |
|
} |
1800 |
|
|
1801 |
|
public E first() { |
1802 |
< |
synchronized(mutex) {return ss.first();} |
1802 |
> |
synchronized (mutex) {return ss.first();} |
1803 |
|
} |
1804 |
|
public E last() { |
1805 |
< |
synchronized(mutex) {return ss.last();} |
1805 |
> |
synchronized (mutex) {return ss.last();} |
1806 |
|
} |
1807 |
|
} |
1808 |
|
|
1817 |
|
* <pre> |
1818 |
|
* List list = Collections.synchronizedList(new ArrayList()); |
1819 |
|
* ... |
1820 |
< |
* synchronized(list) { |
1820 |
> |
* synchronized (list) { |
1821 |
|
* Iterator i = list.iterator(); // Must be in synchronized block |
1822 |
|
* while (i.hasNext()) |
1823 |
|
* foo(i.next()); |
1863 |
|
} |
1864 |
|
|
1865 |
|
public boolean equals(Object o) { |
1866 |
< |
synchronized(mutex) {return list.equals(o);} |
1866 |
> |
synchronized (mutex) {return list.equals(o);} |
1867 |
|
} |
1868 |
|
public int hashCode() { |
1869 |
< |
synchronized(mutex) {return list.hashCode();} |
1869 |
> |
synchronized (mutex) {return list.hashCode();} |
1870 |
|
} |
1871 |
|
|
1872 |
|
public E get(int index) { |
1873 |
< |
synchronized(mutex) {return list.get(index);} |
1873 |
> |
synchronized (mutex) {return list.get(index);} |
1874 |
|
} |
1875 |
|
public E set(int index, E element) { |
1876 |
< |
synchronized(mutex) {return list.set(index, element);} |
1876 |
> |
synchronized (mutex) {return list.set(index, element);} |
1877 |
|
} |
1878 |
|
public void add(int index, E element) { |
1879 |
< |
synchronized(mutex) {list.add(index, element);} |
1879 |
> |
synchronized (mutex) {list.add(index, element);} |
1880 |
|
} |
1881 |
|
public E remove(int index) { |
1882 |
< |
synchronized(mutex) {return list.remove(index);} |
1882 |
> |
synchronized (mutex) {return list.remove(index);} |
1883 |
|
} |
1884 |
|
|
1885 |
|
public int indexOf(Object o) { |
1886 |
< |
synchronized(mutex) {return list.indexOf(o);} |
1886 |
> |
synchronized (mutex) {return list.indexOf(o);} |
1887 |
|
} |
1888 |
|
public int lastIndexOf(Object o) { |
1889 |
< |
synchronized(mutex) {return list.lastIndexOf(o);} |
1889 |
> |
synchronized (mutex) {return list.lastIndexOf(o);} |
1890 |
|
} |
1891 |
|
|
1892 |
|
public boolean addAll(int index, Collection<? extends E> c) { |
1893 |
< |
synchronized(mutex) {return list.addAll(index, c);} |
1893 |
> |
synchronized (mutex) {return list.addAll(index, c);} |
1894 |
|
} |
1895 |
|
|
1896 |
|
public ListIterator<E> listIterator() { |
1902 |
|
} |
1903 |
|
|
1904 |
|
public List<E> subList(int fromIndex, int toIndex) { |
1905 |
< |
synchronized(mutex) { |
1905 |
> |
synchronized (mutex) { |
1906 |
|
return new SynchronizedList<E>(list.subList(fromIndex, toIndex), |
1907 |
|
mutex); |
1908 |
|
} |
1943 |
|
} |
1944 |
|
|
1945 |
|
public List<E> subList(int fromIndex, int toIndex) { |
1946 |
< |
synchronized(mutex) { |
1946 |
> |
synchronized (mutex) { |
1947 |
|
return new SynchronizedRandomAccessList<E>( |
1948 |
|
list.subList(fromIndex, toIndex), mutex); |
1949 |
|
} |
1975 |
|
* ... |
1976 |
|
* Set s = m.keySet(); // Needn't be in synchronized block |
1977 |
|
* ... |
1978 |
< |
* synchronized(m) { // Synchronizing on m, not s! |
1978 |
> |
* synchronized (m) { // Synchronizing on m, not s! |
1979 |
|
* Iterator i = s.iterator(); // Must be in synchronized block |
1980 |
|
* while (i.hasNext()) |
1981 |
|
* foo(i.next()); |
2016 |
|
} |
2017 |
|
|
2018 |
|
public int size() { |
2019 |
< |
synchronized(mutex) {return m.size();} |
2019 |
> |
synchronized (mutex) {return m.size();} |
2020 |
|
} |
2021 |
|
public boolean isEmpty() { |
2022 |
< |
synchronized(mutex) {return m.isEmpty();} |
2022 |
> |
synchronized (mutex) {return m.isEmpty();} |
2023 |
|
} |
2024 |
|
public boolean containsKey(Object key) { |
2025 |
< |
synchronized(mutex) {return m.containsKey(key);} |
2025 |
> |
synchronized (mutex) {return m.containsKey(key);} |
2026 |
|
} |
2027 |
|
public boolean containsValue(Object value) { |
2028 |
< |
synchronized(mutex) {return m.containsValue(value);} |
2028 |
> |
synchronized (mutex) {return m.containsValue(value);} |
2029 |
|
} |
2030 |
|
public V get(Object key) { |
2031 |
< |
synchronized(mutex) {return m.get(key);} |
2031 |
> |
synchronized (mutex) {return m.get(key);} |
2032 |
|
} |
2033 |
|
|
2034 |
|
public V put(K key, V value) { |
2035 |
< |
synchronized(mutex) {return m.put(key, value);} |
2035 |
> |
synchronized (mutex) {return m.put(key, value);} |
2036 |
|
} |
2037 |
|
public V remove(Object key) { |
2038 |
< |
synchronized(mutex) {return m.remove(key);} |
2038 |
> |
synchronized (mutex) {return m.remove(key);} |
2039 |
|
} |
2040 |
|
public void putAll(Map<? extends K, ? extends V> map) { |
2041 |
< |
synchronized(mutex) {m.putAll(map);} |
2041 |
> |
synchronized (mutex) {m.putAll(map);} |
2042 |
|
} |
2043 |
|
public void clear() { |
2044 |
< |
synchronized(mutex) {m.clear();} |
2044 |
> |
synchronized (mutex) {m.clear();} |
2045 |
|
} |
2046 |
|
|
2047 |
|
private transient Set<K> keySet = null; |
2049 |
|
private transient Collection<V> values = null; |
2050 |
|
|
2051 |
|
public Set<K> keySet() { |
2052 |
< |
synchronized(mutex) { |
2052 |
> |
synchronized (mutex) { |
2053 |
|
if (keySet==null) |
2054 |
|
keySet = new SynchronizedSet<K>(m.keySet(), mutex); |
2055 |
|
return keySet; |
2057 |
|
} |
2058 |
|
|
2059 |
|
public Set<Map.Entry<K,V>> entrySet() { |
2060 |
< |
synchronized(mutex) { |
2060 |
> |
synchronized (mutex) { |
2061 |
|
if (entrySet==null) |
2062 |
|
entrySet = new SynchronizedSet<Map.Entry<K,V>>(m.entrySet(), mutex); |
2063 |
|
return entrySet; |
2065 |
|
} |
2066 |
|
|
2067 |
|
public Collection<V> values() { |
2068 |
< |
synchronized(mutex) { |
2068 |
> |
synchronized (mutex) { |
2069 |
|
if (values==null) |
2070 |
|
values = new SynchronizedCollection<V>(m.values(), mutex); |
2071 |
|
return values; |
2073 |
|
} |
2074 |
|
|
2075 |
|
public boolean equals(Object o) { |
2076 |
< |
synchronized(mutex) {return m.equals(o);} |
2076 |
> |
synchronized (mutex) {return m.equals(o);} |
2077 |
|
} |
2078 |
|
public int hashCode() { |
2079 |
< |
synchronized(mutex) {return m.hashCode();} |
2079 |
> |
synchronized (mutex) {return m.hashCode();} |
2080 |
|
} |
2081 |
|
public String toString() { |
2082 |
< |
synchronized(mutex) {return m.toString();} |
2082 |
> |
synchronized (mutex) {return m.toString();} |
2083 |
|
} |
2084 |
|
private void writeObject(ObjectOutputStream s) throws IOException { |
2085 |
< |
synchronized(mutex) {s.defaultWriteObject();} |
2085 |
> |
synchronized (mutex) {s.defaultWriteObject();} |
2086 |
|
} |
2087 |
|
} |
2088 |
|
|
2101 |
|
* ... |
2102 |
|
* Set s = m.keySet(); // Needn't be in synchronized block |
2103 |
|
* ... |
2104 |
< |
* synchronized(m) { // Synchronizing on m, not s! |
2104 |
> |
* synchronized (m) { // Synchronizing on m, not s! |
2105 |
|
* Iterator i = s.iterator(); // Must be in synchronized block |
2106 |
|
* while (i.hasNext()) |
2107 |
|
* foo(i.next()); |
2114 |
|
* ... |
2115 |
|
* Set s2 = m2.keySet(); // Needn't be in synchronized block |
2116 |
|
* ... |
2117 |
< |
* synchronized(m) { // Synchronizing on m, not m2 or s2! |
2117 |
> |
* synchronized (m) { // Synchronizing on m, not m2 or s2! |
2118 |
|
* Iterator i = s.iterator(); // Must be in synchronized block |
2119 |
|
* while (i.hasNext()) |
2120 |
|
* foo(i.next()); |
2154 |
|
} |
2155 |
|
|
2156 |
|
public Comparator<? super K> comparator() { |
2157 |
< |
synchronized(mutex) {return sm.comparator();} |
2157 |
> |
synchronized (mutex) {return sm.comparator();} |
2158 |
|
} |
2159 |
|
|
2160 |
|
public SortedMap<K,V> subMap(K fromKey, K toKey) { |
2161 |
< |
synchronized(mutex) { |
2161 |
> |
synchronized (mutex) { |
2162 |
|
return new SynchronizedSortedMap<K,V>( |
2163 |
|
sm.subMap(fromKey, toKey), mutex); |
2164 |
|
} |
2165 |
|
} |
2166 |
|
public SortedMap<K,V> headMap(K toKey) { |
2167 |
< |
synchronized(mutex) { |
2167 |
> |
synchronized (mutex) { |
2168 |
|
return new SynchronizedSortedMap<K,V>(sm.headMap(toKey), mutex); |
2169 |
|
} |
2170 |
|
} |
2171 |
|
public SortedMap<K,V> tailMap(K fromKey) { |
2172 |
< |
synchronized(mutex) { |
2172 |
> |
synchronized (mutex) { |
2173 |
|
return new SynchronizedSortedMap<K,V>(sm.tailMap(fromKey),mutex); |
2174 |
|
} |
2175 |
|
} |
2176 |
|
|
2177 |
|
public K firstKey() { |
2178 |
< |
synchronized(mutex) {return sm.firstKey();} |
2178 |
> |
synchronized (mutex) {return sm.firstKey();} |
2179 |
|
} |
2180 |
|
public K lastKey() { |
2181 |
< |
synchronized(mutex) {return sm.lastKey();} |
2181 |
> |
synchronized (mutex) {return sm.lastKey();} |
2182 |
|
} |
2183 |
|
} |
2184 |
|
|
3317 |
|
{ |
3318 |
|
private static final long serialVersionUID = 3193687207550431679L; |
3319 |
|
|
3320 |
< |
final private E element; |
3320 |
> |
private final E element; |
3321 |
|
|
3322 |
|
SingletonSet(E e) {element = e;} |
3323 |
|
|
3448 |
|
* @param o the element to appear repeatedly in the returned list. |
3449 |
|
* @return an immutable list consisting of <tt>n</tt> copies of the |
3450 |
|
* specified object. |
3451 |
< |
* @throws IllegalArgumentException if n < 0. |
3451 |
> |
* @throws IllegalArgumentException if {@code n < 0} |
3452 |
|
* @see List#addAll(Collection) |
3453 |
|
* @see List#addAll(int, Collection) |
3454 |
|
*/ |