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.bag;
018
019 import java.util.Comparator;
020
021 import org.apache.commons.collections.SortedBag;
022
023 /**
024 * Decorates another <code>SortedBag</code> to provide additional behaviour.
025 * <p>
026 * Methods are forwarded directly to the decorated bag.
027 *
028 * @since Commons Collections 3.0
029 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
030 *
031 * @author Stephen Colebourne
032 */
033 public abstract class AbstractSortedBagDecorator
034 extends AbstractBagDecorator implements SortedBag {
035
036 /**
037 * Constructor only used in deserialization, do not use otherwise.
038 * @since Commons Collections 3.1
039 */
040 protected AbstractSortedBagDecorator() {
041 super();
042 }
043
044 /**
045 * Constructor that wraps (not copies).
046 *
047 * @param bag the bag to decorate, must not be null
048 * @throws IllegalArgumentException if list is null
049 */
050 protected AbstractSortedBagDecorator(SortedBag bag) {
051 super(bag);
052 }
053
054 /**
055 * Gets the bag being decorated.
056 *
057 * @return the decorated bag
058 */
059 protected SortedBag getSortedBag() {
060 return (SortedBag) getCollection();
061 }
062
063 //-----------------------------------------------------------------------
064 public Object first() {
065 return getSortedBag().first();
066 }
067
068 public Object last() {
069 return getSortedBag().last();
070 }
071
072 public Comparator comparator() {
073 return getSortedBag().comparator();
074 }
075
076 }