< prev index next >

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

Print this page

        

*** 1019,1028 **** --- 1019,1029 ---- /** * @serial include */ static class UnmodifiableCollection<E> implements Collection<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1820017752578914078L; final Collection<? extends E> c; UnmodifiableCollection(Collection<? extends E> c) {
*** 1125,1134 **** --- 1126,1136 ---- /** * @serial include */ static class UnmodifiableSet<E> extends UnmodifiableCollection<E> implements Set<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = -9215047833775013803L; UnmodifiableSet(Set<? extends E> s) {super(s);} public boolean equals(Object o) {return o == this || c.equals(o);} public int hashCode() {return c.hashCode();}
*** 1158,1167 **** --- 1160,1170 ---- * @serial include */ static class UnmodifiableSortedSet<E> extends UnmodifiableSet<E> implements SortedSet<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = -4929149591599911165L; private final SortedSet<E> ss; UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
*** 1210,1235 **** --- 1213,1241 ---- */ static class UnmodifiableNavigableSet<E> extends UnmodifiableSortedSet<E> implements NavigableSet<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = -6027448201786391929L; /** * A singleton empty unmodifiable navigable set used for * {@link #emptyNavigableSet()}. * * @param <E> type of elements, if there were any, and bounds */ private static class EmptyNavigableSet<E> extends UnmodifiableNavigableSet<E> implements Serializable { + @java.io.Serial private static final long serialVersionUID = -6291252904449939134L; public EmptyNavigableSet() { super(new TreeSet<>()); } + @java.io.Serial private Object readResolve() { return EMPTY_NAVIGABLE_SET; } } @SuppressWarnings("rawtypes") private static final NavigableSet<?> EMPTY_NAVIGABLE_SET =
*** 1293,1302 **** --- 1299,1309 ---- /** * @serial include */ static class UnmodifiableList<E> extends UnmodifiableCollection<E> implements List<E> { + @java.io.Serial private static final long serialVersionUID = -283967356065247728L; final List<? extends E> list; UnmodifiableList(List<? extends E> list) {
*** 1377,1386 **** --- 1384,1394 ---- * * Note: Unfortunately, UnmodifiableRandomAccessList instances * serialized in 1.4.1 and deserialized in 1.4 will become * UnmodifiableList instances, as this method was missing in 1.4. */ + @java.io.Serial private Object readResolve() { return (list instanceof RandomAccess ? new UnmodifiableRandomAccessList<>(list) : this); }
*** 1399,1416 **** --- 1407,1426 ---- public List<E> subList(int fromIndex, int toIndex) { return new UnmodifiableRandomAccessList<>( list.subList(fromIndex, toIndex)); } + @java.io.Serial private static final long serialVersionUID = -2542308836966382001L; /** * Allows instances to be deserialized in pre-1.4 JREs (which do * not have UnmodifiableRandomAccessList). UnmodifiableList has * a readResolve method that inverts this transformation upon * deserialization. */ + @java.io.Serial private Object writeReplace() { return new UnmodifiableList<>(list); } }
*** 1435,1444 **** --- 1445,1455 ---- /** * @serial include */ private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = -1034234728574286014L; private final Map<? extends K, ? extends V> m; UnmodifiableMap(Map<? extends K, ? extends V> m) {
*** 1561,1570 **** --- 1572,1582 ---- * * @serial include */ static class UnmodifiableEntrySet<K,V> extends UnmodifiableSet<Map.Entry<K,V>> { + @java.io.Serial private static final long serialVersionUID = 7854390611657943733L; @SuppressWarnings({"unchecked", "rawtypes"}) UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) { // Need to cast to raw in order to work around a limitation in the type system
*** 1792,1801 **** --- 1804,1814 ---- * @serial include */ static class UnmodifiableSortedMap<K,V> extends UnmodifiableMap<K,V> implements SortedMap<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = -8806743815996713206L; private final SortedMap<K, ? extends V> sm; UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
*** 1836,1845 **** --- 1849,1859 ---- * @serial include */ static class UnmodifiableNavigableMap<K,V> extends UnmodifiableSortedMap<K,V> implements NavigableMap<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = -4858195264774772197L; /** * A class for the {@link EMPTY_NAVIGABLE_MAP} which needs readResolve * to preserve singleton property.
*** 1848,1865 **** --- 1862,1881 ---- * @param <V> type of values, if there were any */ private static class EmptyNavigableMap<K,V> extends UnmodifiableNavigableMap<K,V> implements Serializable { + @java.io.Serial private static final long serialVersionUID = -2239321462712562324L; EmptyNavigableMap() { super(new TreeMap<>()); } @Override public NavigableSet<K> navigableKeySet() { return emptyNavigableSet(); } + @java.io.Serial private Object readResolve() { return EMPTY_NAVIGABLE_MAP; } } /** * Singleton for {@link emptyNavigableMap()} which is also immutable.
*** 1996,2005 **** --- 2012,2022 ---- /** * @serial include */ static class SynchronizedCollection<E> implements Collection<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 3053995032091335093L; final Collection<E> c; // Backing Collection final Object mutex; // Object on which to synchronize
*** 2080,2089 **** --- 2097,2107 ---- } @Override public Stream<E> parallelStream() { return c.parallelStream(); // Must be manually synched by user! } + @java.io.Serial private void writeObject(ObjectOutputStream s) throws IOException { synchronized (mutex) {s.defaultWriteObject();} } }
*** 2126,2135 **** --- 2144,2154 ---- * @serial include */ static class SynchronizedSet<E> extends SynchronizedCollection<E> implements Set<E> { + @java.io.Serial private static final long serialVersionUID = 487447009682186044L; SynchronizedSet(Set<E> s) { super(s); }
*** 2195,2204 **** --- 2214,2224 ---- */ static class SynchronizedSortedSet<E> extends SynchronizedSet<E> implements SortedSet<E> { + @java.io.Serial private static final long serialVersionUID = 8695801310862127406L; private final SortedSet<E> ss; SynchronizedSortedSet(SortedSet<E> s) {
*** 2289,2298 **** --- 2309,2319 ---- */ static class SynchronizedNavigableSet<E> extends SynchronizedSortedSet<E> implements NavigableSet<E> { + @java.io.Serial private static final long serialVersionUID = -5505529816273629798L; private final NavigableSet<E> ns; SynchronizedNavigableSet(NavigableSet<E> s) {
*** 2398,2407 **** --- 2419,2429 ---- * @serial include */ static class SynchronizedList<E> extends SynchronizedCollection<E> implements List<E> { + @java.io.Serial private static final long serialVersionUID = -7754090372962971524L; final List<E> list; SynchronizedList(List<E> list) {
*** 2480,2489 **** --- 2502,2512 ---- * * Note: Unfortunately, SynchronizedRandomAccessList instances * serialized in 1.4.1 and deserialized in 1.4 will become * SynchronizedList instances, as this method was missing in 1.4. */ + @java.io.Serial private Object readResolve() { return (list instanceof RandomAccess ? new SynchronizedRandomAccessList<>(list) : this); }
*** 2509,2526 **** --- 2532,2551 ---- return new SynchronizedRandomAccessList<>( list.subList(fromIndex, toIndex), mutex); } } + @java.io.Serial private static final long serialVersionUID = 1530674583602358482L; /** * Allows instances to be deserialized in pre-1.4 JREs (which do * not have SynchronizedRandomAccessList). SynchronizedList has * a readResolve method that inverts this transformation upon * deserialization. */ + @java.io.Serial private Object writeReplace() { return new SynchronizedList<>(list); } }
*** 2561,2570 **** --- 2586,2596 ---- /** * @serial include */ private static class SynchronizedMap<K,V> implements Map<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1978198479659022715L; private final Map<K,V> m; // Backing Map final Object mutex; // Object on which to synchronize
*** 2695,2704 **** --- 2721,2731 ---- public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { synchronized (mutex) {return m.merge(key, value, remappingFunction);} } + @java.io.Serial private void writeObject(ObjectOutputStream s) throws IOException { synchronized (mutex) {s.defaultWriteObject();} } }
*** 2756,2765 **** --- 2783,2793 ---- */ static class SynchronizedSortedMap<K,V> extends SynchronizedMap<K,V> implements SortedMap<K,V> { + @java.io.Serial private static final long serialVersionUID = -8798146769416483793L; private final SortedMap<K,V> sm; SynchronizedSortedMap(SortedMap<K,V> m) {
*** 2858,2867 **** --- 2886,2896 ---- */ static class SynchronizedNavigableMap<K,V> extends SynchronizedSortedMap<K,V> implements NavigableMap<K,V> { + @java.io.Serial private static final long serialVersionUID = 699392247599746807L; private final NavigableMap<K,V> nm; SynchronizedNavigableMap(NavigableMap<K,V> m) {
*** 3036,3045 **** --- 3065,3075 ---- /** * @serial include */ static class CheckedCollection<E> implements Collection<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1578914078182001775L; final Collection<E> c; final Class<E> type;
*** 3185,3194 **** --- 3215,3225 ---- */ static class CheckedQueue<E> extends CheckedCollection<E> implements Queue<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1433151992604707767L; final Queue<E> queue; CheckedQueue(Queue<E> queue, Class<E> elementType) { super(queue, elementType);
*** 3239,3248 **** --- 3270,3280 ---- * @serial include */ static class CheckedSet<E> extends CheckedCollection<E> implements Set<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 4694047833775013803L; CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); } public boolean equals(Object o) { return o == this || c.equals(o); }
*** 3286,3295 **** --- 3318,3328 ---- * @serial include */ static class CheckedSortedSet<E> extends CheckedSet<E> implements SortedSet<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1599911165492914959L; private final SortedSet<E> ss; CheckedSortedSet(SortedSet<E> s, Class<E> type) {
*** 3349,3358 **** --- 3382,3392 ---- * @serial include */ static class CheckedNavigableSet<E> extends CheckedSortedSet<E> implements NavigableSet<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = -5429120189805438922L; private final NavigableSet<E> ns; CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
*** 3432,3441 **** --- 3466,3476 ---- */ static class CheckedList<E> extends CheckedCollection<E> implements List<E> { + @java.io.Serial private static final long serialVersionUID = 65247728283967356L; final List<E> list; CheckedList(List<E> list, Class<E> type) { super(list, type);
*** 3517,3526 **** --- 3552,3562 ---- * @serial include */ static class CheckedRandomAccessList<E> extends CheckedList<E> implements RandomAccess { + @java.io.Serial private static final long serialVersionUID = 1638200125423088369L; CheckedRandomAccessList(List<E> list, Class<E> type) { super(list, type); }
*** 3578,3587 **** --- 3614,3624 ---- * @serial include */ private static class CheckedMap<K,V> implements Map<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = 5742860141034234728L; private final Map<K, V> m; final Class<K> keyType; final Class<V> valueType;
*** 3977,3986 **** --- 4014,4024 ---- * @serial include */ static class CheckedSortedMap<K,V> extends CheckedMap<K,V> implements SortedMap<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1599671320688067438L; private final SortedMap<K, V> sm; CheckedSortedMap(SortedMap<K, V> m,
*** 4051,4060 **** --- 4089,4099 ---- * @serial include */ static class CheckedNavigableMap<K,V> extends CheckedSortedMap<K,V> implements NavigableMap<K,V>, Serializable { + @java.io.Serial private static final long serialVersionUID = -4852462692372534096L; private final NavigableMap<K, V> nm; CheckedNavigableMap(NavigableMap<K, V> m,
*** 4329,4338 **** --- 4368,4378 ---- */ private static class EmptySet<E> extends AbstractSet<E> implements Serializable { + @java.io.Serial private static final long serialVersionUID = 1582296315990362920L; public Iterator<E> iterator() { return emptyIterator(); } public int size() {return 0;}
*** 4362,4371 **** --- 4402,4412 ---- } @Override public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); } // Preserves singleton property + @java.io.Serial private Object readResolve() { return EMPTY_SET; } @Override
*** 4453,4462 **** --- 4494,4504 ---- * @serial include */ private static class EmptyList<E> extends AbstractList<E> implements RandomAccess, Serializable { + @java.io.Serial private static final long serialVersionUID = 8842843931221139166L; public Iterator<E> iterator() { return emptyIterator(); }
*** 4510,4519 **** --- 4552,4562 ---- @Override public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); } // Preserves singleton property + @java.io.Serial private Object readResolve() { return EMPTY_LIST; } }
*** 4596,4605 **** --- 4639,4649 ---- */ private static class EmptyMap<K,V> extends AbstractMap<K,V> implements Serializable { + @java.io.Serial private static final long serialVersionUID = 6428348081105594320L; public int size() {return 0;} public boolean isEmpty() {return true;} public void clear() {}
*** 4676,4685 **** --- 4720,4730 ---- BiFunction<? super V, ? super V, ? extends V> remappingFunction) { throw new UnsupportedOperationException(); } // Preserves singleton property + @java.io.Serial private Object readResolve() { return EMPTY_MAP; } }
*** 4775,4784 **** --- 4820,4830 ---- */ private static class SingletonSet<E> extends AbstractSet<E> implements Serializable { + @java.io.Serial private static final long serialVersionUID = 3193687207550431679L; private final E element; SingletonSet(E e) {element = e;}
*** 4828,4837 **** --- 4874,4884 ---- */ private static class SingletonList<E> extends AbstractList<E> implements RandomAccess, Serializable { + @java.io.Serial private static final long serialVersionUID = 3093736618740652951L; private final E element; SingletonList(E obj) {element = obj;}
*** 4896,4905 **** --- 4943,4953 ---- * @serial include */ private static class SingletonMap<K,V> extends AbstractMap<K,V> implements Serializable { + @java.io.Serial private static final long serialVersionUID = -6979724477215052911L; private final K k; private final V v;
*** 5033,5042 **** --- 5081,5091 ---- */ private static class CopiesList<E> extends AbstractList<E> implements RandomAccess, Serializable { + @java.io.Serial private static final long serialVersionUID = 2739099268398711800L; final int n; final E element;
*** 5164,5173 **** --- 5213,5223 ---- @Override public Spliterator<E> spliterator() { return stream().spliterator(); } + @java.io.Serial private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); SharedSecrets.getJavaObjectInputStreamAccess().checkArray(ois, Object[].class, n); } }
*** 5201,5219 **** --- 5251,5271 ---- * @serial include */ private static class ReverseComparator implements Comparator<Comparable<Object>>, Serializable { + @java.io.Serial private static final long serialVersionUID = 7207038068494060240L; static final ReverseComparator REVERSE_ORDER = new ReverseComparator(); public int compare(Comparable<Object> c1, Comparable<Object> c2) { return c2.compareTo(c1); } + @java.io.Serial private Object readResolve() { return Collections.reverseOrder(); } @Override public Comparator<Comparable<Object>> reversed() { return Comparator.naturalOrder();
*** 5256,5265 **** --- 5308,5318 ---- * @serial include */ private static class ReverseComparator2<T> implements Comparator<T>, Serializable { + @java.io.Serial private static final long serialVersionUID = 4374092139857L; /** * The comparator specified in the static factory. This will never * be null, as the static factory returns a ReverseComparator
*** 5590,5601 **** --- 5643,5656 ---- @Override public Stream<E> stream() {return s.stream();} @Override public Stream<E> parallelStream() {return s.parallelStream();} + @java.io.Serial private static final long serialVersionUID = 2454657854757543876L; + @java.io.Serial private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); s = m.keySet();
*** 5627,5636 **** --- 5682,5692 ---- /** * @serial include */ static class AsLIFOQueue<E> extends AbstractQueue<E> implements Queue<E>, Serializable { + @java.io.Serial private static final long serialVersionUID = 1802017725587941708L; private final Deque<E> q; AsLIFOQueue(Deque<E> q) { this.q = q; } public boolean add(E e) { q.addFirst(e); return true; } public boolean offer(E e) { return q.offerFirst(e); }
< prev index next >