src/java.base/share/classes/java/util/Collections.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 53107 cfceb4df2499
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package java.util;
    26 package java.util;
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
       
    29 import java.io.ObjectInputStream;
    29 import java.io.ObjectOutputStream;
    30 import java.io.ObjectOutputStream;
    30 import java.io.Serializable;
    31 import java.io.Serializable;
    31 import java.lang.reflect.Array;
    32 import java.lang.reflect.Array;
    32 import java.util.function.BiConsumer;
    33 import java.util.function.BiConsumer;
    33 import java.util.function.BiFunction;
    34 import java.util.function.BiFunction;
    37 import java.util.function.Predicate;
    38 import java.util.function.Predicate;
    38 import java.util.function.UnaryOperator;
    39 import java.util.function.UnaryOperator;
    39 import java.util.stream.IntStream;
    40 import java.util.stream.IntStream;
    40 import java.util.stream.Stream;
    41 import java.util.stream.Stream;
    41 import java.util.stream.StreamSupport;
    42 import java.util.stream.StreamSupport;
       
    43 import jdk.internal.access.SharedSecrets;
    42 
    44 
    43 /**
    45 /**
    44  * This class consists exclusively of static methods that operate on or return
    46  * This class consists exclusively of static methods that operate on or return
    45  * collections.  It contains polymorphic algorithms that operate on
    47  * collections.  It contains polymorphic algorithms that operate on
    46  * collections, "wrappers", which return a new collection backed by a
    48  * collections, "wrappers", which return a new collection backed by a
  1017 
  1019 
  1018     /**
  1020     /**
  1019      * @serial include
  1021      * @serial include
  1020      */
  1022      */
  1021     static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
  1023     static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
       
  1024         @java.io.Serial
  1022         private static final long serialVersionUID = 1820017752578914078L;
  1025         private static final long serialVersionUID = 1820017752578914078L;
  1023 
  1026 
       
  1027         @SuppressWarnings("serial") // Conditionally serializable
  1024         final Collection<? extends E> c;
  1028         final Collection<? extends E> c;
  1025 
  1029 
  1026         UnmodifiableCollection(Collection<? extends E> c) {
  1030         UnmodifiableCollection(Collection<? extends E> c) {
  1027             if (c==null)
  1031             if (c==null)
  1028                 throw new NullPointerException();
  1032                 throw new NullPointerException();
  1123     /**
  1127     /**
  1124      * @serial include
  1128      * @serial include
  1125      */
  1129      */
  1126     static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
  1130     static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
  1127                                  implements Set<E>, Serializable {
  1131                                  implements Set<E>, Serializable {
       
  1132         @java.io.Serial
  1128         private static final long serialVersionUID = -9215047833775013803L;
  1133         private static final long serialVersionUID = -9215047833775013803L;
  1129 
  1134 
  1130         UnmodifiableSet(Set<? extends E> s)     {super(s);}
  1135         UnmodifiableSet(Set<? extends E> s)     {super(s);}
  1131         public boolean equals(Object o) {return o == this || c.equals(o);}
  1136         public boolean equals(Object o) {return o == this || c.equals(o);}
  1132         public int hashCode()           {return c.hashCode();}
  1137         public int hashCode()           {return c.hashCode();}
  1156      * @serial include
  1161      * @serial include
  1157      */
  1162      */
  1158     static class UnmodifiableSortedSet<E>
  1163     static class UnmodifiableSortedSet<E>
  1159                              extends UnmodifiableSet<E>
  1164                              extends UnmodifiableSet<E>
  1160                              implements SortedSet<E>, Serializable {
  1165                              implements SortedSet<E>, Serializable {
       
  1166         @java.io.Serial
  1161         private static final long serialVersionUID = -4929149591599911165L;
  1167         private static final long serialVersionUID = -4929149591599911165L;
       
  1168         @SuppressWarnings("serial") // Conditionally serializable
  1162         private final SortedSet<E> ss;
  1169         private final SortedSet<E> ss;
  1163 
  1170 
  1164         UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
  1171         UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
  1165 
  1172 
  1166         public Comparator<? super E> comparator() {return ss.comparator();}
  1173         public Comparator<? super E> comparator() {return ss.comparator();}
  1208      */
  1215      */
  1209     static class UnmodifiableNavigableSet<E>
  1216     static class UnmodifiableNavigableSet<E>
  1210                              extends UnmodifiableSortedSet<E>
  1217                              extends UnmodifiableSortedSet<E>
  1211                              implements NavigableSet<E>, Serializable {
  1218                              implements NavigableSet<E>, Serializable {
  1212 
  1219 
       
  1220         @java.io.Serial
  1213         private static final long serialVersionUID = -6027448201786391929L;
  1221         private static final long serialVersionUID = -6027448201786391929L;
  1214 
  1222 
  1215         /**
  1223         /**
  1216          * A singleton empty unmodifiable navigable set used for
  1224          * A singleton empty unmodifiable navigable set used for
  1217          * {@link #emptyNavigableSet()}.
  1225          * {@link #emptyNavigableSet()}.
  1218          *
  1226          *
  1219          * @param <E> type of elements, if there were any, and bounds
  1227          * @param <E> type of elements, if there were any, and bounds
  1220          */
  1228          */
  1221         private static class EmptyNavigableSet<E> extends UnmodifiableNavigableSet<E>
  1229         private static class EmptyNavigableSet<E> extends UnmodifiableNavigableSet<E>
  1222             implements Serializable {
  1230             implements Serializable {
       
  1231             @java.io.Serial
  1223             private static final long serialVersionUID = -6291252904449939134L;
  1232             private static final long serialVersionUID = -6291252904449939134L;
  1224 
  1233 
  1225             public EmptyNavigableSet() {
  1234             public EmptyNavigableSet() {
  1226                 super(new TreeSet<>());
  1235                 super(new TreeSet<>());
  1227             }
  1236             }
  1228 
  1237 
       
  1238             @java.io.Serial
  1229             private Object readResolve()        { return EMPTY_NAVIGABLE_SET; }
  1239             private Object readResolve()        { return EMPTY_NAVIGABLE_SET; }
  1230         }
  1240         }
  1231 
  1241 
  1232         @SuppressWarnings("rawtypes")
  1242         @SuppressWarnings("rawtypes")
  1233         private static final NavigableSet<?> EMPTY_NAVIGABLE_SET =
  1243         private static final NavigableSet<?> EMPTY_NAVIGABLE_SET =
  1234                 new EmptyNavigableSet<>();
  1244                 new EmptyNavigableSet<>();
  1235 
  1245 
  1236         /**
  1246         /**
  1237          * The instance we are protecting.
  1247          * The instance we are protecting.
  1238          */
  1248          */
       
  1249         @SuppressWarnings("serial") // Conditionally serializable
  1239         private final NavigableSet<E> ns;
  1250         private final NavigableSet<E> ns;
  1240 
  1251 
  1241         UnmodifiableNavigableSet(NavigableSet<E> s)         {super(s); ns = s;}
  1252         UnmodifiableNavigableSet(NavigableSet<E> s)         {super(s); ns = s;}
  1242 
  1253 
  1243         public E lower(E e)                             { return ns.lower(e); }
  1254         public E lower(E e)                             { return ns.lower(e); }
  1291     /**
  1302     /**
  1292      * @serial include
  1303      * @serial include
  1293      */
  1304      */
  1294     static class UnmodifiableList<E> extends UnmodifiableCollection<E>
  1305     static class UnmodifiableList<E> extends UnmodifiableCollection<E>
  1295                                   implements List<E> {
  1306                                   implements List<E> {
       
  1307         @java.io.Serial
  1296         private static final long serialVersionUID = -283967356065247728L;
  1308         private static final long serialVersionUID = -283967356065247728L;
  1297 
  1309 
       
  1310         @SuppressWarnings("serial") // Conditionally serializable
  1298         final List<? extends E> list;
  1311         final List<? extends E> list;
  1299 
  1312 
  1300         UnmodifiableList(List<? extends E> list) {
  1313         UnmodifiableList(List<? extends E> list) {
  1301             super(list);
  1314             super(list);
  1302             this.list = list;
  1315             this.list = list;
  1375          *
  1388          *
  1376          * Note: Unfortunately, UnmodifiableRandomAccessList instances
  1389          * Note: Unfortunately, UnmodifiableRandomAccessList instances
  1377          * serialized in 1.4.1 and deserialized in 1.4 will become
  1390          * serialized in 1.4.1 and deserialized in 1.4 will become
  1378          * UnmodifiableList instances, as this method was missing in 1.4.
  1391          * UnmodifiableList instances, as this method was missing in 1.4.
  1379          */
  1392          */
       
  1393         @java.io.Serial
  1380         private Object readResolve() {
  1394         private Object readResolve() {
  1381             return (list instanceof RandomAccess
  1395             return (list instanceof RandomAccess
  1382                     ? new UnmodifiableRandomAccessList<>(list)
  1396                     ? new UnmodifiableRandomAccessList<>(list)
  1383                     : this);
  1397                     : this);
  1384         }
  1398         }
  1397         public List<E> subList(int fromIndex, int toIndex) {
  1411         public List<E> subList(int fromIndex, int toIndex) {
  1398             return new UnmodifiableRandomAccessList<>(
  1412             return new UnmodifiableRandomAccessList<>(
  1399                 list.subList(fromIndex, toIndex));
  1413                 list.subList(fromIndex, toIndex));
  1400         }
  1414         }
  1401 
  1415 
       
  1416         @java.io.Serial
  1402         private static final long serialVersionUID = -2542308836966382001L;
  1417         private static final long serialVersionUID = -2542308836966382001L;
  1403 
  1418 
  1404         /**
  1419         /**
  1405          * Allows instances to be deserialized in pre-1.4 JREs (which do
  1420          * Allows instances to be deserialized in pre-1.4 JREs (which do
  1406          * not have UnmodifiableRandomAccessList).  UnmodifiableList has
  1421          * not have UnmodifiableRandomAccessList).  UnmodifiableList has
  1407          * a readResolve method that inverts this transformation upon
  1422          * a readResolve method that inverts this transformation upon
  1408          * deserialization.
  1423          * deserialization.
  1409          */
  1424          */
       
  1425         @java.io.Serial
  1410         private Object writeReplace() {
  1426         private Object writeReplace() {
  1411             return new UnmodifiableList<>(list);
  1427             return new UnmodifiableList<>(list);
  1412         }
  1428         }
  1413     }
  1429     }
  1414 
  1430 
  1433 
  1449 
  1434     /**
  1450     /**
  1435      * @serial include
  1451      * @serial include
  1436      */
  1452      */
  1437     private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
  1453     private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
       
  1454         @java.io.Serial
  1438         private static final long serialVersionUID = -1034234728574286014L;
  1455         private static final long serialVersionUID = -1034234728574286014L;
  1439 
  1456 
       
  1457         @SuppressWarnings("serial") // Conditionally serializable
  1440         private final Map<? extends K, ? extends V> m;
  1458         private final Map<? extends K, ? extends V> m;
  1441 
  1459 
  1442         UnmodifiableMap(Map<? extends K, ? extends V> m) {
  1460         UnmodifiableMap(Map<? extends K, ? extends V> m) {
  1443             if (m==null)
  1461             if (m==null)
  1444                 throw new NullPointerException();
  1462                 throw new NullPointerException();
  1559          *
  1577          *
  1560          * @serial include
  1578          * @serial include
  1561          */
  1579          */
  1562         static class UnmodifiableEntrySet<K,V>
  1580         static class UnmodifiableEntrySet<K,V>
  1563             extends UnmodifiableSet<Map.Entry<K,V>> {
  1581             extends UnmodifiableSet<Map.Entry<K,V>> {
       
  1582             @java.io.Serial
  1564             private static final long serialVersionUID = 7854390611657943733L;
  1583             private static final long serialVersionUID = 7854390611657943733L;
  1565 
  1584 
  1566             @SuppressWarnings({"unchecked", "rawtypes"})
  1585             @SuppressWarnings({"unchecked", "rawtypes"})
  1567             UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
  1586             UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
  1568                 // Need to cast to raw in order to work around a limitation in the type system
  1587                 // Need to cast to raw in order to work around a limitation in the type system
  1790      * @serial include
  1809      * @serial include
  1791      */
  1810      */
  1792     static class UnmodifiableSortedMap<K,V>
  1811     static class UnmodifiableSortedMap<K,V>
  1793           extends UnmodifiableMap<K,V>
  1812           extends UnmodifiableMap<K,V>
  1794           implements SortedMap<K,V>, Serializable {
  1813           implements SortedMap<K,V>, Serializable {
       
  1814         @java.io.Serial
  1795         private static final long serialVersionUID = -8806743815996713206L;
  1815         private static final long serialVersionUID = -8806743815996713206L;
  1796 
  1816 
       
  1817         @SuppressWarnings("serial") // Conditionally serializable
  1797         private final SortedMap<K, ? extends V> sm;
  1818         private final SortedMap<K, ? extends V> sm;
  1798 
  1819 
  1799         UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
  1820         UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
  1800         public Comparator<? super K> comparator()   { return sm.comparator(); }
  1821         public Comparator<? super K> comparator()   { return sm.comparator(); }
  1801         public SortedMap<K,V> subMap(K fromKey, K toKey)
  1822         public SortedMap<K,V> subMap(K fromKey, K toKey)
  1834      * @serial include
  1855      * @serial include
  1835      */
  1856      */
  1836     static class UnmodifiableNavigableMap<K,V>
  1857     static class UnmodifiableNavigableMap<K,V>
  1837           extends UnmodifiableSortedMap<K,V>
  1858           extends UnmodifiableSortedMap<K,V>
  1838           implements NavigableMap<K,V>, Serializable {
  1859           implements NavigableMap<K,V>, Serializable {
       
  1860         @java.io.Serial
  1839         private static final long serialVersionUID = -4858195264774772197L;
  1861         private static final long serialVersionUID = -4858195264774772197L;
  1840 
  1862 
  1841         /**
  1863         /**
  1842          * A class for the {@link EMPTY_NAVIGABLE_MAP} which needs readResolve
  1864          * A class for the {@link EMPTY_NAVIGABLE_MAP} which needs readResolve
  1843          * to preserve singleton property.
  1865          * to preserve singleton property.
  1846          * @param <V> type of values, if there were any
  1868          * @param <V> type of values, if there were any
  1847          */
  1869          */
  1848         private static class EmptyNavigableMap<K,V> extends UnmodifiableNavigableMap<K,V>
  1870         private static class EmptyNavigableMap<K,V> extends UnmodifiableNavigableMap<K,V>
  1849             implements Serializable {
  1871             implements Serializable {
  1850 
  1872 
       
  1873             @java.io.Serial
  1851             private static final long serialVersionUID = -2239321462712562324L;
  1874             private static final long serialVersionUID = -2239321462712562324L;
  1852 
  1875 
  1853             EmptyNavigableMap()                       { super(new TreeMap<>()); }
  1876             EmptyNavigableMap()                       { super(new TreeMap<>()); }
  1854 
  1877 
  1855             @Override
  1878             @Override
  1856             public NavigableSet<K> navigableKeySet()
  1879             public NavigableSet<K> navigableKeySet()
  1857                                                 { return emptyNavigableSet(); }
  1880                                                 { return emptyNavigableSet(); }
  1858 
  1881 
       
  1882             @java.io.Serial
  1859             private Object readResolve()        { return EMPTY_NAVIGABLE_MAP; }
  1883             private Object readResolve()        { return EMPTY_NAVIGABLE_MAP; }
  1860         }
  1884         }
  1861 
  1885 
  1862         /**
  1886         /**
  1863          * Singleton for {@link emptyNavigableMap()} which is also immutable.
  1887          * Singleton for {@link emptyNavigableMap()} which is also immutable.
  1866             new EmptyNavigableMap<>();
  1890             new EmptyNavigableMap<>();
  1867 
  1891 
  1868         /**
  1892         /**
  1869          * The instance we wrap and protect.
  1893          * The instance we wrap and protect.
  1870          */
  1894          */
       
  1895         @SuppressWarnings("serial") // Conditionally serializable
  1871         private final NavigableMap<K, ? extends V> nm;
  1896         private final NavigableMap<K, ? extends V> nm;
  1872 
  1897 
  1873         UnmodifiableNavigableMap(NavigableMap<K, ? extends V> m)
  1898         UnmodifiableNavigableMap(NavigableMap<K, ? extends V> m)
  1874                                                             {super(m); nm = m;}
  1899                                                             {super(m); nm = m;}
  1875 
  1900 
  1994 
  2019 
  1995     /**
  2020     /**
  1996      * @serial include
  2021      * @serial include
  1997      */
  2022      */
  1998     static class SynchronizedCollection<E> implements Collection<E>, Serializable {
  2023     static class SynchronizedCollection<E> implements Collection<E>, Serializable {
       
  2024         @java.io.Serial
  1999         private static final long serialVersionUID = 3053995032091335093L;
  2025         private static final long serialVersionUID = 3053995032091335093L;
  2000 
  2026 
       
  2027         @SuppressWarnings("serial") // Conditionally serializable
  2001         final Collection<E> c;  // Backing Collection
  2028         final Collection<E> c;  // Backing Collection
       
  2029         @SuppressWarnings("serial") // Conditionally serializable
  2002         final Object mutex;     // Object on which to synchronize
  2030         final Object mutex;     // Object on which to synchronize
  2003 
  2031 
  2004         SynchronizedCollection(Collection<E> c) {
  2032         SynchronizedCollection(Collection<E> c) {
  2005             this.c = Objects.requireNonNull(c);
  2033             this.c = Objects.requireNonNull(c);
  2006             mutex = this;
  2034             mutex = this;
  2078         }
  2106         }
  2079         @Override
  2107         @Override
  2080         public Stream<E> parallelStream() {
  2108         public Stream<E> parallelStream() {
  2081             return c.parallelStream(); // Must be manually synched by user!
  2109             return c.parallelStream(); // Must be manually synched by user!
  2082         }
  2110         }
       
  2111         @java.io.Serial
  2083         private void writeObject(ObjectOutputStream s) throws IOException {
  2112         private void writeObject(ObjectOutputStream s) throws IOException {
  2084             synchronized (mutex) {s.defaultWriteObject();}
  2113             synchronized (mutex) {s.defaultWriteObject();}
  2085         }
  2114         }
  2086     }
  2115     }
  2087 
  2116 
  2124      * @serial include
  2153      * @serial include
  2125      */
  2154      */
  2126     static class SynchronizedSet<E>
  2155     static class SynchronizedSet<E>
  2127           extends SynchronizedCollection<E>
  2156           extends SynchronizedCollection<E>
  2128           implements Set<E> {
  2157           implements Set<E> {
       
  2158         @java.io.Serial
  2129         private static final long serialVersionUID = 487447009682186044L;
  2159         private static final long serialVersionUID = 487447009682186044L;
  2130 
  2160 
  2131         SynchronizedSet(Set<E> s) {
  2161         SynchronizedSet(Set<E> s) {
  2132             super(s);
  2162             super(s);
  2133         }
  2163         }
  2193      */
  2223      */
  2194     static class SynchronizedSortedSet<E>
  2224     static class SynchronizedSortedSet<E>
  2195         extends SynchronizedSet<E>
  2225         extends SynchronizedSet<E>
  2196         implements SortedSet<E>
  2226         implements SortedSet<E>
  2197     {
  2227     {
       
  2228         @java.io.Serial
  2198         private static final long serialVersionUID = 8695801310862127406L;
  2229         private static final long serialVersionUID = 8695801310862127406L;
  2199 
  2230 
       
  2231         @SuppressWarnings("serial") // Conditionally serializable
  2200         private final SortedSet<E> ss;
  2232         private final SortedSet<E> ss;
  2201 
  2233 
  2202         SynchronizedSortedSet(SortedSet<E> s) {
  2234         SynchronizedSortedSet(SortedSet<E> s) {
  2203             super(s);
  2235             super(s);
  2204             ss = s;
  2236             ss = s;
  2287      */
  2319      */
  2288     static class SynchronizedNavigableSet<E>
  2320     static class SynchronizedNavigableSet<E>
  2289         extends SynchronizedSortedSet<E>
  2321         extends SynchronizedSortedSet<E>
  2290         implements NavigableSet<E>
  2322         implements NavigableSet<E>
  2291     {
  2323     {
       
  2324         @java.io.Serial
  2292         private static final long serialVersionUID = -5505529816273629798L;
  2325         private static final long serialVersionUID = -5505529816273629798L;
  2293 
  2326 
       
  2327         @SuppressWarnings("serial") // Conditionally serializable
  2294         private final NavigableSet<E> ns;
  2328         private final NavigableSet<E> ns;
  2295 
  2329 
  2296         SynchronizedNavigableSet(NavigableSet<E> s) {
  2330         SynchronizedNavigableSet(NavigableSet<E> s) {
  2297             super(s);
  2331             super(s);
  2298             ns = s;
  2332             ns = s;
  2396      * @serial include
  2430      * @serial include
  2397      */
  2431      */
  2398     static class SynchronizedList<E>
  2432     static class SynchronizedList<E>
  2399         extends SynchronizedCollection<E>
  2433         extends SynchronizedCollection<E>
  2400         implements List<E> {
  2434         implements List<E> {
       
  2435         @java.io.Serial
  2401         private static final long serialVersionUID = -7754090372962971524L;
  2436         private static final long serialVersionUID = -7754090372962971524L;
  2402 
  2437 
       
  2438         @SuppressWarnings("serial") // Conditionally serializable
  2403         final List<E> list;
  2439         final List<E> list;
  2404 
  2440 
  2405         SynchronizedList(List<E> list) {
  2441         SynchronizedList(List<E> list) {
  2406             super(list);
  2442             super(list);
  2407             this.list = list;
  2443             this.list = list;
  2478          *
  2514          *
  2479          * Note: Unfortunately, SynchronizedRandomAccessList instances
  2515          * Note: Unfortunately, SynchronizedRandomAccessList instances
  2480          * serialized in 1.4.1 and deserialized in 1.4 will become
  2516          * serialized in 1.4.1 and deserialized in 1.4 will become
  2481          * SynchronizedList instances, as this method was missing in 1.4.
  2517          * SynchronizedList instances, as this method was missing in 1.4.
  2482          */
  2518          */
       
  2519         @java.io.Serial
  2483         private Object readResolve() {
  2520         private Object readResolve() {
  2484             return (list instanceof RandomAccess
  2521             return (list instanceof RandomAccess
  2485                     ? new SynchronizedRandomAccessList<>(list)
  2522                     ? new SynchronizedRandomAccessList<>(list)
  2486                     : this);
  2523                     : this);
  2487         }
  2524         }
  2507                 return new SynchronizedRandomAccessList<>(
  2544                 return new SynchronizedRandomAccessList<>(
  2508                     list.subList(fromIndex, toIndex), mutex);
  2545                     list.subList(fromIndex, toIndex), mutex);
  2509             }
  2546             }
  2510         }
  2547         }
  2511 
  2548 
       
  2549         @java.io.Serial
  2512         private static final long serialVersionUID = 1530674583602358482L;
  2550         private static final long serialVersionUID = 1530674583602358482L;
  2513 
  2551 
  2514         /**
  2552         /**
  2515          * Allows instances to be deserialized in pre-1.4 JREs (which do
  2553          * Allows instances to be deserialized in pre-1.4 JREs (which do
  2516          * not have SynchronizedRandomAccessList).  SynchronizedList has
  2554          * not have SynchronizedRandomAccessList).  SynchronizedList has
  2517          * a readResolve method that inverts this transformation upon
  2555          * a readResolve method that inverts this transformation upon
  2518          * deserialization.
  2556          * deserialization.
  2519          */
  2557          */
       
  2558         @java.io.Serial
  2520         private Object writeReplace() {
  2559         private Object writeReplace() {
  2521             return new SynchronizedList<>(list);
  2560             return new SynchronizedList<>(list);
  2522         }
  2561         }
  2523     }
  2562     }
  2524 
  2563 
  2559     /**
  2598     /**
  2560      * @serial include
  2599      * @serial include
  2561      */
  2600      */
  2562     private static class SynchronizedMap<K,V>
  2601     private static class SynchronizedMap<K,V>
  2563         implements Map<K,V>, Serializable {
  2602         implements Map<K,V>, Serializable {
       
  2603         @java.io.Serial
  2564         private static final long serialVersionUID = 1978198479659022715L;
  2604         private static final long serialVersionUID = 1978198479659022715L;
  2565 
  2605 
       
  2606         @SuppressWarnings("serial") // Conditionally serializable
  2566         private final Map<K,V> m;     // Backing Map
  2607         private final Map<K,V> m;     // Backing Map
       
  2608         @SuppressWarnings("serial") // Conditionally serializable
  2567         final Object      mutex;        // Object on which to synchronize
  2609         final Object      mutex;        // Object on which to synchronize
  2568 
  2610 
  2569         SynchronizedMap(Map<K,V> m) {
  2611         SynchronizedMap(Map<K,V> m) {
  2570             this.m = Objects.requireNonNull(m);
  2612             this.m = Objects.requireNonNull(m);
  2571             mutex = this;
  2613             mutex = this;
  2693         public V merge(K key, V value,
  2735         public V merge(K key, V value,
  2694                 BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  2736                 BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  2695             synchronized (mutex) {return m.merge(key, value, remappingFunction);}
  2737             synchronized (mutex) {return m.merge(key, value, remappingFunction);}
  2696         }
  2738         }
  2697 
  2739 
       
  2740         @java.io.Serial
  2698         private void writeObject(ObjectOutputStream s) throws IOException {
  2741         private void writeObject(ObjectOutputStream s) throws IOException {
  2699             synchronized (mutex) {s.defaultWriteObject();}
  2742             synchronized (mutex) {s.defaultWriteObject();}
  2700         }
  2743         }
  2701     }
  2744     }
  2702 
  2745 
  2754      */
  2797      */
  2755     static class SynchronizedSortedMap<K,V>
  2798     static class SynchronizedSortedMap<K,V>
  2756         extends SynchronizedMap<K,V>
  2799         extends SynchronizedMap<K,V>
  2757         implements SortedMap<K,V>
  2800         implements SortedMap<K,V>
  2758     {
  2801     {
       
  2802         @java.io.Serial
  2759         private static final long serialVersionUID = -8798146769416483793L;
  2803         private static final long serialVersionUID = -8798146769416483793L;
  2760 
  2804 
       
  2805         @SuppressWarnings("serial") // Conditionally serializable
  2761         private final SortedMap<K,V> sm;
  2806         private final SortedMap<K,V> sm;
  2762 
  2807 
  2763         SynchronizedSortedMap(SortedMap<K,V> m) {
  2808         SynchronizedSortedMap(SortedMap<K,V> m) {
  2764             super(m);
  2809             super(m);
  2765             sm = m;
  2810             sm = m;
  2856      */
  2901      */
  2857     static class SynchronizedNavigableMap<K,V>
  2902     static class SynchronizedNavigableMap<K,V>
  2858         extends SynchronizedSortedMap<K,V>
  2903         extends SynchronizedSortedMap<K,V>
  2859         implements NavigableMap<K,V>
  2904         implements NavigableMap<K,V>
  2860     {
  2905     {
       
  2906         @java.io.Serial
  2861         private static final long serialVersionUID = 699392247599746807L;
  2907         private static final long serialVersionUID = 699392247599746807L;
  2862 
  2908 
       
  2909         @SuppressWarnings("serial") // Conditionally serializable
  2863         private final NavigableMap<K,V> nm;
  2910         private final NavigableMap<K,V> nm;
  2864 
  2911 
  2865         SynchronizedNavigableMap(NavigableMap<K,V> m) {
  2912         SynchronizedNavigableMap(NavigableMap<K,V> m) {
  2866             super(m);
  2913             super(m);
  2867             nm = m;
  2914             nm = m;
  3034 
  3081 
  3035     /**
  3082     /**
  3036      * @serial include
  3083      * @serial include
  3037      */
  3084      */
  3038     static class CheckedCollection<E> implements Collection<E>, Serializable {
  3085     static class CheckedCollection<E> implements Collection<E>, Serializable {
       
  3086         @java.io.Serial
  3039         private static final long serialVersionUID = 1578914078182001775L;
  3087         private static final long serialVersionUID = 1578914078182001775L;
  3040 
  3088 
       
  3089         @SuppressWarnings("serial") // Conditionally serializable
  3041         final Collection<E> c;
  3090         final Collection<E> c;
       
  3091         @SuppressWarnings("serial") // Conditionally serializable
  3042         final Class<E> type;
  3092         final Class<E> type;
  3043 
  3093 
  3044         @SuppressWarnings("unchecked")
  3094         @SuppressWarnings("unchecked")
  3045         E typeCheck(Object o) {
  3095         E typeCheck(Object o) {
  3046             if (o != null && !type.isInstance(o))
  3096             if (o != null && !type.isInstance(o))
  3092             };
  3142             };
  3093         }
  3143         }
  3094 
  3144 
  3095         public boolean add(E e)          { return c.add(typeCheck(e)); }
  3145         public boolean add(E e)          { return c.add(typeCheck(e)); }
  3096 
  3146 
       
  3147         @SuppressWarnings("serial") // Conditionally serializable
  3097         private E[] zeroLengthElementArray; // Lazily initialized
  3148         private E[] zeroLengthElementArray; // Lazily initialized
  3098 
  3149 
  3099         private E[] zeroLengthElementArray() {
  3150         private E[] zeroLengthElementArray() {
  3100             return zeroLengthElementArray != null ? zeroLengthElementArray :
  3151             return zeroLengthElementArray != null ? zeroLengthElementArray :
  3101                 (zeroLengthElementArray = zeroLengthArray(type));
  3152                 (zeroLengthElementArray = zeroLengthArray(type));
  3183      */
  3234      */
  3184     static class CheckedQueue<E>
  3235     static class CheckedQueue<E>
  3185         extends CheckedCollection<E>
  3236         extends CheckedCollection<E>
  3186         implements Queue<E>, Serializable
  3237         implements Queue<E>, Serializable
  3187     {
  3238     {
       
  3239         @java.io.Serial
  3188         private static final long serialVersionUID = 1433151992604707767L;
  3240         private static final long serialVersionUID = 1433151992604707767L;
       
  3241         @SuppressWarnings("serial") // Conditionally serializable
  3189         final Queue<E> queue;
  3242         final Queue<E> queue;
  3190 
  3243 
  3191         CheckedQueue(Queue<E> queue, Class<E> elementType) {
  3244         CheckedQueue(Queue<E> queue, Class<E> elementType) {
  3192             super(queue, elementType);
  3245             super(queue, elementType);
  3193             this.queue = queue;
  3246             this.queue = queue;
  3237      * @serial include
  3290      * @serial include
  3238      */
  3291      */
  3239     static class CheckedSet<E> extends CheckedCollection<E>
  3292     static class CheckedSet<E> extends CheckedCollection<E>
  3240                                  implements Set<E>, Serializable
  3293                                  implements Set<E>, Serializable
  3241     {
  3294     {
       
  3295         @java.io.Serial
  3242         private static final long serialVersionUID = 4694047833775013803L;
  3296         private static final long serialVersionUID = 4694047833775013803L;
  3243 
  3297 
  3244         CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
  3298         CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
  3245 
  3299 
  3246         public boolean equals(Object o) { return o == this || c.equals(o); }
  3300         public boolean equals(Object o) { return o == this || c.equals(o); }
  3284      * @serial include
  3338      * @serial include
  3285      */
  3339      */
  3286     static class CheckedSortedSet<E> extends CheckedSet<E>
  3340     static class CheckedSortedSet<E> extends CheckedSet<E>
  3287         implements SortedSet<E>, Serializable
  3341         implements SortedSet<E>, Serializable
  3288     {
  3342     {
       
  3343         @java.io.Serial
  3289         private static final long serialVersionUID = 1599911165492914959L;
  3344         private static final long serialVersionUID = 1599911165492914959L;
  3290 
  3345 
       
  3346         @SuppressWarnings("serial") // Conditionally serializable
  3291         private final SortedSet<E> ss;
  3347         private final SortedSet<E> ss;
  3292 
  3348 
  3293         CheckedSortedSet(SortedSet<E> s, Class<E> type) {
  3349         CheckedSortedSet(SortedSet<E> s, Class<E> type) {
  3294             super(s, type);
  3350             super(s, type);
  3295             ss = s;
  3351             ss = s;
  3347      * @serial include
  3403      * @serial include
  3348      */
  3404      */
  3349     static class CheckedNavigableSet<E> extends CheckedSortedSet<E>
  3405     static class CheckedNavigableSet<E> extends CheckedSortedSet<E>
  3350         implements NavigableSet<E>, Serializable
  3406         implements NavigableSet<E>, Serializable
  3351     {
  3407     {
       
  3408         @java.io.Serial
  3352         private static final long serialVersionUID = -5429120189805438922L;
  3409         private static final long serialVersionUID = -5429120189805438922L;
  3353 
  3410 
       
  3411         @SuppressWarnings("serial") // Conditionally serializable
  3354         private final NavigableSet<E> ns;
  3412         private final NavigableSet<E> ns;
  3355 
  3413 
  3356         CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
  3414         CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
  3357             super(s, type);
  3415             super(s, type);
  3358             ns = s;
  3416             ns = s;
  3430      */
  3488      */
  3431     static class CheckedList<E>
  3489     static class CheckedList<E>
  3432         extends CheckedCollection<E>
  3490         extends CheckedCollection<E>
  3433         implements List<E>
  3491         implements List<E>
  3434     {
  3492     {
       
  3493         @java.io.Serial
  3435         private static final long serialVersionUID = 65247728283967356L;
  3494         private static final long serialVersionUID = 65247728283967356L;
       
  3495         @SuppressWarnings("serial") // Conditionally serializable
  3436         final List<E> list;
  3496         final List<E> list;
  3437 
  3497 
  3438         CheckedList(List<E> list, Class<E> type) {
  3498         CheckedList(List<E> list, Class<E> type) {
  3439             super(list, type);
  3499             super(list, type);
  3440             this.list = list;
  3500             this.list = list;
  3515      * @serial include
  3575      * @serial include
  3516      */
  3576      */
  3517     static class CheckedRandomAccessList<E> extends CheckedList<E>
  3577     static class CheckedRandomAccessList<E> extends CheckedList<E>
  3518                                             implements RandomAccess
  3578                                             implements RandomAccess
  3519     {
  3579     {
       
  3580         @java.io.Serial
  3520         private static final long serialVersionUID = 1638200125423088369L;
  3581         private static final long serialVersionUID = 1638200125423088369L;
  3521 
  3582 
  3522         CheckedRandomAccessList(List<E> list, Class<E> type) {
  3583         CheckedRandomAccessList(List<E> list, Class<E> type) {
  3523             super(list, type);
  3584             super(list, type);
  3524         }
  3585         }
  3576      * @serial include
  3637      * @serial include
  3577      */
  3638      */
  3578     private static class CheckedMap<K,V>
  3639     private static class CheckedMap<K,V>
  3579         implements Map<K,V>, Serializable
  3640         implements Map<K,V>, Serializable
  3580     {
  3641     {
       
  3642         @java.io.Serial
  3581         private static final long serialVersionUID = 5742860141034234728L;
  3643         private static final long serialVersionUID = 5742860141034234728L;
  3582 
  3644 
       
  3645         @SuppressWarnings("serial") // Conditionally serializable
  3583         private final Map<K, V> m;
  3646         private final Map<K, V> m;
       
  3647         @SuppressWarnings("serial") // Conditionally serializable
  3584         final Class<K> keyType;
  3648         final Class<K> keyType;
       
  3649         @SuppressWarnings("serial") // Conditionally serializable
  3585         final Class<V> valueType;
  3650         final Class<V> valueType;
  3586 
  3651 
  3587         private void typeCheck(Object key, Object value) {
  3652         private void typeCheck(Object key, Object value) {
  3588             if (key != null && !keyType.isInstance(key))
  3653             if (key != null && !keyType.isInstance(key))
  3589                 throw new ClassCastException(badKeyMsg(key));
  3654                 throw new ClassCastException(badKeyMsg(key));
  3975      * @serial include
  4040      * @serial include
  3976      */
  4041      */
  3977     static class CheckedSortedMap<K,V> extends CheckedMap<K,V>
  4042     static class CheckedSortedMap<K,V> extends CheckedMap<K,V>
  3978         implements SortedMap<K,V>, Serializable
  4043         implements SortedMap<K,V>, Serializable
  3979     {
  4044     {
       
  4045         @java.io.Serial
  3980         private static final long serialVersionUID = 1599671320688067438L;
  4046         private static final long serialVersionUID = 1599671320688067438L;
  3981 
  4047 
       
  4048         @SuppressWarnings("serial") // Conditionally serializable
  3982         private final SortedMap<K, V> sm;
  4049         private final SortedMap<K, V> sm;
  3983 
  4050 
  3984         CheckedSortedMap(SortedMap<K, V> m,
  4051         CheckedSortedMap(SortedMap<K, V> m,
  3985                          Class<K> keyType, Class<V> valueType) {
  4052                          Class<K> keyType, Class<V> valueType) {
  3986             super(m, keyType, valueType);
  4053             super(m, keyType, valueType);
  4049      * @serial include
  4116      * @serial include
  4050      */
  4117      */
  4051     static class CheckedNavigableMap<K,V> extends CheckedSortedMap<K,V>
  4118     static class CheckedNavigableMap<K,V> extends CheckedSortedMap<K,V>
  4052         implements NavigableMap<K,V>, Serializable
  4119         implements NavigableMap<K,V>, Serializable
  4053     {
  4120     {
       
  4121         @java.io.Serial
  4054         private static final long serialVersionUID = -4852462692372534096L;
  4122         private static final long serialVersionUID = -4852462692372534096L;
  4055 
  4123 
       
  4124         @SuppressWarnings("serial") // Conditionally serializable
  4056         private final NavigableMap<K, V> nm;
  4125         private final NavigableMap<K, V> nm;
  4057 
  4126 
  4058         CheckedNavigableMap(NavigableMap<K, V> m,
  4127         CheckedNavigableMap(NavigableMap<K, V> m,
  4059                          Class<K> keyType, Class<V> valueType) {
  4128                          Class<K> keyType, Class<V> valueType) {
  4060             super(m, keyType, valueType);
  4129             super(m, keyType, valueType);
  4327      */
  4396      */
  4328     private static class EmptySet<E>
  4397     private static class EmptySet<E>
  4329         extends AbstractSet<E>
  4398         extends AbstractSet<E>
  4330         implements Serializable
  4399         implements Serializable
  4331     {
  4400     {
       
  4401         @java.io.Serial
  4332         private static final long serialVersionUID = 1582296315990362920L;
  4402         private static final long serialVersionUID = 1582296315990362920L;
  4333 
  4403 
  4334         public Iterator<E> iterator() { return emptyIterator(); }
  4404         public Iterator<E> iterator() { return emptyIterator(); }
  4335 
  4405 
  4336         public int size() {return 0;}
  4406         public int size() {return 0;}
  4360         }
  4430         }
  4361         @Override
  4431         @Override
  4362         public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
  4432         public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
  4363 
  4433 
  4364         // Preserves singleton property
  4434         // Preserves singleton property
       
  4435         @java.io.Serial
  4365         private Object readResolve() {
  4436         private Object readResolve() {
  4366             return EMPTY_SET;
  4437             return EMPTY_SET;
  4367         }
  4438         }
  4368 
  4439 
  4369         @Override
  4440         @Override
  4451      * @serial include
  4522      * @serial include
  4452      */
  4523      */
  4453     private static class EmptyList<E>
  4524     private static class EmptyList<E>
  4454         extends AbstractList<E>
  4525         extends AbstractList<E>
  4455         implements RandomAccess, Serializable {
  4526         implements RandomAccess, Serializable {
       
  4527         @java.io.Serial
  4456         private static final long serialVersionUID = 8842843931221139166L;
  4528         private static final long serialVersionUID = 8842843931221139166L;
  4457 
  4529 
  4458         public Iterator<E> iterator() {
  4530         public Iterator<E> iterator() {
  4459             return emptyIterator();
  4531             return emptyIterator();
  4460         }
  4532         }
  4508 
  4580 
  4509         @Override
  4581         @Override
  4510         public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
  4582         public Spliterator<E> spliterator() { return Spliterators.emptySpliterator(); }
  4511 
  4583 
  4512         // Preserves singleton property
  4584         // Preserves singleton property
       
  4585         @java.io.Serial
  4513         private Object readResolve() {
  4586         private Object readResolve() {
  4514             return EMPTY_LIST;
  4587             return EMPTY_LIST;
  4515         }
  4588         }
  4516     }
  4589     }
  4517 
  4590 
  4594      */
  4667      */
  4595     private static class EmptyMap<K,V>
  4668     private static class EmptyMap<K,V>
  4596         extends AbstractMap<K,V>
  4669         extends AbstractMap<K,V>
  4597         implements Serializable
  4670         implements Serializable
  4598     {
  4671     {
       
  4672         @java.io.Serial
  4599         private static final long serialVersionUID = 6428348081105594320L;
  4673         private static final long serialVersionUID = 6428348081105594320L;
  4600 
  4674 
  4601         public int size()                          {return 0;}
  4675         public int size()                          {return 0;}
  4602         public boolean isEmpty()                   {return true;}
  4676         public boolean isEmpty()                   {return true;}
  4603         public void clear()                        {}
  4677         public void clear()                        {}
  4674                 BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  4748                 BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  4675             throw new UnsupportedOperationException();
  4749             throw new UnsupportedOperationException();
  4676         }
  4750         }
  4677 
  4751 
  4678         // Preserves singleton property
  4752         // Preserves singleton property
       
  4753         @java.io.Serial
  4679         private Object readResolve() {
  4754         private Object readResolve() {
  4680             return EMPTY_MAP;
  4755             return EMPTY_MAP;
  4681         }
  4756         }
  4682     }
  4757     }
  4683 
  4758 
  4773      */
  4848      */
  4774     private static class SingletonSet<E>
  4849     private static class SingletonSet<E>
  4775         extends AbstractSet<E>
  4850         extends AbstractSet<E>
  4776         implements Serializable
  4851         implements Serializable
  4777     {
  4852     {
       
  4853         @java.io.Serial
  4778         private static final long serialVersionUID = 3193687207550431679L;
  4854         private static final long serialVersionUID = 3193687207550431679L;
  4779 
  4855 
       
  4856         @SuppressWarnings("serial") // Conditionally serializable
  4780         private final E element;
  4857         private final E element;
  4781 
  4858 
  4782         SingletonSet(E e) {element = e;}
  4859         SingletonSet(E e) {element = e;}
  4783 
  4860 
  4784         public Iterator<E> iterator() {
  4861         public Iterator<E> iterator() {
  4826      */
  4903      */
  4827     private static class SingletonList<E>
  4904     private static class SingletonList<E>
  4828         extends AbstractList<E>
  4905         extends AbstractList<E>
  4829         implements RandomAccess, Serializable {
  4906         implements RandomAccess, Serializable {
  4830 
  4907 
       
  4908         @java.io.Serial
  4831         private static final long serialVersionUID = 3093736618740652951L;
  4909         private static final long serialVersionUID = 3093736618740652951L;
  4832 
  4910 
       
  4911         @SuppressWarnings("serial") // Conditionally serializable
  4833         private final E element;
  4912         private final E element;
  4834 
  4913 
  4835         SingletonList(E obj)                {element = obj;}
  4914         SingletonList(E obj)                {element = obj;}
  4836 
  4915 
  4837         public Iterator<E> iterator() {
  4916         public Iterator<E> iterator() {
  4894      * @serial include
  4973      * @serial include
  4895      */
  4974      */
  4896     private static class SingletonMap<K,V>
  4975     private static class SingletonMap<K,V>
  4897           extends AbstractMap<K,V>
  4976           extends AbstractMap<K,V>
  4898           implements Serializable {
  4977           implements Serializable {
       
  4978         @java.io.Serial
  4899         private static final long serialVersionUID = -6979724477215052911L;
  4979         private static final long serialVersionUID = -6979724477215052911L;
  4900 
  4980 
       
  4981         @SuppressWarnings("serial") // Conditionally serializable
  4901         private final K k;
  4982         private final K k;
       
  4983         @SuppressWarnings("serial") // Conditionally serializable
  4902         private final V v;
  4984         private final V v;
  4903 
  4985 
  4904         SingletonMap(K key, V value) {
  4986         SingletonMap(K key, V value) {
  4905             k = key;
  4987             k = key;
  4906             v = value;
  4988             v = value;
  5031      */
  5113      */
  5032     private static class CopiesList<E>
  5114     private static class CopiesList<E>
  5033         extends AbstractList<E>
  5115         extends AbstractList<E>
  5034         implements RandomAccess, Serializable
  5116         implements RandomAccess, Serializable
  5035     {
  5117     {
       
  5118         @java.io.Serial
  5036         private static final long serialVersionUID = 2739099268398711800L;
  5119         private static final long serialVersionUID = 2739099268398711800L;
  5037 
  5120 
  5038         final int n;
  5121         final int n;
       
  5122         @SuppressWarnings("serial") // Conditionally serializable
  5039         final E element;
  5123         final E element;
  5040 
  5124 
  5041         CopiesList(int n, E e) {
  5125         CopiesList(int n, E e) {
  5042             assert n >= 0;
  5126             assert n >= 0;
  5043             this.n = n;
  5127             this.n = n;
  5161 
  5245 
  5162         @Override
  5246         @Override
  5163         public Spliterator<E> spliterator() {
  5247         public Spliterator<E> spliterator() {
  5164             return stream().spliterator();
  5248             return stream().spliterator();
  5165         }
  5249         }
       
  5250 
       
  5251         @java.io.Serial
       
  5252         private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
       
  5253             ois.defaultReadObject();
       
  5254             SharedSecrets.getJavaObjectInputStreamAccess().checkArray(ois, Object[].class, n);
       
  5255         }
  5166     }
  5256     }
  5167 
  5257 
  5168     /**
  5258     /**
  5169      * Returns a comparator that imposes the reverse of the <em>natural
  5259      * Returns a comparator that imposes the reverse of the <em>natural
  5170      * ordering</em> on a collection of objects that implement the
  5260      * ordering</em> on a collection of objects that implement the
  5194      * @serial include
  5284      * @serial include
  5195      */
  5285      */
  5196     private static class ReverseComparator
  5286     private static class ReverseComparator
  5197         implements Comparator<Comparable<Object>>, Serializable {
  5287         implements Comparator<Comparable<Object>>, Serializable {
  5198 
  5288 
       
  5289         @java.io.Serial
  5199         private static final long serialVersionUID = 7207038068494060240L;
  5290         private static final long serialVersionUID = 7207038068494060240L;
  5200 
  5291 
  5201         static final ReverseComparator REVERSE_ORDER
  5292         static final ReverseComparator REVERSE_ORDER
  5202             = new ReverseComparator();
  5293             = new ReverseComparator();
  5203 
  5294 
  5204         public int compare(Comparable<Object> c1, Comparable<Object> c2) {
  5295         public int compare(Comparable<Object> c1, Comparable<Object> c2) {
  5205             return c2.compareTo(c1);
  5296             return c2.compareTo(c1);
  5206         }
  5297         }
  5207 
  5298 
       
  5299         @java.io.Serial
  5208         private Object readResolve() { return Collections.reverseOrder(); }
  5300         private Object readResolve() { return Collections.reverseOrder(); }
  5209 
  5301 
  5210         @Override
  5302         @Override
  5211         public Comparator<Comparable<Object>> reversed() {
  5303         public Comparator<Comparable<Object>> reversed() {
  5212             return Comparator.naturalOrder();
  5304             return Comparator.naturalOrder();
  5249      * @serial include
  5341      * @serial include
  5250      */
  5342      */
  5251     private static class ReverseComparator2<T> implements Comparator<T>,
  5343     private static class ReverseComparator2<T> implements Comparator<T>,
  5252         Serializable
  5344         Serializable
  5253     {
  5345     {
       
  5346         @java.io.Serial
  5254         private static final long serialVersionUID = 4374092139857L;
  5347         private static final long serialVersionUID = 4374092139857L;
  5255 
  5348 
  5256         /**
  5349         /**
  5257          * The comparator specified in the static factory.  This will never
  5350          * The comparator specified in the static factory.  This will never
  5258          * be null, as the static factory returns a ReverseComparator
  5351          * be null, as the static factory returns a ReverseComparator
  5259          * instance if its argument is null.
  5352          * instance if its argument is null.
  5260          *
  5353          *
  5261          * @serial
  5354          * @serial
  5262          */
  5355          */
       
  5356         @SuppressWarnings("serial") // Conditionally serializable
  5263         final Comparator<T> cmp;
  5357         final Comparator<T> cmp;
  5264 
  5358 
  5265         ReverseComparator2(Comparator<T> cmp) {
  5359         ReverseComparator2(Comparator<T> cmp) {
  5266             assert cmp != null;
  5360             assert cmp != null;
  5267             this.cmp = cmp;
  5361             this.cmp = cmp;
  5539      * @serial include
  5633      * @serial include
  5540      */
  5634      */
  5541     private static class SetFromMap<E> extends AbstractSet<E>
  5635     private static class SetFromMap<E> extends AbstractSet<E>
  5542         implements Set<E>, Serializable
  5636         implements Set<E>, Serializable
  5543     {
  5637     {
       
  5638         @SuppressWarnings("serial") // Conditionally serializable
  5544         private final Map<E, Boolean> m;  // The backing map
  5639         private final Map<E, Boolean> m;  // The backing map
  5545         private transient Set<E> s;       // Its keySet
  5640         private transient Set<E> s;       // Its keySet
  5546 
  5641 
  5547         SetFromMap(Map<E, Boolean> map) {
  5642         SetFromMap(Map<E, Boolean> map) {
  5548             if (!map.isEmpty())
  5643             if (!map.isEmpty())
  5583         @Override
  5678         @Override
  5584         public Stream<E> stream()           {return s.stream();}
  5679         public Stream<E> stream()           {return s.stream();}
  5585         @Override
  5680         @Override
  5586         public Stream<E> parallelStream()   {return s.parallelStream();}
  5681         public Stream<E> parallelStream()   {return s.parallelStream();}
  5587 
  5682 
       
  5683         @java.io.Serial
  5588         private static final long serialVersionUID = 2454657854757543876L;
  5684         private static final long serialVersionUID = 2454657854757543876L;
  5589 
  5685 
       
  5686         @java.io.Serial
  5590         private void readObject(java.io.ObjectInputStream stream)
  5687         private void readObject(java.io.ObjectInputStream stream)
  5591             throws IOException, ClassNotFoundException
  5688             throws IOException, ClassNotFoundException
  5592         {
  5689         {
  5593             stream.defaultReadObject();
  5690             stream.defaultReadObject();
  5594             s = m.keySet();
  5691             s = m.keySet();
  5620     /**
  5717     /**
  5621      * @serial include
  5718      * @serial include
  5622      */
  5719      */
  5623     static class AsLIFOQueue<E> extends AbstractQueue<E>
  5720     static class AsLIFOQueue<E> extends AbstractQueue<E>
  5624         implements Queue<E>, Serializable {
  5721         implements Queue<E>, Serializable {
       
  5722         @java.io.Serial
  5625         private static final long serialVersionUID = 1802017725587941708L;
  5723         private static final long serialVersionUID = 1802017725587941708L;
       
  5724         @SuppressWarnings("serial") // Conditionally serializable
  5626         private final Deque<E> q;
  5725         private final Deque<E> q;
  5627         AsLIFOQueue(Deque<E> q)                     { this.q = q; }
  5726         AsLIFOQueue(Deque<E> q)                     { this.q = q; }
  5628         public boolean add(E e)                     { q.addFirst(e); return true; }
  5727         public boolean add(E e)                     { q.addFirst(e); return true; }
  5629         public boolean offer(E e)                   { return q.offerFirst(e); }
  5728         public boolean offer(E e)                   { return q.offerFirst(e); }
  5630         public E poll()                             { return q.pollFirst(); }
  5729         public E poll()                             { return q.pollFirst(); }