MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / TreeSet

Class TreeSet

Ports/CLDC11/src/java/util/TreeSet.java:28–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26///
27/// 1.2
28public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E> {
29
30 /// Keys are this set's elements. Values are always Boolean.TRUE
31 private transient NavigableMap<E, Object> backingMap;
32
33 private transient NavigableSet<E> descendingSet;
34
35 TreeSet(NavigableMap<E, Object> map) {
36 backingMap = map;
37 }
38
39 /// Constructs a new empty instance of `TreeSet` which uses natural
40 /// ordering.
41 public TreeSet() {
42 backingMap = new TreeMap<E, Object>();
43 }
44
45 /// Constructs a new instance of `TreeSet` which uses natural ordering
46 /// and containing the unique elements in the specified collection.
47 ///
48 /// #### Parameters
49 ///
50 /// - `collection`: the collection of elements to add.
51 ///
52 /// #### Throws
53 ///
54 /// - `ClassCastException`: @throws ClassCastException
55 /// when an element in the collection does not implement the
56 /// Comparable interface, or the elements in the collection
57 /// cannot be compared.
58 public TreeSet(Collection<? extends E> collection) {
59 this();
60 addAll(collection);
61 }
62
63 /// Constructs a new empty instance of `TreeSet` which uses the
64 /// specified comparator.
65 ///
66 /// #### Parameters
67 ///
68 /// - `comparator`: the comparator to use.
69 public TreeSet(Comparator<? super E> comparator) {
70 backingMap = new TreeMap<E, Object>(comparator);
71 }
72
73 /// Constructs a new instance of `TreeSet` containing the elements of
74 /// the specified SortedSet and using the same Comparator.
75 ///
76 /// #### Parameters
77 ///
78 /// - `set`: the SortedSet of elements to add.
79 public TreeSet(SortedSet<E> set) {
80 this(set.comparator());
81 Iterator<E> it = set.iterator();
82 while (it.hasNext()) {
83 add(it.next());
84 }
85 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected