01: /*
02: * Copyright 2003-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.map;
17:
18: import java.util.Comparator;
19: import java.util.SortedMap;
20:
21: /**
22: * Provides a base decorator that enables additional functionality to be added
23: * to a Map via decoration.
24: * <p>
25: * Methods are forwarded directly to the decorated map.
26: * <p>
27: * This implementation does not perform any special processing with the map views.
28: * Instead it simply returns the set/collection from the wrapped map. This may be
29: * undesirable, for example if you are trying to write a validating implementation
30: * it would provide a loophole around the validation.
31: * But, you might want that loophole, so this class is kept simple.
32: *
33: * @since Commons Collections 3.0
34: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
35: *
36: * @author Stephen Colebourne
37: */
38: public abstract class AbstractSortedMapDecorator extends
39: AbstractMapDecorator implements SortedMap {
40:
41: /**
42: * Constructor only used in deserialization, do not use otherwise.
43: * @since Commons Collections 3.1
44: */
45: protected AbstractSortedMapDecorator() {
46: super ();
47: }
48:
49: /**
50: * Constructor that wraps (not copies).
51: *
52: * @param map the map to decorate, must not be null
53: * @throws IllegalArgumentException if the collection is null
54: */
55: public AbstractSortedMapDecorator(SortedMap map) {
56: super (map);
57: }
58:
59: /**
60: * Gets the map being decorated.
61: *
62: * @return the decorated map
63: */
64: protected SortedMap getSortedMap() {
65: return (SortedMap) map;
66: }
67:
68: //-----------------------------------------------------------------------
69: public Comparator comparator() {
70: return getSortedMap().comparator();
71: }
72:
73: public Object firstKey() {
74: return getSortedMap().firstKey();
75: }
76:
77: public SortedMap headMap(Object toKey) {
78: return getSortedMap().headMap(toKey);
79: }
80:
81: public Object lastKey() {
82: return getSortedMap().lastKey();
83: }
84:
85: public SortedMap subMap(Object fromKey, Object toKey) {
86: return getSortedMap().subMap(fromKey, toKey);
87: }
88:
89: public SortedMap tailMap(Object fromKey) {
90: return getSortedMap().tailMap(fromKey);
91: }
92:
93: }
|