src/share/classes/java/util/Collections.java

Print this page
rev 3186 : 6880112: Project Coin: Port JDK core library code to use diamond operator

*** 1033,1043 **** * @param c the collection for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified collection. */ public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) { ! return new UnmodifiableCollection<T>(c); } /** * @serial include */ --- 1033,1043 ---- * @param c the collection for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified collection. */ public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) { ! return new UnmodifiableCollection<>(c); } /** * @serial include */
*** 1107,1117 **** * * @param s the set for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified set. */ public static <T> Set<T> unmodifiableSet(Set<? extends T> s) { ! return new UnmodifiableSet<T>(s); } /** * @serial include */ --- 1107,1117 ---- * * @param s the set for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified set. */ public static <T> Set<T> unmodifiableSet(Set<? extends T> s) { ! return new UnmodifiableSet<>(s); } /** * @serial include */
*** 1139,1149 **** * @param s the sorted set for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified sorted set. */ public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) { ! return new UnmodifiableSortedSet<T>(s); } /** * @serial include */ --- 1139,1149 ---- * @param s the sorted set for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified sorted set. */ public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) { ! return new UnmodifiableSortedSet<>(s); } /** * @serial include */
*** 1156,1172 **** UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;} public Comparator<? super E> comparator() {return ss.comparator();} public SortedSet<E> subSet(E fromElement, E toElement) { ! return new UnmodifiableSortedSet<E>(ss.subSet(fromElement,toElement)); } public SortedSet<E> headSet(E toElement) { ! return new UnmodifiableSortedSet<E>(ss.headSet(toElement)); } public SortedSet<E> tailSet(E fromElement) { ! return new UnmodifiableSortedSet<E>(ss.tailSet(fromElement)); } public E first() {return ss.first();} public E last() {return ss.last();} } --- 1156,1172 ---- UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;} public Comparator<? super E> comparator() {return ss.comparator();} public SortedSet<E> subSet(E fromElement, E toElement) { ! return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement)); } public SortedSet<E> headSet(E toElement) { ! return new UnmodifiableSortedSet<>(ss.headSet(toElement)); } public SortedSet<E> tailSet(E fromElement) { ! return new UnmodifiableSortedSet<>(ss.tailSet(fromElement)); } public E first() {return ss.first();} public E last() {return ss.last();} }
*** 1186,1197 **** * @param list the list for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified list. */ public static <T> List<T> unmodifiableList(List<? extends T> list) { return (list instanceof RandomAccess ? ! new UnmodifiableRandomAccessList<T>(list) : ! new UnmodifiableList<T>(list)); } /** * @serial include */ --- 1186,1197 ---- * @param list the list for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified list. */ public static <T> List<T> unmodifiableList(List<? extends T> list) { return (list instanceof RandomAccess ? ! new UnmodifiableRandomAccessList<>(list) : ! new UnmodifiableList<>(list)); } /** * @serial include */
*** 1248,1258 **** } }; } public List<E> subList(int fromIndex, int toIndex) { ! return new UnmodifiableList<E>(list.subList(fromIndex, toIndex)); } /** * UnmodifiableRandomAccessList instances are serialized as * UnmodifiableList instances to allow them to be deserialized --- 1248,1258 ---- } }; } public List<E> subList(int fromIndex, int toIndex) { ! return new UnmodifiableList<>(list.subList(fromIndex, toIndex)); } /** * UnmodifiableRandomAccessList instances are serialized as * UnmodifiableList instances to allow them to be deserialized
*** 1265,1275 **** * serialized in 1.4.1 and deserialized in 1.4 will become * UnmodifiableList instances, as this method was missing in 1.4. */ private Object readResolve() { return (list instanceof RandomAccess ! ? new UnmodifiableRandomAccessList<E>(list) : this); } } /** --- 1265,1275 ---- * serialized in 1.4.1 and deserialized in 1.4 will become * UnmodifiableList instances, as this method was missing in 1.4. */ private Object readResolve() { return (list instanceof RandomAccess ! ? new UnmodifiableRandomAccessList<>(list) : this); } } /**
*** 1281,1291 **** UnmodifiableRandomAccessList(List<? extends E> list) { super(list); } public List<E> subList(int fromIndex, int toIndex) { ! return new UnmodifiableRandomAccessList<E>( list.subList(fromIndex, toIndex)); } private static final long serialVersionUID = -2542308836966382001L; --- 1281,1291 ---- UnmodifiableRandomAccessList(List<? extends E> list) { super(list); } public List<E> subList(int fromIndex, int toIndex) { ! return new UnmodifiableRandomAccessList<>( list.subList(fromIndex, toIndex)); } private static final long serialVersionUID = -2542308836966382001L;
*** 1294,1304 **** * not have UnmodifiableRandomAccessList). UnmodifiableList has * a readResolve method that inverts this transformation upon * deserialization. */ private Object writeReplace() { ! return new UnmodifiableList<E>(list); } } /** * Returns an unmodifiable view of the specified map. This method --- 1294,1304 ---- * not have UnmodifiableRandomAccessList). UnmodifiableList has * a readResolve method that inverts this transformation upon * deserialization. */ private Object writeReplace() { ! return new UnmodifiableList<>(list); } } /** * Returns an unmodifiable view of the specified map. This method
*** 1313,1323 **** * * @param m the map for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified map. */ public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m) { ! return new UnmodifiableMap<K,V>(m); } /** * @serial include */ --- 1313,1323 ---- * * @param m the map for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified map. */ public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m) { ! return new UnmodifiableMap<>(m); } /** * @serial include */
*** 1361,1371 **** return keySet; } public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) ! entrySet = new UnmodifiableEntrySet<K,V>(m.entrySet()); return entrySet; } public Collection<V> values() { if (values==null) --- 1361,1371 ---- return keySet; } public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) ! entrySet = new UnmodifiableEntrySet<>(m.entrySet()); return entrySet; } public Collection<V> values() { if (values==null)
*** 1398,1430 **** public boolean hasNext() { return i.hasNext(); } public Map.Entry<K,V> next() { ! return new UnmodifiableEntry<K,V>(i.next()); } public void remove() { throw new UnsupportedOperationException(); } }; } public Object[] toArray() { Object[] a = c.toArray(); for (int i=0; i<a.length; i++) ! a[i] = new UnmodifiableEntry<K,V>((Map.Entry<K,V>)a[i]); return a; } public <T> T[] toArray(T[] a) { // We don't pass a to c.toArray, to avoid window of // vulnerability wherein an unscrupulous multithreaded client // could get his hands on raw (unwrapped) Entries from c. Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0)); for (int i=0; i<arr.length; i++) ! arr[i] = new UnmodifiableEntry<K,V>((Map.Entry<K,V>)arr[i]); if (arr.length > a.length) return (T[])arr; System.arraycopy(arr, 0, a, 0, arr.length); --- 1398,1430 ---- public boolean hasNext() { return i.hasNext(); } public Map.Entry<K,V> next() { ! return new UnmodifiableEntry<>(i.next()); } public void remove() { throw new UnsupportedOperationException(); } }; } public Object[] toArray() { Object[] a = c.toArray(); for (int i=0; i<a.length; i++) ! a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]); return a; } public <T> T[] toArray(T[] a) { // We don't pass a to c.toArray, to avoid window of // vulnerability wherein an unscrupulous multithreaded client // could get his hands on raw (unwrapped) Entries from c. Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0)); for (int i=0; i<arr.length; i++) ! arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]); if (arr.length > a.length) return (T[])arr; System.arraycopy(arr, 0, a, 0, arr.length);
*** 1441,1451 **** */ public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; return c.contains( ! new UnmodifiableEntry<Object,Object>((Map.Entry<?,?>) o)); } /** * The next two methods are overridden to protect against * an unscrupulous List whose contains(Object o) method senses --- 1441,1451 ---- */ public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; return c.contains( ! new UnmodifiableEntry<>((Map.Entry<?,?>) o)); } /** * The next two methods are overridden to protect against * an unscrupulous List whose contains(Object o) method senses
*** 1515,1525 **** * @param m the sorted map for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified sorted map. */ public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) { ! return new UnmodifiableSortedMap<K,V>(m); } /** * @serial include */ --- 1515,1525 ---- * @param m the sorted map for which an unmodifiable view is to be * returned. * @return an unmodifiable view of the specified sorted map. */ public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) { ! return new UnmodifiableSortedMap<>(m); } /** * @serial include */
*** 1533,1549 **** UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m;} public Comparator<? super K> comparator() {return sm.comparator();} public SortedMap<K,V> subMap(K fromKey, K toKey) { ! return new UnmodifiableSortedMap<K,V>(sm.subMap(fromKey, toKey)); } public SortedMap<K,V> headMap(K toKey) { ! return new UnmodifiableSortedMap<K,V>(sm.headMap(toKey)); } public SortedMap<K,V> tailMap(K fromKey) { ! return new UnmodifiableSortedMap<K,V>(sm.tailMap(fromKey)); } public K firstKey() {return sm.firstKey();} public K lastKey() {return sm.lastKey();} } --- 1533,1549 ---- UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m;} public Comparator<? super K> comparator() {return sm.comparator();} public SortedMap<K,V> subMap(K fromKey, K toKey) { ! return new UnmodifiableSortedMap<>(sm.subMap(fromKey, toKey)); } public SortedMap<K,V> headMap(K toKey) { ! return new UnmodifiableSortedMap<>(sm.headMap(toKey)); } public SortedMap<K,V> tailMap(K fromKey) { ! return new UnmodifiableSortedMap<>(sm.tailMap(fromKey)); } public K firstKey() {return sm.firstKey();} public K lastKey() {return sm.lastKey();} }
*** 1581,1595 **** * * @param c the collection to be "wrapped" in a synchronized collection. * @return a synchronized view of the specified collection. */ public static <T> Collection<T> synchronizedCollection(Collection<T> c) { ! return new SynchronizedCollection<T>(c); } static <T> Collection<T> synchronizedCollection(Collection<T> c, Object mutex) { ! return new SynchronizedCollection<T>(c, mutex); } /** * @serial include */ --- 1581,1595 ---- * * @param c the collection to be "wrapped" in a synchronized collection. * @return a synchronized view of the specified collection. */ public static <T> Collection<T> synchronizedCollection(Collection<T> c) { ! return new SynchronizedCollection<>(c); } static <T> Collection<T> synchronizedCollection(Collection<T> c, Object mutex) { ! return new SynchronizedCollection<>(c, mutex); } /** * @serial include */
*** 1684,1698 **** * * @param s the set to be "wrapped" in a synchronized set. * @return a synchronized view of the specified set. */ public static <T> Set<T> synchronizedSet(Set<T> s) { ! return new SynchronizedSet<T>(s); } static <T> Set<T> synchronizedSet(Set<T> s, Object mutex) { ! return new SynchronizedSet<T>(s, mutex); } /** * @serial include */ --- 1684,1698 ---- * * @param s the set to be "wrapped" in a synchronized set. * @return a synchronized view of the specified set. */ public static <T> Set<T> synchronizedSet(Set<T> s) { ! return new SynchronizedSet<>(s); } static <T> Set<T> synchronizedSet(Set<T> s, Object mutex) { ! return new SynchronizedSet<>(s, mutex); } /** * @serial include */
*** 1752,1762 **** * * @param s the sorted set to be "wrapped" in a synchronized sorted set. * @return a synchronized view of the specified sorted set. */ public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) { ! return new SynchronizedSortedSet<T>(s); } /** * @serial include */ --- 1752,1762 ---- * * @param s the sorted set to be "wrapped" in a synchronized sorted set. * @return a synchronized view of the specified sorted set. */ public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) { ! return new SynchronizedSortedSet<>(s); } /** * @serial include */
*** 1781,1802 **** synchronized (mutex) {return ss.comparator();} } public SortedSet<E> subSet(E fromElement, E toElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<E>( ss.subSet(fromElement, toElement), mutex); } } public SortedSet<E> headSet(E toElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<E>(ss.headSet(toElement), mutex); } } public SortedSet<E> tailSet(E fromElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<E>(ss.tailSet(fromElement),mutex); } } public E first() { synchronized (mutex) {return ss.first();} --- 1781,1802 ---- synchronized (mutex) {return ss.comparator();} } public SortedSet<E> subSet(E fromElement, E toElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<>( ss.subSet(fromElement, toElement), mutex); } } public SortedSet<E> headSet(E toElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<>(ss.headSet(toElement), mutex); } } public SortedSet<E> tailSet(E fromElement) { synchronized (mutex) { ! return new SynchronizedSortedSet<>(ss.tailSet(fromElement),mutex); } } public E first() { synchronized (mutex) {return ss.first();}
*** 1831,1848 **** * @param list the list to be "wrapped" in a synchronized list. * @return a synchronized view of the specified list. */ public static <T> List<T> synchronizedList(List<T> list) { return (list instanceof RandomAccess ? ! new SynchronizedRandomAccessList<T>(list) : ! new SynchronizedList<T>(list)); } static <T> List<T> synchronizedList(List<T> list, Object mutex) { return (list instanceof RandomAccess ? ! new SynchronizedRandomAccessList<T>(list, mutex) : ! new SynchronizedList<T>(list, mutex)); } /** * @serial include */ --- 1831,1848 ---- * @param list the list to be "wrapped" in a synchronized list. * @return a synchronized view of the specified list. */ public static <T> List<T> synchronizedList(List<T> list) { return (list instanceof RandomAccess ? ! new SynchronizedRandomAccessList<>(list) : ! new SynchronizedList<>(list)); } static <T> List<T> synchronizedList(List<T> list, Object mutex) { return (list instanceof RandomAccess ? ! new SynchronizedRandomAccessList<>(list, mutex) : ! new SynchronizedList<>(list, mutex)); } /** * @serial include */
*** 1901,1911 **** return list.listIterator(index); // Must be manually synched by user } public List<E> subList(int fromIndex, int toIndex) { synchronized (mutex) { ! return new SynchronizedList<E>(list.subList(fromIndex, toIndex), mutex); } } /** --- 1901,1911 ---- return list.listIterator(index); // Must be manually synched by user } public List<E> subList(int fromIndex, int toIndex) { synchronized (mutex) { ! return new SynchronizedList<>(list.subList(fromIndex, toIndex), mutex); } } /**
*** 1920,1930 **** * serialized in 1.4.1 and deserialized in 1.4 will become * SynchronizedList instances, as this method was missing in 1.4. */ private Object readResolve() { return (list instanceof RandomAccess ! ? new SynchronizedRandomAccessList<E>(list) : this); } } /** --- 1920,1930 ---- * serialized in 1.4.1 and deserialized in 1.4 will become * SynchronizedList instances, as this method was missing in 1.4. */ private Object readResolve() { return (list instanceof RandomAccess ! ? new SynchronizedRandomAccessList<>(list) : this); } } /**
*** 1942,1952 **** super(list, mutex); } public List<E> subList(int fromIndex, int toIndex) { synchronized (mutex) { ! return new SynchronizedRandomAccessList<E>( list.subList(fromIndex, toIndex), mutex); } } private static final long serialVersionUID = 1530674583602358482L; --- 1942,1952 ---- super(list, mutex); } public List<E> subList(int fromIndex, int toIndex) { synchronized (mutex) { ! return new SynchronizedRandomAccessList<>( list.subList(fromIndex, toIndex), mutex); } } private static final long serialVersionUID = 1530674583602358482L;
*** 1956,1966 **** * not have SynchronizedRandomAccessList). SynchronizedList has * a readResolve method that inverts this transformation upon * deserialization. */ private Object writeReplace() { ! return new SynchronizedList<E>(list); } } /** * Returns a synchronized (thread-safe) map backed by the specified --- 1956,1966 ---- * not have SynchronizedRandomAccessList). SynchronizedList has * a readResolve method that inverts this transformation upon * deserialization. */ private Object writeReplace() { ! return new SynchronizedList<>(list); } } /** * Returns a synchronized (thread-safe) map backed by the specified
*** 1988,1998 **** * * @param m the map to be "wrapped" in a synchronized map. * @return a synchronized view of the specified map. */ public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) { ! return new SynchronizedMap<K,V>(m); } /** * @serial include */ --- 1988,1998 ---- * * @param m the map to be "wrapped" in a synchronized map. * @return a synchronized view of the specified map. */ public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) { ! return new SynchronizedMap<>(m); } /** * @serial include */
*** 2049,2075 **** private transient Collection<V> values = null; public Set<K> keySet() { synchronized (mutex) { if (keySet==null) ! keySet = new SynchronizedSet<K>(m.keySet(), mutex); return keySet; } } public Set<Map.Entry<K,V>> entrySet() { synchronized (mutex) { if (entrySet==null) ! entrySet = new SynchronizedSet<Map.Entry<K,V>>(m.entrySet(), mutex); return entrySet; } } public Collection<V> values() { synchronized (mutex) { if (values==null) ! values = new SynchronizedCollection<V>(m.values(), mutex); return values; } } public boolean equals(Object o) { --- 2049,2075 ---- private transient Collection<V> values = null; public Set<K> keySet() { synchronized (mutex) { if (keySet==null) ! keySet = new SynchronizedSet<>(m.keySet(), mutex); return keySet; } } public Set<Map.Entry<K,V>> entrySet() { synchronized (mutex) { if (entrySet==null) ! entrySet = new SynchronizedSet<>(m.entrySet(), mutex); return entrySet; } } public Collection<V> values() { synchronized (mutex) { if (values==null) ! values = new SynchronizedCollection<>(m.values(), mutex); return values; } } public boolean equals(Object o) {
*** 2127,2137 **** * * @param m the sorted map to be "wrapped" in a synchronized sorted map. * @return a synchronized view of the specified sorted map. */ public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) { ! return new SynchronizedSortedMap<K,V>(m); } /** * @serial include --- 2127,2137 ---- * * @param m the sorted map to be "wrapped" in a synchronized sorted map. * @return a synchronized view of the specified sorted map. */ public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) { ! return new SynchronizedSortedMap<>(m); } /** * @serial include
*** 2157,2178 **** synchronized (mutex) {return sm.comparator();} } public SortedMap<K,V> subMap(K fromKey, K toKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<K,V>( sm.subMap(fromKey, toKey), mutex); } } public SortedMap<K,V> headMap(K toKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<K,V>(sm.headMap(toKey), mutex); } } public SortedMap<K,V> tailMap(K fromKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<K,V>(sm.tailMap(fromKey),mutex); } } public K firstKey() { synchronized (mutex) {return sm.firstKey();} --- 2157,2178 ---- synchronized (mutex) {return sm.comparator();} } public SortedMap<K,V> subMap(K fromKey, K toKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<>( sm.subMap(fromKey, toKey), mutex); } } public SortedMap<K,V> headMap(K toKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex); } } public SortedMap<K,V> tailMap(K fromKey) { synchronized (mutex) { ! return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex); } } public K firstKey() { synchronized (mutex) {return sm.firstKey();}
*** 2244,2254 **** * @return a dynamically typesafe view of the specified collection * @since 1.5 */ public static <E> Collection<E> checkedCollection(Collection<E> c, Class<E> type) { ! return new CheckedCollection<E>(c, type); } @SuppressWarnings("unchecked") static <T> T[] zeroLengthArray(Class<T> type) { return (T[]) Array.newInstance(type, 0); --- 2244,2254 ---- * @return a dynamically typesafe view of the specified collection * @since 1.5 */ public static <E> Collection<E> checkedCollection(Collection<E> c, Class<E> type) { ! return new CheckedCollection<>(c, type); } @SuppressWarnings("unchecked") static <T> T[] zeroLengthArray(Class<T> type) { return (T[]) Array.newInstance(type, 0);
*** 2376,2386 **** * @param type the type of element that {@code s} is permitted to hold * @return a dynamically typesafe view of the specified set * @since 1.5 */ public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) { ! return new CheckedSet<E>(s, type); } /** * @serial include */ --- 2376,2386 ---- * @param type the type of element that {@code s} is permitted to hold * @return a dynamically typesafe view of the specified set * @since 1.5 */ public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) { ! return new CheckedSet<>(s, type); } /** * @serial include */
*** 2422,2432 **** * @return a dynamically typesafe view of the specified sorted set * @since 1.5 */ public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type) { ! return new CheckedSortedSet<E>(s, type); } /** * @serial include */ --- 2422,2432 ---- * @return a dynamically typesafe view of the specified sorted set * @since 1.5 */ public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type) { ! return new CheckedSortedSet<>(s, type); } /** * @serial include */
*** 2482,2493 **** * @return a dynamically typesafe view of the specified list * @since 1.5 */ public static <E> List<E> checkedList(List<E> list, Class<E> type) { return (list instanceof RandomAccess ? ! new CheckedRandomAccessList<E>(list, type) : ! new CheckedList<E>(list, type)); } /** * @serial include */ --- 2482,2493 ---- * @return a dynamically typesafe view of the specified list * @since 1.5 */ public static <E> List<E> checkedList(List<E> list, Class<E> type) { return (list instanceof RandomAccess ? ! new CheckedRandomAccessList<>(list, type) : ! new CheckedList<>(list, type)); } /** * @serial include */
*** 2548,2558 **** } }; } public List<E> subList(int fromIndex, int toIndex) { ! return new CheckedList<E>(list.subList(fromIndex, toIndex), type); } } /** * @serial include --- 2548,2558 ---- } }; } public List<E> subList(int fromIndex, int toIndex) { ! return new CheckedList<>(list.subList(fromIndex, toIndex), type); } } /** * @serial include
*** 2565,2575 **** CheckedRandomAccessList(List<E> list, Class<E> type) { super(list, type); } public List<E> subList(int fromIndex, int toIndex) { ! return new CheckedRandomAccessList<E>( list.subList(fromIndex, toIndex), type); } } /** --- 2565,2575 ---- CheckedRandomAccessList(List<E> list, Class<E> type) { super(list, type); } public List<E> subList(int fromIndex, int toIndex) { ! return new CheckedRandomAccessList<>( list.subList(fromIndex, toIndex), type); } } /**
*** 2607,2617 **** * @since 1.5 */ public static <K, V> Map<K, V> checkedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) { ! return new CheckedMap<K,V>(m, keyType, valueType); } /** * @serial include --- 2607,2617 ---- * @since 1.5 */ public static <K, V> Map<K, V> checkedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) { ! return new CheckedMap<>(m, keyType, valueType); } /** * @serial include
*** 2676,2703 **** // - all-or-nothing semantics // - protection from malicious t // - correct behavior if t is a concurrent map Object[] entries = t.entrySet().toArray(); List<Map.Entry<K,V>> checked = ! new ArrayList<Map.Entry<K,V>>(entries.length); for (Object o : entries) { Map.Entry<?,?> e = (Map.Entry<?,?>) o; Object k = e.getKey(); Object v = e.getValue(); typeCheck(k, v); checked.add( ! new AbstractMap.SimpleImmutableEntry<K,V>((K) k, (V) v)); } for (Map.Entry<K,V> e : checked) m.put(e.getKey(), e.getValue()); } private transient Set<Map.Entry<K,V>> entrySet = null; public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) ! entrySet = new CheckedEntrySet<K,V>(m.entrySet(), valueType); return entrySet; } /** * We need this class in addition to CheckedSet as Map.Entry permits --- 2676,2703 ---- // - all-or-nothing semantics // - protection from malicious t // - correct behavior if t is a concurrent map Object[] entries = t.entrySet().toArray(); List<Map.Entry<K,V>> checked = ! new ArrayList<>(entries.length); for (Object o : entries) { Map.Entry<?,?> e = (Map.Entry<?,?>) o; Object k = e.getKey(); Object v = e.getValue(); typeCheck(k, v); checked.add( ! new AbstractMap.SimpleImmutableEntry<>((K) k, (V) v)); } for (Map.Entry<K,V> e : checked) m.put(e.getKey(), e.getValue()); } private transient Set<Map.Entry<K,V>> entrySet = null; public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) ! entrySet = new CheckedEntrySet<>(m.entrySet(), valueType); return entrySet; } /** * We need this class in addition to CheckedSet as Map.Entry permits
*** 2808,2818 **** public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; return s.remove(new AbstractMap.SimpleImmutableEntry ! <Object, Object>((Map.Entry<?,?>)o)); } public boolean removeAll(Collection<?> c) { return batchRemove(c, false); } --- 2808,2818 ---- public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; return s.remove(new AbstractMap.SimpleImmutableEntry ! <>((Map.Entry<?,?>)o)); } public boolean removeAll(Collection<?> c) { return batchRemove(c, false); }
*** 2841,2851 **** && containsAll(that); // Invokes safe containsAll() above } static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e, Class<T> valueType) { ! return new CheckedEntry<K,V,T>(e, valueType); } /** * This "wrapper class" serves two purposes: it prevents * the client from modifying the backing Map, by short-circuiting --- 2841,2851 ---- && containsAll(that); // Invokes safe containsAll() above } static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e, Class<T> valueType) { ! return new CheckedEntry<>(e, valueType); } /** * This "wrapper class" serves two purposes: it prevents * the client from modifying the backing Map, by short-circuiting
*** 2882,2892 **** if (o == this) return true; if (!(o instanceof Map.Entry)) return false; return e.equals(new AbstractMap.SimpleImmutableEntry ! <Object, Object>((Map.Entry<?,?>)o)); } } } } --- 2882,2892 ---- if (o == this) return true; if (!(o instanceof Map.Entry)) return false; return e.equals(new AbstractMap.SimpleImmutableEntry ! <>((Map.Entry<?,?>)o)); } } } }
*** 2925,2935 **** * @since 1.5 */ public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K, V> m, Class<K> keyType, Class<V> valueType) { ! return new CheckedSortedMap<K,V>(m, keyType, valueType); } /** * @serial include */ --- 2925,2935 ---- * @since 1.5 */ public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K, V> m, Class<K> keyType, Class<V> valueType) { ! return new CheckedSortedMap<>(m, keyType, valueType); } /** * @serial include */
*** 2991,3001 **** return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR; } private static class EmptyIterator<E> implements Iterator<E> { static final EmptyIterator<Object> EMPTY_ITERATOR ! = new EmptyIterator<Object>(); public boolean hasNext() { return false; } public E next() { throw new NoSuchElementException(); } public void remove() { throw new IllegalStateException(); } } --- 2991,3001 ---- return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR; } private static class EmptyIterator<E> implements Iterator<E> { static final EmptyIterator<Object> EMPTY_ITERATOR ! = new EmptyIterator<>(); public boolean hasNext() { return false; } public E next() { throw new NoSuchElementException(); } public void remove() { throw new IllegalStateException(); } }
*** 3040,3050 **** private static class EmptyListIterator<E> extends EmptyIterator<E> implements ListIterator<E> { static final EmptyListIterator<Object> EMPTY_ITERATOR ! = new EmptyListIterator<Object>(); public boolean hasPrevious() { return false; } public E previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } --- 3040,3050 ---- private static class EmptyListIterator<E> extends EmptyIterator<E> implements ListIterator<E> { static final EmptyListIterator<Object> EMPTY_ITERATOR ! = new EmptyListIterator<>(); public boolean hasPrevious() { return false; } public E previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; }
*** 3076,3086 **** return (Enumeration<T>) EmptyEnumeration.EMPTY_ENUMERATION; } private static class EmptyEnumeration<E> implements Enumeration<E> { static final EmptyEnumeration<Object> EMPTY_ENUMERATION ! = new EmptyEnumeration<Object>(); public boolean hasMoreElements() { return false; } public E nextElement() { throw new NoSuchElementException(); } } --- 3076,3086 ---- return (Enumeration<T>) EmptyEnumeration.EMPTY_ENUMERATION; } private static class EmptyEnumeration<E> implements Enumeration<E> { static final EmptyEnumeration<Object> EMPTY_ENUMERATION ! = new EmptyEnumeration<>(); public boolean hasMoreElements() { return false; } public E nextElement() { throw new NoSuchElementException(); } }
*** 3088,3098 **** * The empty set (immutable). This set is serializable. * * @see #emptySet() */ @SuppressWarnings("unchecked") ! public static final Set EMPTY_SET = new EmptySet<Object>(); /** * Returns the empty set (immutable). This set is serializable. * Unlike the like-named field, this method is parameterized. * --- 3088,3098 ---- * The empty set (immutable). This set is serializable. * * @see #emptySet() */ @SuppressWarnings("unchecked") ! public static final Set EMPTY_SET = new EmptySet<>(); /** * Returns the empty set (immutable). This set is serializable. * Unlike the like-named field, this method is parameterized. *
*** 3148,3158 **** * The empty list (immutable). This list is serializable. * * @see #emptyList() */ @SuppressWarnings("unchecked") ! public static final List EMPTY_LIST = new EmptyList<Object>(); /** * Returns the empty list (immutable). This list is serializable. * * <p>This example illustrates the type-safe way to obtain an empty list: --- 3148,3158 ---- * The empty list (immutable). This list is serializable. * * @see #emptyList() */ @SuppressWarnings("unchecked") ! public static final List EMPTY_LIST = new EmptyList<>(); /** * Returns the empty list (immutable). This list is serializable. * * <p>This example illustrates the type-safe way to obtain an empty list:
*** 3222,3232 **** * * @see #emptyMap() * @since 1.3 */ @SuppressWarnings("unchecked") ! public static final Map EMPTY_MAP = new EmptyMap<Object,Object>(); /** * Returns the empty map (immutable). This map is serializable. * * <p>This example illustrates the type-safe way to obtain an empty set: --- 3222,3232 ---- * * @see #emptyMap() * @since 1.3 */ @SuppressWarnings("unchecked") ! public static final Map EMPTY_MAP = new EmptyMap<>(); /** * Returns the empty map (immutable). This map is serializable. * * <p>This example illustrates the type-safe way to obtain an empty set:
*** 3284,3294 **** * * @param o the sole object to be stored in the returned set. * @return an immutable set containing only the specified object. */ public static <T> Set<T> singleton(T o) { ! return new SingletonSet<T>(o); } static <E> Iterator<E> singletonIterator(final E e) { return new Iterator<E>() { private boolean hasNext = true; --- 3284,3294 ---- * * @param o the sole object to be stored in the returned set. * @return an immutable set containing only the specified object. */ public static <T> Set<T> singleton(T o) { ! return new SingletonSet<>(o); } static <E> Iterator<E> singletonIterator(final E e) { return new Iterator<E>() { private boolean hasNext = true;
*** 3337,3347 **** * @param o the sole object to be stored in the returned list. * @return an immutable list containing only the specified object. * @since 1.3 */ public static <T> List<T> singletonList(T o) { ! return new SingletonList<T>(o); } /** * @serial include */ --- 3337,3347 ---- * @param o the sole object to be stored in the returned list. * @return an immutable list containing only the specified object. * @since 1.3 */ public static <T> List<T> singletonList(T o) { ! return new SingletonList<>(o); } /** * @serial include */
*** 3379,3389 **** * @return an immutable map containing only the specified key-value * mapping. * @since 1.3 */ public static <K,V> Map<K,V> singletonMap(K key, V value) { ! return new SingletonMap<K,V>(key, value); } /** * @serial include */ --- 3379,3389 ---- * @return an immutable map containing only the specified key-value * mapping. * @since 1.3 */ public static <K,V> Map<K,V> singletonMap(K key, V value) { ! return new SingletonMap<>(key, value); } /** * @serial include */
*** 3421,3431 **** } public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) entrySet = Collections.<Map.Entry<K,V>>singleton( ! new SimpleImmutableEntry<K,V>(k, v)); return entrySet; } public Collection<V> values() { if (values==null) --- 3421,3431 ---- } public Set<Map.Entry<K,V>> entrySet() { if (entrySet==null) entrySet = Collections.<Map.Entry<K,V>>singleton( ! new SimpleImmutableEntry<>(k, v)); return entrySet; } public Collection<V> values() { if (values==null)
*** 3453,3463 **** * @see List#addAll(int, Collection) */ public static <T> List<T> nCopies(int n, T o) { if (n < 0) throw new IllegalArgumentException("List length = " + n); ! return new CopiesList<T>(n, o); } /** * @serial include */ --- 3453,3463 ---- * @see List#addAll(int, Collection) */ public static <T> List<T> nCopies(int n, T o) { if (n < 0) throw new IllegalArgumentException("List length = " + n); ! return new CopiesList<>(n, o); } /** * @serial include */
*** 3527,3537 **** if (toIndex > n) throw new IndexOutOfBoundsException("toIndex = " + toIndex); if (fromIndex > toIndex) throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); ! return new CopiesList<E>(toIndex - fromIndex, element); } } /** * Returns a comparator that imposes the reverse of the <i>natural --- 3527,3537 ---- if (toIndex > n) throw new IndexOutOfBoundsException("toIndex = " + toIndex); if (fromIndex > toIndex) throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); ! return new CopiesList<>(toIndex - fromIndex, element); } } /** * Returns a comparator that imposes the reverse of the <i>natural
*** 3593,3603 **** return reverseOrder(); if (cmp instanceof ReverseComparator2) return ((ReverseComparator2<T>)cmp).cmp; ! return new ReverseComparator2<T>(cmp); } /** * @serial include */ --- 3593,3603 ---- return reverseOrder(); if (cmp instanceof ReverseComparator2) return ((ReverseComparator2<T>)cmp).cmp; ! return new ReverseComparator2<>(cmp); } /** * @serial include */
*** 3672,3682 **** * @since 1.4 * @see Enumeration * @see ArrayList */ public static <T> ArrayList<T> list(Enumeration<T> e) { ! ArrayList<T> l = new ArrayList<T>(); while (e.hasMoreElements()) l.add(e.nextElement()); return l; } --- 3672,3682 ---- * @since 1.4 * @see Enumeration * @see ArrayList */ public static <T> ArrayList<T> list(Enumeration<T> e) { ! ArrayList<T> l = new ArrayList<>(); while (e.hasMoreElements()) l.add(e.nextElement()); return l; }
*** 3817,3827 **** * @return the set backed by the map * @throws IllegalArgumentException if <tt>map</tt> is not empty * @since 1.6 */ public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) { ! return new SetFromMap<E>(map); } /** * @serial include */ --- 3817,3827 ---- * @return the set backed by the map * @throws IllegalArgumentException if <tt>map</tt> is not empty * @since 1.6 */ public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) { ! return new SetFromMap<>(map); } /** * @serial include */
*** 3881,3891 **** * @param deque the deque * @return the queue * @since 1.6 */ public static <T> Queue<T> asLifoQueue(Deque<T> deque) { ! return new AsLIFOQueue<T>(deque); } /** * @serial include */ --- 3881,3891 ---- * @param deque the deque * @return the queue * @since 1.6 */ public static <T> Queue<T> asLifoQueue(Deque<T> deque) { ! return new AsLIFOQueue<>(deque); } /** * @serial include */