src/java.base/share/classes/java/util/TreeSet.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 49433 b6671a111395
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 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
   300         if (m.size()==0 && c.size() > 0 &&
   300         if (m.size()==0 && c.size() > 0 &&
   301             c instanceof SortedSet &&
   301             c instanceof SortedSet &&
   302             m instanceof TreeMap) {
   302             m instanceof TreeMap) {
   303             SortedSet<? extends E> set = (SortedSet<? extends E>) c;
   303             SortedSet<? extends E> set = (SortedSet<? extends E>) c;
   304             TreeMap<E,Object> map = (TreeMap<E, Object>) m;
   304             TreeMap<E,Object> map = (TreeMap<E, Object>) m;
   305             Comparator<?> cc = set.comparator();
   305             if (Objects.equals(set.comparator(), map.comparator())) {
   306             Comparator<? super E> mc = map.comparator();
       
   307             if (cc==mc || (cc != null && cc.equals(mc))) {
       
   308                 map.addAllForTreeSet(set, PRESENT);
   306                 map.addAllForTreeSet(set, PRESENT);
   309                 return true;
   307                 return true;
   310             }
   308             }
   311         }
   309         }
   312         return super.addAll(c);
   310         return super.addAll(c);
   492      *             elements it contains) (int), followed by all of its
   490      *             elements it contains) (int), followed by all of its
   493      *             elements (each an Object) in order (as determined by the
   491      *             elements (each an Object) in order (as determined by the
   494      *             set's Comparator, or by the elements' natural ordering if
   492      *             set's Comparator, or by the elements' natural ordering if
   495      *             the set has no Comparator).
   493      *             the set has no Comparator).
   496      */
   494      */
       
   495     @java.io.Serial
   497     private void writeObject(java.io.ObjectOutputStream s)
   496     private void writeObject(java.io.ObjectOutputStream s)
   498         throws java.io.IOException {
   497         throws java.io.IOException {
   499         // Write out any hidden stuff
   498         // Write out any hidden stuff
   500         s.defaultWriteObject();
   499         s.defaultWriteObject();
   501 
   500 
   512 
   511 
   513     /**
   512     /**
   514      * Reconstitute the {@code TreeSet} instance from a stream (that is,
   513      * Reconstitute the {@code TreeSet} instance from a stream (that is,
   515      * deserialize it).
   514      * deserialize it).
   516      */
   515      */
       
   516     @java.io.Serial
   517     private void readObject(java.io.ObjectInputStream s)
   517     private void readObject(java.io.ObjectInputStream s)
   518         throws java.io.IOException, ClassNotFoundException {
   518         throws java.io.IOException, ClassNotFoundException {
   519         // Read in any hidden stuff
   519         // Read in any hidden stuff
   520         s.defaultReadObject();
   520         s.defaultReadObject();
   521 
   521 
   554      */
   554      */
   555     public Spliterator<E> spliterator() {
   555     public Spliterator<E> spliterator() {
   556         return TreeMap.keySpliteratorFor(m);
   556         return TreeMap.keySpliteratorFor(m);
   557     }
   557     }
   558 
   558 
       
   559     @java.io.Serial
   559     private static final long serialVersionUID = -2479143000061671589L;
   560     private static final long serialVersionUID = -2479143000061671589L;
   560 }
   561 }