01: /*
02: * Copyright 2002-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
19: import java.util.Comparator;
20: import java.util.SortedMap;
21: import java.util.TreeMap;
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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
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());
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 comparator) {
50: super (new TreeMap(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 coll) {
60: this ();
61: addAll(coll);
62: }
63:
64: public Object first() {
65: return ((SortedMap) getMap()).firstKey();
66: }
67:
68: public Object last() {
69: return ((SortedMap) getMap()).lastKey();
70: }
71:
72: public Comparator comparator() {
73: return ((SortedMap) getMap()).comparator();
74: }
75:
76: }
|