< prev index next >
src/java.base/share/classes/java/util/Collections.java
Print this page
@@ -1019,10 +1019,11 @@
/**
* @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,10 +1126,11 @@
/**
* @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,10 +1160,11 @@
* @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,26 +1213,29 @@
*/
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,10 +1299,11 @@
/**
* @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,10 +1384,11 @@
*
* 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,18 +1407,20 @@
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,10 +1445,11 @@
/**
* @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,10 +1572,11 @@
*
* @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,10 +1804,11 @@
* @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,10 +1849,11 @@
* @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,18 +1862,20 @@
* @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,10 +2012,11 @@
/**
* @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,10 +2097,11 @@
}
@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,10 +2144,11 @@
* @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,10 +2214,11 @@
*/
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,10 +2309,11 @@
*/
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,10 +2419,11 @@
* @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,10 +2502,11 @@
*
* 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,18 +2532,20 @@
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,10 +2586,11 @@
/**
* @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,10 +2721,11 @@
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,10 +2783,11 @@
*/
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,10 +2886,11 @@
*/
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,10 +3065,11 @@
/**
* @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,10 +3215,11 @@
*/
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,10 +3270,11 @@
* @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,10 +3318,11 @@
* @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,10 +3382,11 @@
* @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,10 +3466,11 @@
*/
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,10 +3552,11 @@
* @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,10 +3614,11 @@
* @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,10 +4014,11 @@
* @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,10 +4089,11 @@
* @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,10 +4368,11 @@
*/
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,10 +4402,11 @@
}
@Override
public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
// Preserves singleton property
+ @java.io.Serial
private Object readResolve() {
return EMPTY_SET;
}
@Override
@@ -4453,10 +4494,11 @@
* @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,10 +4552,11 @@
@Override
public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
// Preserves singleton property
+ @java.io.Serial
private Object readResolve() {
return EMPTY_LIST;
}
}
@@ -4596,10 +4639,11 @@
*/
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,10 +4720,11 @@
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
}
// Preserves singleton property
+ @java.io.Serial
private Object readResolve() {
return EMPTY_MAP;
}
}
@@ -4775,10 +4820,11 @@
*/
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,10 +4874,11 @@
*/
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,10 +4943,11 @@
* @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,10 +5081,11 @@
*/
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,10 +5213,11 @@
@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,19 +5251,21 @@
* @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,10 +5308,11 @@
* @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,12 +5643,14 @@
@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,10 +5682,11 @@
/**
* @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 >