ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/TreeSet.java
(Generate patch)

Comparing jsr166/src/main/java/util/TreeSet.java (file contents):
Revision 1.26 by jsr166, Sun May 20 07:54:01 2007 UTC vs.
Revision 1.27 by jsr166, Sun May 18 23:47:56 2008 UTC

# Line 81 | Line 81 | package java.util;
81   *
82   * @author  Josh Bloch
83   * @version %I%, %G%
84 < * @see     Collection
85 < * @see     Set
86 < * @see     HashSet
84 > * @see     Collection
85 > * @see     Set
86 > * @see     HashSet
87   * @see     Comparable
88   * @see     Comparator
89 < * @see     TreeMap
89 > * @see     TreeMap
90   * @since   1.2
91   */
92  
# Line 122 | Line 122 | public class TreeSet<E> extends Abstract
122       * {@code ClassCastException}.
123       */
124      public TreeSet() {
125 <        this(new TreeMap<E,Object>());
125 >        this(new TreeMap<E,Object>());
126      }
127  
128      /**
# Line 139 | Line 139 | public class TreeSet<E> extends Abstract
139       *        ordering} of the elements will be used.
140       */
141      public TreeSet(Comparator<? super E> comparator) {
142 <        this(new TreeMap<E,Object>(comparator));
142 >        this(new TreeMap<E,Object>(comparator));
143      }
144  
145      /**
# Line 170 | Line 170 | public class TreeSet<E> extends Abstract
170       */
171      public TreeSet(SortedSet<E> s) {
172          this(s.comparator());
173 <        addAll(s);
173 >        addAll(s);
174      }
175  
176      /**
# Line 189 | Line 189 | public class TreeSet<E> extends Abstract
189       * @since 1.6
190       */
191      public Iterator<E> descendingIterator() {
192 <        return m.descendingKeySet().iterator();
192 >        return m.descendingKeySet().iterator();
193      }
194  
195      /**
196       * @since 1.6
197       */
198      public NavigableSet<E> descendingSet() {
199 <        return new TreeSet(m.descendingMap());
199 >        return new TreeSet(m.descendingMap());
200      }
201  
202      /**
# Line 205 | Line 205 | public class TreeSet<E> extends Abstract
205       * @return the number of elements in this set (its cardinality)
206       */
207      public int size() {
208 <        return m.size();
208 >        return m.size();
209      }
210  
211      /**
# Line 214 | Line 214 | public class TreeSet<E> extends Abstract
214       * @return {@code true} if this set contains no elements
215       */
216      public boolean isEmpty() {
217 <        return m.isEmpty();
217 >        return m.isEmpty();
218      }
219  
220      /**
# Line 232 | Line 232 | public class TreeSet<E> extends Abstract
232       *         does not permit null elements
233       */
234      public boolean contains(Object o) {
235 <        return m.containsKey(o);
235 >        return m.containsKey(o);
236      }
237  
238      /**
# Line 253 | Line 253 | public class TreeSet<E> extends Abstract
253       *         does not permit null elements
254       */
255      public boolean add(E e) {
256 <        return m.put(e, PRESENT)==null;
256 >        return m.put(e, PRESENT)==null;
257      }
258  
259      /**
# Line 274 | Line 274 | public class TreeSet<E> extends Abstract
274       *         does not permit null elements
275       */
276      public boolean remove(Object o) {
277 <        return m.remove(o)==PRESENT;
277 >        return m.remove(o)==PRESENT;
278      }
279  
280      /**
# Line 282 | Line 282 | public class TreeSet<E> extends Abstract
282       * The set will be empty after this call returns.
283       */
284      public void clear() {
285 <        m.clear();
285 >        m.clear();
286      }
287  
288      /**
# Line 299 | Line 299 | public class TreeSet<E> extends Abstract
299      public  boolean addAll(Collection<? extends E> c) {
300          // Use linear-time version if applicable
301          if (m.size()==0 && c.size() > 0 &&
302 <            c instanceof SortedSet &&
302 >            c instanceof SortedSet &&
303              m instanceof TreeMap) {
304              SortedSet<? extends E> set = (SortedSet<? extends E>) c;
305              TreeMap<E,Object> map = (TreeMap<E, Object>) m;
# Line 323 | Line 323 | public class TreeSet<E> extends Abstract
323       */
324      public NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
325                                    E toElement,   boolean toInclusive) {
326 <        return new TreeSet<E>(m.subMap(fromElement, fromInclusive,
326 >        return new TreeSet<E>(m.subMap(fromElement, fromInclusive,
327                                         toElement,   toInclusive));
328      }
329  
# Line 336 | Line 336 | public class TreeSet<E> extends Abstract
336       * @since 1.6
337       */
338      public NavigableSet<E> headSet(E toElement, boolean inclusive) {
339 <        return new TreeSet<E>(m.headMap(toElement, inclusive));
339 >        return new TreeSet<E>(m.headMap(toElement, inclusive));
340      }
341  
342      /**
# Line 348 | Line 348 | public class TreeSet<E> extends Abstract
348       * @since 1.6
349       */
350      public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {
351 <        return new TreeSet<E>(m.tailMap(fromElement, inclusive));
351 >        return new TreeSet<E>(m.tailMap(fromElement, inclusive));
352      }
353  
354      /**
# Line 359 | Line 359 | public class TreeSet<E> extends Abstract
359       * @throws IllegalArgumentException {@inheritDoc}
360       */
361      public SortedSet<E> subSet(E fromElement, E toElement) {
362 <        return subSet(fromElement, true, toElement, false);
362 >        return subSet(fromElement, true, toElement, false);
363      }
364  
365      /**
# Line 370 | Line 370 | public class TreeSet<E> extends Abstract
370       * @throws IllegalArgumentException {@inheritDoc}
371       */
372      public SortedSet<E> headSet(E toElement) {
373 <        return headSet(toElement, false);
373 >        return headSet(toElement, false);
374      }
375  
376      /**
# Line 381 | Line 381 | public class TreeSet<E> extends Abstract
381       * @throws IllegalArgumentException {@inheritDoc}
382       */
383      public SortedSet<E> tailSet(E fromElement) {
384 <        return tailSet(fromElement, true);
384 >        return tailSet(fromElement, true);
385      }
386  
387      public Comparator<? super E> comparator() {
# Line 472 | Line 472 | public class TreeSet<E> extends Abstract
472       */
473      public Object clone() {
474          TreeSet<E> clone = null;
475 <        try {
476 <            clone = (TreeSet<E>) super.clone();
477 <        } catch (CloneNotSupportedException e) {
478 <            throw new InternalError();
479 <        }
475 >        try {
476 >            clone = (TreeSet<E>) super.clone();
477 >        } catch (CloneNotSupportedException e) {
478 >            throw new InternalError();
479 >        }
480  
481          clone.m = new TreeMap<E,Object>(m);
482          return clone;
# Line 496 | Line 496 | public class TreeSet<E> extends Abstract
496       */
497      private void writeObject(java.io.ObjectOutputStream s)
498          throws java.io.IOException {
499 <        // Write out any hidden stuff
500 <        s.defaultWriteObject();
499 >        // Write out any hidden stuff
500 >        s.defaultWriteObject();
501  
502          // Write out Comparator
503          s.writeObject(m.comparator());
# Line 505 | Line 505 | public class TreeSet<E> extends Abstract
505          // Write out size
506          s.writeInt(m.size());
507  
508 <        // Write out all elements in the proper order.
509 <        for (Iterator i=m.keySet().iterator(); i.hasNext(); )
508 >        // Write out all elements in the proper order.
509 >        for (Iterator i=m.keySet().iterator(); i.hasNext(); )
510              s.writeObject(i.next());
511      }
512  
# Line 516 | Line 516 | public class TreeSet<E> extends Abstract
516       */
517      private void readObject(java.io.ObjectInputStream s)
518          throws java.io.IOException, ClassNotFoundException {
519 <        // Read in any hidden stuff
520 <        s.defaultReadObject();
519 >        // Read in any hidden stuff
520 >        s.defaultReadObject();
521  
522          // Read in Comparator
523          Comparator<? super E> c = (Comparator<? super E>) s.readObject();
524  
525          // Create backing TreeMap
526 <        TreeMap<E,Object> tm;
527 <        if (c==null)
528 <            tm = new TreeMap<E,Object>();
529 <        else
530 <            tm = new TreeMap<E,Object>(c);
531 <        m = tm;
526 >        TreeMap<E,Object> tm;
527 >        if (c==null)
528 >            tm = new TreeMap<E,Object>();
529 >        else
530 >            tm = new TreeMap<E,Object>(c);
531 >        m = tm;
532  
533          // Read in size
534          int size = s.readInt();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines