src/java.base/share/classes/java/util/Collections.java
changeset 58520 e036ee8bae56
parent 57956 e0b8b019d2f5
child 58679 9c3209ff7550
equal deleted inserted replaced
58519:6e017b301287 58520:e036ee8bae56
  1022      */
  1022      */
  1023     static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
  1023     static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
  1024         @java.io.Serial
  1024         @java.io.Serial
  1025         private static final long serialVersionUID = 1820017752578914078L;
  1025         private static final long serialVersionUID = 1820017752578914078L;
  1026 
  1026 
       
  1027         @SuppressWarnings("serial") // Conditionally serializable
  1027         final Collection<? extends E> c;
  1028         final Collection<? extends E> c;
  1028 
  1029 
  1029         UnmodifiableCollection(Collection<? extends E> c) {
  1030         UnmodifiableCollection(Collection<? extends E> c) {
  1030             if (c==null)
  1031             if (c==null)
  1031                 throw new NullPointerException();
  1032                 throw new NullPointerException();
  1162     static class UnmodifiableSortedSet<E>
  1163     static class UnmodifiableSortedSet<E>
  1163                              extends UnmodifiableSet<E>
  1164                              extends UnmodifiableSet<E>
  1164                              implements SortedSet<E>, Serializable {
  1165                              implements SortedSet<E>, Serializable {
  1165         @java.io.Serial
  1166         @java.io.Serial
  1166         private static final long serialVersionUID = -4929149591599911165L;
  1167         private static final long serialVersionUID = -4929149591599911165L;
       
  1168         @SuppressWarnings("serial") // Conditionally serializable
  1167         private final SortedSet<E> ss;
  1169         private final SortedSet<E> ss;
  1168 
  1170 
  1169         UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
  1171         UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
  1170 
  1172 
  1171         public Comparator<? super E> comparator() {return ss.comparator();}
  1173         public Comparator<? super E> comparator() {return ss.comparator();}
  1242                 new EmptyNavigableSet<>();
  1244                 new EmptyNavigableSet<>();
  1243 
  1245 
  1244         /**
  1246         /**
  1245          * The instance we are protecting.
  1247          * The instance we are protecting.
  1246          */
  1248          */
       
  1249         @SuppressWarnings("serial") // Conditionally serializable
  1247         private final NavigableSet<E> ns;
  1250         private final NavigableSet<E> ns;
  1248 
  1251 
  1249         UnmodifiableNavigableSet(NavigableSet<E> s)         {super(s); ns = s;}
  1252         UnmodifiableNavigableSet(NavigableSet<E> s)         {super(s); ns = s;}
  1250 
  1253 
  1251         public E lower(E e)                             { return ns.lower(e); }
  1254         public E lower(E e)                             { return ns.lower(e); }
  1302     static class UnmodifiableList<E> extends UnmodifiableCollection<E>
  1305     static class UnmodifiableList<E> extends UnmodifiableCollection<E>
  1303                                   implements List<E> {
  1306                                   implements List<E> {
  1304         @java.io.Serial
  1307         @java.io.Serial
  1305         private static final long serialVersionUID = -283967356065247728L;
  1308         private static final long serialVersionUID = -283967356065247728L;
  1306 
  1309 
       
  1310         @SuppressWarnings("serial") // Conditionally serializable
  1307         final List<? extends E> list;
  1311         final List<? extends E> list;
  1308 
  1312 
  1309         UnmodifiableList(List<? extends E> list) {
  1313         UnmodifiableList(List<? extends E> list) {
  1310             super(list);
  1314             super(list);
  1311             this.list = list;
  1315             this.list = list;
  1448      */
  1452      */
  1449     private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
  1453     private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
  1450         @java.io.Serial
  1454         @java.io.Serial
  1451         private static final long serialVersionUID = -1034234728574286014L;
  1455         private static final long serialVersionUID = -1034234728574286014L;
  1452 
  1456 
       
  1457         @SuppressWarnings("serial") // Conditionally serializable
  1453         private final Map<? extends K, ? extends V> m;
  1458         private final Map<? extends K, ? extends V> m;
  1454 
  1459 
  1455         UnmodifiableMap(Map<? extends K, ? extends V> m) {
  1460         UnmodifiableMap(Map<? extends K, ? extends V> m) {
  1456             if (m==null)
  1461             if (m==null)
  1457                 throw new NullPointerException();
  1462                 throw new NullPointerException();
  1807           extends UnmodifiableMap<K,V>
  1812           extends UnmodifiableMap<K,V>
  1808           implements SortedMap<K,V>, Serializable {
  1813           implements SortedMap<K,V>, Serializable {
  1809         @java.io.Serial
  1814         @java.io.Serial
  1810         private static final long serialVersionUID = -8806743815996713206L;
  1815         private static final long serialVersionUID = -8806743815996713206L;
  1811 
  1816 
       
  1817         @SuppressWarnings("serial") // Conditionally serializable
  1812         private final SortedMap<K, ? extends V> sm;
  1818         private final SortedMap<K, ? extends V> sm;
  1813 
  1819 
  1814         UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
  1820         UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
  1815         public Comparator<? super K> comparator()   { return sm.comparator(); }
  1821         public Comparator<? super K> comparator()   { return sm.comparator(); }
  1816         public SortedMap<K,V> subMap(K fromKey, K toKey)
  1822         public SortedMap<K,V> subMap(K fromKey, K toKey)
  1884             new EmptyNavigableMap<>();
  1890             new EmptyNavigableMap<>();
  1885 
  1891 
  1886         /**
  1892         /**
  1887          * The instance we wrap and protect.
  1893          * The instance we wrap and protect.
  1888          */
  1894          */
       
  1895         @SuppressWarnings("serial") // Conditionally serializable
  1889         private final NavigableMap<K, ? extends V> nm;
  1896         private final NavigableMap<K, ? extends V> nm;
  1890 
  1897 
  1891         UnmodifiableNavigableMap(NavigableMap<K, ? extends V> m)
  1898         UnmodifiableNavigableMap(NavigableMap<K, ? extends V> m)
  1892                                                             {super(m); nm = m;}
  1899                                                             {super(m); nm = m;}
  1893 
  1900 
  2015      */
  2022      */
  2016     static class SynchronizedCollection<E> implements Collection<E>, Serializable {
  2023     static class SynchronizedCollection<E> implements Collection<E>, Serializable {
  2017         @java.io.Serial
  2024         @java.io.Serial
  2018         private static final long serialVersionUID = 3053995032091335093L;
  2025         private static final long serialVersionUID = 3053995032091335093L;
  2019 
  2026 
       
  2027         @SuppressWarnings("serial") // Conditionally serializable
  2020         final Collection<E> c;  // Backing Collection
  2028         final Collection<E> c;  // Backing Collection
       
  2029         @SuppressWarnings("serial") // Conditionally serializable
  2021         final Object mutex;     // Object on which to synchronize
  2030         final Object mutex;     // Object on which to synchronize
  2022 
  2031 
  2023         SynchronizedCollection(Collection<E> c) {
  2032         SynchronizedCollection(Collection<E> c) {
  2024             this.c = Objects.requireNonNull(c);
  2033             this.c = Objects.requireNonNull(c);
  2025             mutex = this;
  2034             mutex = this;
  2217         implements SortedSet<E>
  2226         implements SortedSet<E>
  2218     {
  2227     {
  2219         @java.io.Serial
  2228         @java.io.Serial
  2220         private static final long serialVersionUID = 8695801310862127406L;
  2229         private static final long serialVersionUID = 8695801310862127406L;
  2221 
  2230 
       
  2231         @SuppressWarnings("serial") // Conditionally serializable
  2222         private final SortedSet<E> ss;
  2232         private final SortedSet<E> ss;
  2223 
  2233 
  2224         SynchronizedSortedSet(SortedSet<E> s) {
  2234         SynchronizedSortedSet(SortedSet<E> s) {
  2225             super(s);
  2235             super(s);
  2226             ss = s;
  2236             ss = s;
  2312         implements NavigableSet<E>
  2322         implements NavigableSet<E>
  2313     {
  2323     {
  2314         @java.io.Serial
  2324         @java.io.Serial
  2315         private static final long serialVersionUID = -5505529816273629798L;
  2325         private static final long serialVersionUID = -5505529816273629798L;
  2316 
  2326 
       
  2327         @SuppressWarnings("serial") // Conditionally serializable
  2317         private final NavigableSet<E> ns;
  2328         private final NavigableSet<E> ns;
  2318 
  2329 
  2319         SynchronizedNavigableSet(NavigableSet<E> s) {
  2330         SynchronizedNavigableSet(NavigableSet<E> s) {
  2320             super(s);
  2331             super(s);
  2321             ns = s;
  2332             ns = s;
  2422         extends SynchronizedCollection<E>
  2433         extends SynchronizedCollection<E>
  2423         implements List<E> {
  2434         implements List<E> {
  2424         @java.io.Serial
  2435         @java.io.Serial
  2425         private static final long serialVersionUID = -7754090372962971524L;
  2436         private static final long serialVersionUID = -7754090372962971524L;
  2426 
  2437 
       
  2438         @SuppressWarnings("serial") // Conditionally serializable
  2427         final List<E> list;
  2439         final List<E> list;
  2428 
  2440 
  2429         SynchronizedList(List<E> list) {
  2441         SynchronizedList(List<E> list) {
  2430             super(list);
  2442             super(list);
  2431             this.list = list;
  2443             this.list = list;
  2589     private static class SynchronizedMap<K,V>
  2601     private static class SynchronizedMap<K,V>
  2590         implements Map<K,V>, Serializable {
  2602         implements Map<K,V>, Serializable {
  2591         @java.io.Serial
  2603         @java.io.Serial
  2592         private static final long serialVersionUID = 1978198479659022715L;
  2604         private static final long serialVersionUID = 1978198479659022715L;
  2593 
  2605 
       
  2606         @SuppressWarnings("serial") // Conditionally serializable
  2594         private final Map<K,V> m;     // Backing Map
  2607         private final Map<K,V> m;     // Backing Map
       
  2608         @SuppressWarnings("serial") // Conditionally serializable
  2595         final Object      mutex;        // Object on which to synchronize
  2609         final Object      mutex;        // Object on which to synchronize
  2596 
  2610 
  2597         SynchronizedMap(Map<K,V> m) {
  2611         SynchronizedMap(Map<K,V> m) {
  2598             this.m = Objects.requireNonNull(m);
  2612             this.m = Objects.requireNonNull(m);
  2599             mutex = this;
  2613             mutex = this;
  2786         implements SortedMap<K,V>
  2800         implements SortedMap<K,V>
  2787     {
  2801     {
  2788         @java.io.Serial
  2802         @java.io.Serial
  2789         private static final long serialVersionUID = -8798146769416483793L;
  2803         private static final long serialVersionUID = -8798146769416483793L;
  2790 
  2804 
       
  2805         @SuppressWarnings("serial") // Conditionally serializable
  2791         private final SortedMap<K,V> sm;
  2806         private final SortedMap<K,V> sm;
  2792 
  2807 
  2793         SynchronizedSortedMap(SortedMap<K,V> m) {
  2808         SynchronizedSortedMap(SortedMap<K,V> m) {
  2794             super(m);
  2809             super(m);
  2795             sm = m;
  2810             sm = m;
  2889         implements NavigableMap<K,V>
  2904         implements NavigableMap<K,V>
  2890     {
  2905     {
  2891         @java.io.Serial
  2906         @java.io.Serial
  2892         private static final long serialVersionUID = 699392247599746807L;
  2907         private static final long serialVersionUID = 699392247599746807L;
  2893 
  2908 
       
  2909         @SuppressWarnings("serial") // Conditionally serializable
  2894         private final NavigableMap<K,V> nm;
  2910         private final NavigableMap<K,V> nm;
  2895 
  2911 
  2896         SynchronizedNavigableMap(NavigableMap<K,V> m) {
  2912         SynchronizedNavigableMap(NavigableMap<K,V> m) {
  2897             super(m);
  2913             super(m);
  2898             nm = m;
  2914             nm = m;
  3068      */
  3084      */
  3069     static class CheckedCollection<E> implements Collection<E>, Serializable {
  3085     static class CheckedCollection<E> implements Collection<E>, Serializable {
  3070         @java.io.Serial
  3086         @java.io.Serial
  3071         private static final long serialVersionUID = 1578914078182001775L;
  3087         private static final long serialVersionUID = 1578914078182001775L;
  3072 
  3088 
       
  3089         @SuppressWarnings("serial") // Conditionally serializable
  3073         final Collection<E> c;
  3090         final Collection<E> c;
       
  3091         @SuppressWarnings("serial") // Conditionally serializable
  3074         final Class<E> type;
  3092         final Class<E> type;
  3075 
  3093 
  3076         @SuppressWarnings("unchecked")
  3094         @SuppressWarnings("unchecked")
  3077         E typeCheck(Object o) {
  3095         E typeCheck(Object o) {
  3078             if (o != null && !type.isInstance(o))
  3096             if (o != null && !type.isInstance(o))
  3124             };
  3142             };
  3125         }
  3143         }
  3126 
  3144 
  3127         public boolean add(E e)          { return c.add(typeCheck(e)); }
  3145         public boolean add(E e)          { return c.add(typeCheck(e)); }
  3128 
  3146 
       
  3147         @SuppressWarnings("serial") // Conditionally serializable
  3129         private E[] zeroLengthElementArray; // Lazily initialized
  3148         private E[] zeroLengthElementArray; // Lazily initialized
  3130 
  3149 
  3131         private E[] zeroLengthElementArray() {
  3150         private E[] zeroLengthElementArray() {
  3132             return zeroLengthElementArray != null ? zeroLengthElementArray :
  3151             return zeroLengthElementArray != null ? zeroLengthElementArray :
  3133                 (zeroLengthElementArray = zeroLengthArray(type));
  3152                 (zeroLengthElementArray = zeroLengthArray(type));
  3217         extends CheckedCollection<E>
  3236         extends CheckedCollection<E>
  3218         implements Queue<E>, Serializable
  3237         implements Queue<E>, Serializable
  3219     {
  3238     {
  3220         @java.io.Serial
  3239         @java.io.Serial
  3221         private static final long serialVersionUID = 1433151992604707767L;
  3240         private static final long serialVersionUID = 1433151992604707767L;
       
  3241         @SuppressWarnings("serial") // Conditionally serializable
  3222         final Queue<E> queue;
  3242         final Queue<E> queue;
  3223 
  3243 
  3224         CheckedQueue(Queue<E> queue, Class<E> elementType) {
  3244         CheckedQueue(Queue<E> queue, Class<E> elementType) {
  3225             super(queue, elementType);
  3245             super(queue, elementType);
  3226             this.queue = queue;
  3246             this.queue = queue;
  3321         implements SortedSet<E>, Serializable
  3341         implements SortedSet<E>, Serializable
  3322     {
  3342     {
  3323         @java.io.Serial
  3343         @java.io.Serial
  3324         private static final long serialVersionUID = 1599911165492914959L;
  3344         private static final long serialVersionUID = 1599911165492914959L;
  3325 
  3345 
       
  3346         @SuppressWarnings("serial") // Conditionally serializable
  3326         private final SortedSet<E> ss;
  3347         private final SortedSet<E> ss;
  3327 
  3348 
  3328         CheckedSortedSet(SortedSet<E> s, Class<E> type) {
  3349         CheckedSortedSet(SortedSet<E> s, Class<E> type) {
  3329             super(s, type);
  3350             super(s, type);
  3330             ss = s;
  3351             ss = s;
  3385         implements NavigableSet<E>, Serializable
  3406         implements NavigableSet<E>, Serializable
  3386     {
  3407     {
  3387         @java.io.Serial
  3408         @java.io.Serial
  3388         private static final long serialVersionUID = -5429120189805438922L;
  3409         private static final long serialVersionUID = -5429120189805438922L;
  3389 
  3410 
       
  3411         @SuppressWarnings("serial") // Conditionally serializable
  3390         private final NavigableSet<E> ns;
  3412         private final NavigableSet<E> ns;
  3391 
  3413 
  3392         CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
  3414         CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
  3393             super(s, type);
  3415             super(s, type);
  3394             ns = s;
  3416             ns = s;
  3468         extends CheckedCollection<E>
  3490         extends CheckedCollection<E>
  3469         implements List<E>
  3491         implements List<E>
  3470     {
  3492     {
  3471         @java.io.Serial
  3493         @java.io.Serial
  3472         private static final long serialVersionUID = 65247728283967356L;
  3494         private static final long serialVersionUID = 65247728283967356L;
       
  3495         @SuppressWarnings("serial") // Conditionally serializable
  3473         final List<E> list;
  3496         final List<E> list;
  3474 
  3497 
  3475         CheckedList(List<E> list, Class<E> type) {
  3498         CheckedList(List<E> list, Class<E> type) {
  3476             super(list, type);
  3499             super(list, type);
  3477             this.list = list;
  3500             this.list = list;
  3617         implements Map<K,V>, Serializable
  3640         implements Map<K,V>, Serializable
  3618     {
  3641     {
  3619         @java.io.Serial
  3642         @java.io.Serial
  3620         private static final long serialVersionUID = 5742860141034234728L;
  3643         private static final long serialVersionUID = 5742860141034234728L;
  3621 
  3644 
       
  3645         @SuppressWarnings("serial") // Conditionally serializable
  3622         private final Map<K, V> m;
  3646         private final Map<K, V> m;
       
  3647         @SuppressWarnings("serial") // Conditionally serializable
  3623         final Class<K> keyType;
  3648         final Class<K> keyType;
       
  3649         @SuppressWarnings("serial") // Conditionally serializable
  3624         final Class<V> valueType;
  3650         final Class<V> valueType;
  3625 
  3651 
  3626         private void typeCheck(Object key, Object value) {
  3652         private void typeCheck(Object key, Object value) {
  3627             if (key != null && !keyType.isInstance(key))
  3653             if (key != null && !keyType.isInstance(key))
  3628                 throw new ClassCastException(badKeyMsg(key));
  3654                 throw new ClassCastException(badKeyMsg(key));
  4017         implements SortedMap<K,V>, Serializable
  4043         implements SortedMap<K,V>, Serializable
  4018     {
  4044     {
  4019         @java.io.Serial
  4045         @java.io.Serial
  4020         private static final long serialVersionUID = 1599671320688067438L;
  4046         private static final long serialVersionUID = 1599671320688067438L;
  4021 
  4047 
       
  4048         @SuppressWarnings("serial") // Conditionally serializable
  4022         private final SortedMap<K, V> sm;
  4049         private final SortedMap<K, V> sm;
  4023 
  4050 
  4024         CheckedSortedMap(SortedMap<K, V> m,
  4051         CheckedSortedMap(SortedMap<K, V> m,
  4025                          Class<K> keyType, Class<V> valueType) {
  4052                          Class<K> keyType, Class<V> valueType) {
  4026             super(m, keyType, valueType);
  4053             super(m, keyType, valueType);
  4092         implements NavigableMap<K,V>, Serializable
  4119         implements NavigableMap<K,V>, Serializable
  4093     {
  4120     {
  4094         @java.io.Serial
  4121         @java.io.Serial
  4095         private static final long serialVersionUID = -4852462692372534096L;
  4122         private static final long serialVersionUID = -4852462692372534096L;
  4096 
  4123 
       
  4124         @SuppressWarnings("serial") // Conditionally serializable
  4097         private final NavigableMap<K, V> nm;
  4125         private final NavigableMap<K, V> nm;
  4098 
  4126 
  4099         CheckedNavigableMap(NavigableMap<K, V> m,
  4127         CheckedNavigableMap(NavigableMap<K, V> m,
  4100                          Class<K> keyType, Class<V> valueType) {
  4128                          Class<K> keyType, Class<V> valueType) {
  4101             super(m, keyType, valueType);
  4129             super(m, keyType, valueType);
  4823         implements Serializable
  4851         implements Serializable
  4824     {
  4852     {
  4825         @java.io.Serial
  4853         @java.io.Serial
  4826         private static final long serialVersionUID = 3193687207550431679L;
  4854         private static final long serialVersionUID = 3193687207550431679L;
  4827 
  4855 
       
  4856         @SuppressWarnings("serial") // Conditionally serializable
  4828         private final E element;
  4857         private final E element;
  4829 
  4858 
  4830         SingletonSet(E e) {element = e;}
  4859         SingletonSet(E e) {element = e;}
  4831 
  4860 
  4832         public Iterator<E> iterator() {
  4861         public Iterator<E> iterator() {
  4877         implements RandomAccess, Serializable {
  4906         implements RandomAccess, Serializable {
  4878 
  4907 
  4879         @java.io.Serial
  4908         @java.io.Serial
  4880         private static final long serialVersionUID = 3093736618740652951L;
  4909         private static final long serialVersionUID = 3093736618740652951L;
  4881 
  4910 
       
  4911         @SuppressWarnings("serial") // Conditionally serializable
  4882         private final E element;
  4912         private final E element;
  4883 
  4913 
  4884         SingletonList(E obj)                {element = obj;}
  4914         SingletonList(E obj)                {element = obj;}
  4885 
  4915 
  4886         public Iterator<E> iterator() {
  4916         public Iterator<E> iterator() {
  4946           extends AbstractMap<K,V>
  4976           extends AbstractMap<K,V>
  4947           implements Serializable {
  4977           implements Serializable {
  4948         @java.io.Serial
  4978         @java.io.Serial
  4949         private static final long serialVersionUID = -6979724477215052911L;
  4979         private static final long serialVersionUID = -6979724477215052911L;
  4950 
  4980 
       
  4981         @SuppressWarnings("serial") // Conditionally serializable
  4951         private final K k;
  4982         private final K k;
       
  4983         @SuppressWarnings("serial") // Conditionally serializable
  4952         private final V v;
  4984         private final V v;
  4953 
  4985 
  4954         SingletonMap(K key, V value) {
  4986         SingletonMap(K key, V value) {
  4955             k = key;
  4987             k = key;
  4956             v = value;
  4988             v = value;
  5085     {
  5117     {
  5086         @java.io.Serial
  5118         @java.io.Serial
  5087         private static final long serialVersionUID = 2739099268398711800L;
  5119         private static final long serialVersionUID = 2739099268398711800L;
  5088 
  5120 
  5089         final int n;
  5121         final int n;
       
  5122         @SuppressWarnings("serial") // Conditionally serializable
  5090         final E element;
  5123         final E element;
  5091 
  5124 
  5092         CopiesList(int n, E e) {
  5125         CopiesList(int n, E e) {
  5093             assert n >= 0;
  5126             assert n >= 0;
  5094             this.n = n;
  5127             this.n = n;
  5318          * be null, as the static factory returns a ReverseComparator
  5351          * be null, as the static factory returns a ReverseComparator
  5319          * instance if its argument is null.
  5352          * instance if its argument is null.
  5320          *
  5353          *
  5321          * @serial
  5354          * @serial
  5322          */
  5355          */
       
  5356         @SuppressWarnings("serial") // Conditionally serializable
  5323         final Comparator<T> cmp;
  5357         final Comparator<T> cmp;
  5324 
  5358 
  5325         ReverseComparator2(Comparator<T> cmp) {
  5359         ReverseComparator2(Comparator<T> cmp) {
  5326             assert cmp != null;
  5360             assert cmp != null;
  5327             this.cmp = cmp;
  5361             this.cmp = cmp;
  5599      * @serial include
  5633      * @serial include
  5600      */
  5634      */
  5601     private static class SetFromMap<E> extends AbstractSet<E>
  5635     private static class SetFromMap<E> extends AbstractSet<E>
  5602         implements Set<E>, Serializable
  5636         implements Set<E>, Serializable
  5603     {
  5637     {
       
  5638         @SuppressWarnings("serial") // Conditionally serializable
  5604         private final Map<E, Boolean> m;  // The backing map
  5639         private final Map<E, Boolean> m;  // The backing map
  5605         private transient Set<E> s;       // Its keySet
  5640         private transient Set<E> s;       // Its keySet
  5606 
  5641 
  5607         SetFromMap(Map<E, Boolean> map) {
  5642         SetFromMap(Map<E, Boolean> map) {
  5608             if (!map.isEmpty())
  5643             if (!map.isEmpty())
  5684      */
  5719      */
  5685     static class AsLIFOQueue<E> extends AbstractQueue<E>
  5720     static class AsLIFOQueue<E> extends AbstractQueue<E>
  5686         implements Queue<E>, Serializable {
  5721         implements Queue<E>, Serializable {
  5687         @java.io.Serial
  5722         @java.io.Serial
  5688         private static final long serialVersionUID = 1802017725587941708L;
  5723         private static final long serialVersionUID = 1802017725587941708L;
       
  5724         @SuppressWarnings("serial") // Conditionally serializable
  5689         private final Deque<E> q;
  5725         private final Deque<E> q;
  5690         AsLIFOQueue(Deque<E> q)                     { this.q = q; }
  5726         AsLIFOQueue(Deque<E> q)                     { this.q = q; }
  5691         public boolean add(E e)                     { q.addFirst(e); return true; }
  5727         public boolean add(E e)                     { q.addFirst(e); return true; }
  5692         public boolean offer(E e)                   { return q.offerFirst(e); }
  5728         public boolean offer(E e)                   { return q.offerFirst(e); }
  5693         public E poll()                             { return q.pollFirst(); }
  5729         public E poll()                             { return q.pollFirst(); }