KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > TreeBag


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Comparator JavaDoc;
20 import java.util.SortedMap JavaDoc;
21 import java.util.TreeMap JavaDoc;
22
23 /**
24  * A {@link Bag} that is backed by a {@link TreeMap}.
25  * Order will be maintained among the unique representative
26  * members.
27  *
28  * @deprecated Moved to bag subpackage and rewritten internally. Due to be removed in v4.0.
29  * @since Commons Collections 2.0
30  * @version $Revision: 1.13 $ $Date: 2004/02/18 01:15:42 $
31  *
32  * @author Chuck Burdick
33  */

34 public class TreeBag extends DefaultMapBag implements SortedBag {
35
36     /**
37      * Constructs an empty <code>TreeBag</code>.
38      */

39     public TreeBag() {
40         super(new TreeMap JavaDoc());
41     }
42
43     /**
44      * Constructs an empty {@link Bag} that maintains order on its unique
45      * representative members according to the given {@link Comparator}.
46      *
47      * @param comparator the comparator to use
48      */

49     public TreeBag(Comparator JavaDoc comparator) {
50         super(new TreeMap JavaDoc(comparator));
51     }
52
53     /**
54      * Constructs a {@link Bag} containing all the members of the given
55      * collection.
56      *
57      * @param coll the collection to copy into the bag
58      */

59     public TreeBag(Collection JavaDoc coll) {
60         this();
61         addAll(coll);
62     }
63
64     public Object JavaDoc first() {
65         return ((SortedMap JavaDoc) getMap()).firstKey();
66     }
67
68     public Object JavaDoc last() {
69         return ((SortedMap JavaDoc) getMap()).lastKey();
70     }
71
72     public Comparator JavaDoc comparator() {
73         return ((SortedMap JavaDoc) getMap()).comparator();
74     }
75     
76 }
77
Popular Tags