< prev index next >

src/java.base/share/classes/java/util/TreeSet.java

Print this page




 203      *
 204      * @return the number of elements in this set (its cardinality)
 205      */
 206     public int size() {
 207         return m.size();
 208     }
 209 
 210     /**
 211      * Returns {@code true} if this set contains no elements.
 212      *
 213      * @return {@code true} if this set contains no elements
 214      */
 215     public boolean isEmpty() {
 216         return m.isEmpty();
 217     }
 218 
 219     /**
 220      * Returns {@code true} if this set contains the specified element.
 221      * More formally, returns {@code true} if and only if this set
 222      * contains an element {@code e} such that
 223      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 224      *
 225      * @param o object to be checked for containment in this set
 226      * @return {@code true} if this set contains the specified element
 227      * @throws ClassCastException if the specified object cannot be compared
 228      *         with the elements currently in the set
 229      * @throws NullPointerException if the specified element is null
 230      *         and this set uses natural ordering, or its comparator
 231      *         does not permit null elements
 232      */
 233     public boolean contains(Object o) {
 234         return m.containsKey(o);
 235     }
 236 
 237     /**
 238      * Adds the specified element to this set if it is not already present.
 239      * More formally, adds the specified element {@code e} to this set if
 240      * the set contains no element {@code e2} such that
 241      * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
 242      * If this set already contains the element, the call leaves the set
 243      * unchanged and returns {@code false}.
 244      *
 245      * @param e element to be added to this set
 246      * @return {@code true} if this set did not already contain the specified
 247      *         element
 248      * @throws ClassCastException if the specified object cannot be compared
 249      *         with the elements currently in this set
 250      * @throws NullPointerException if the specified element is null
 251      *         and this set uses natural ordering, or its comparator
 252      *         does not permit null elements
 253      */
 254     public boolean add(E e) {
 255         return m.put(e, PRESENT)==null;
 256     }
 257 
 258     /**
 259      * Removes the specified element from this set if it is present.
 260      * More formally, removes an element {@code e} such that
 261      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
 262      * if this set contains such an element.  Returns {@code true} if
 263      * this set contained the element (or equivalently, if this set
 264      * changed as a result of the call).  (This set will not contain the
 265      * element once the call returns.)
 266      *
 267      * @param o object to be removed from this set, if present
 268      * @return {@code true} if this set contained the specified element
 269      * @throws ClassCastException if the specified object cannot be compared
 270      *         with the elements currently in this set
 271      * @throws NullPointerException if the specified element is null
 272      *         and this set uses natural ordering, or its comparator
 273      *         does not permit null elements
 274      */
 275     public boolean remove(Object o) {
 276         return m.remove(o)==PRESENT;
 277     }
 278 
 279     /**
 280      * Removes all of the elements from this set.
 281      * The set will be empty after this call returns.




 203      *
 204      * @return the number of elements in this set (its cardinality)
 205      */
 206     public int size() {
 207         return m.size();
 208     }
 209 
 210     /**
 211      * Returns {@code true} if this set contains no elements.
 212      *
 213      * @return {@code true} if this set contains no elements
 214      */
 215     public boolean isEmpty() {
 216         return m.isEmpty();
 217     }
 218 
 219     /**
 220      * Returns {@code true} if this set contains the specified element.
 221      * More formally, returns {@code true} if and only if this set
 222      * contains an element {@code e} such that
 223      * <code>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>.
 224      *
 225      * @param o object to be checked for containment in this set
 226      * @return {@code true} if this set contains the specified element
 227      * @throws ClassCastException if the specified object cannot be compared
 228      *         with the elements currently in the set
 229      * @throws NullPointerException if the specified element is null
 230      *         and this set uses natural ordering, or its comparator
 231      *         does not permit null elements
 232      */
 233     public boolean contains(Object o) {
 234         return m.containsKey(o);
 235     }
 236 
 237     /**
 238      * Adds the specified element to this set if it is not already present.
 239      * More formally, adds the specified element {@code e} to this set if
 240      * the set contains no element {@code e2} such that
 241      * <code>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</code>.
 242      * If this set already contains the element, the call leaves the set
 243      * unchanged and returns {@code false}.
 244      *
 245      * @param e element to be added to this set
 246      * @return {@code true} if this set did not already contain the specified
 247      *         element
 248      * @throws ClassCastException if the specified object cannot be compared
 249      *         with the elements currently in this set
 250      * @throws NullPointerException if the specified element is null
 251      *         and this set uses natural ordering, or its comparator
 252      *         does not permit null elements
 253      */
 254     public boolean add(E e) {
 255         return m.put(e, PRESENT)==null;
 256     }
 257 
 258     /**
 259      * Removes the specified element from this set if it is present.
 260      * More formally, removes an element {@code e} such that
 261      * <code>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>,
 262      * if this set contains such an element.  Returns {@code true} if
 263      * this set contained the element (or equivalently, if this set
 264      * changed as a result of the call).  (This set will not contain the
 265      * element once the call returns.)
 266      *
 267      * @param o object to be removed from this set, if present
 268      * @return {@code true} if this set contained the specified element
 269      * @throws ClassCastException if the specified object cannot be compared
 270      *         with the elements currently in this set
 271      * @throws NullPointerException if the specified element is null
 272      *         and this set uses natural ordering, or its comparator
 273      *         does not permit null elements
 274      */
 275     public boolean remove(Object o) {
 276         return m.remove(o)==PRESENT;
 277     }
 278 
 279     /**
 280      * Removes all of the elements from this set.
 281      * The set will be empty after this call returns.


< prev index next >