001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.collections.map; 018 019 import java.util.Comparator; 020 import java.util.SortedMap; 021 022 /** 023 * Provides a base decorator that enables additional functionality to be added 024 * to a Map via decoration. 025 * <p> 026 * Methods are forwarded directly to the decorated map. 027 * <p> 028 * This implementation does not perform any special processing with the map views. 029 * Instead it simply returns the set/collection from the wrapped map. This may be 030 * undesirable, for example if you are trying to write a validating implementation 031 * it would provide a loophole around the validation. 032 * But, you might want that loophole, so this class is kept simple. 033 * 034 * @since Commons Collections 3.0 035 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $ 036 * 037 * @author Stephen Colebourne 038 */ 039 public abstract class AbstractSortedMapDecorator 040 extends AbstractMapDecorator implements SortedMap { 041 042 /** 043 * Constructor only used in deserialization, do not use otherwise. 044 * @since Commons Collections 3.1 045 */ 046 protected AbstractSortedMapDecorator() { 047 super(); 048 } 049 050 /** 051 * Constructor that wraps (not copies). 052 * 053 * @param map the map to decorate, must not be null 054 * @throws IllegalArgumentException if the collection is null 055 */ 056 public AbstractSortedMapDecorator(SortedMap map) { 057 super(map); 058 } 059 060 /** 061 * Gets the map being decorated. 062 * 063 * @return the decorated map 064 */ 065 protected SortedMap getSortedMap() { 066 return (SortedMap) map; 067 } 068 069 //----------------------------------------------------------------------- 070 public Comparator comparator() { 071 return getSortedMap().comparator(); 072 } 073 074 public Object firstKey() { 075 return getSortedMap().firstKey(); 076 } 077 078 public SortedMap headMap(Object toKey) { 079 return getSortedMap().headMap(toKey); 080 } 081 082 public Object lastKey() { 083 return getSortedMap().lastKey(); 084 } 085 086 public SortedMap subMap(Object fromKey, Object toKey) { 087 return getSortedMap().subMap(fromKey, toKey); 088 } 089 090 public SortedMap tailMap(Object fromKey) { 091 return getSortedMap().tailMap(fromKey); 092 } 093 094 }