Java Reference
In-Depth Information
1
/**
2
* Construct an empty TreeSet.
3
*/
4
public TreeSet( )
5
{
6
nullNode = new AANode<AnyType>( null, null, null );
7
nullNode.left = nullNode.right = nullNode;
8
nullNode.level = 0;
9
root = nullNode;
10
cmp = null;
11
}
12
13
/**
14
* Construct an empty TreeSet with a specified comparator.
15
*/
16
public TreeSet( Comparator<? super AnyType> c )
17
{ this( ); cmp = c; }
18
19
/**
20
* Construct a TreeSet from another SortedSet.
21
*/
22
public TreeSet( SortedSet<AnyType> other )
23
{ this( other.comparator( ) ); copyFrom( other ); }
24
25
/**
26
* Construct a TreeSet from any collection.
27
* Uses an O( N log N ) algorithm, but could be improved.
28
*/
29
public TreeSet( Collection<? extends AnyType> other )
30
{ this( ); copyFrom( other ); }
31
32
/**
33
* Return the comparator used by this TreeSet.
34
* @return the comparator or null if the default comparator is used.
35
*/
36
public Comparator<? super AnyType> comparator( )
37
{ return cmp; }
38
39
/**
40
* Copy any collection into a new TreeSet.
41
*/
42
private void copyFrom( Collection<? extends AnyType> other )
43
{
44
clear( );
45
for( AnyType x : other )
46
add( x );
47
}
figure 19.69
Constructors and comparator method for
TreeSet
Search WWH ::
Custom Search