View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.commons.collections.set;
18  
19  import java.util.Comparator;
20  import java.util.Set;
21  import java.util.SortedSet;
22  
23  /**
24   * Decorates another <code>SortedSet</code> to provide additional behaviour.
25   * <p>
26   * Methods are forwarded directly to the decorated set.
27   *
28   * @since Commons Collections 3.0
29   * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
30   * 
31   * @author Stephen Colebourne
32   */
33  public abstract class AbstractSortedSetDecorator extends AbstractSetDecorator implements SortedSet {
34  
35      /**
36       * Constructor only used in deserialization, do not use otherwise.
37       * @since Commons Collections 3.1
38       */
39      protected AbstractSortedSetDecorator() {
40          super();
41      }
42  
43      /**
44       * Constructor that wraps (not copies).
45       * 
46       * @param set  the set to decorate, must not be null
47       * @throws IllegalArgumentException if set is null
48       */
49      protected AbstractSortedSetDecorator(Set set) {
50          super(set);
51      }
52  
53      /**
54       * Gets the sorted set being decorated.
55       * 
56       * @return the decorated set
57       */
58      protected SortedSet getSortedSet() {
59          return (SortedSet) getCollection();
60      }
61      
62      //-----------------------------------------------------------------------
63      public SortedSet subSet(Object fromElement, Object toElement) {
64          return getSortedSet().subSet(fromElement, toElement);
65      }
66  
67      public SortedSet headSet(Object toElement) {
68          return getSortedSet().headSet(toElement);
69      }
70  
71      public SortedSet tailSet(Object fromElement) {
72          return getSortedSet().tailSet(fromElement);
73      }
74  
75      public Object first() {
76          return getSortedSet().first();
77      }
78  
79      public Object last() {
80          return getSortedSet().last();
81      }
82  
83      public Comparator comparator() {
84          return getSortedSet().comparator();
85      }
86  
87  }