Home | History | Annotate | Download | only in collect
      1 /*
      2  * Copyright (C) 2012 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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 
     17 package com.google.common.collect;
     18 
     19 import com.google.common.collect.Multisets.UnmodifiableMultiset;
     20 
     21 import java.util.Collections;
     22 import java.util.Comparator;
     23 import java.util.SortedSet;
     24 
     25 /**
     26  * Implementation of {@link Multisets#unmodifiableSortedMultiset(SortedMultiset)}
     27  * for GWT.
     28  *
     29  * @author Louis Wasserman
     30  */
     31 final class UnmodifiableSortedMultiset<E>
     32     extends UnmodifiableMultiset<E> implements SortedMultiset<E> {
     33   UnmodifiableSortedMultiset(SortedMultiset<E> delegate) {
     34     super(delegate);
     35   }
     36 
     37   @Override
     38   protected SortedMultiset<E> delegate() {
     39     return (SortedMultiset<E>) super.delegate();
     40   }
     41 
     42   @Override
     43   public Comparator<? super E> comparator() {
     44     return delegate().comparator();
     45   }
     46 
     47   @Override
     48   SortedSet<E> createElementSet() {
     49     return Collections.unmodifiableSortedSet(delegate().elementSet());
     50   }
     51 
     52   @Override
     53   public SortedSet<E> elementSet() {
     54     return (SortedSet<E>) super.elementSet();
     55   }
     56 
     57   private transient UnmodifiableSortedMultiset<E> descendingMultiset;
     58 
     59   @Override
     60   public SortedMultiset<E> descendingMultiset() {
     61     UnmodifiableSortedMultiset<E> result = descendingMultiset;
     62     if (result == null) {
     63       result = new UnmodifiableSortedMultiset<E>(
     64           delegate().descendingMultiset());
     65       result.descendingMultiset = this;
     66       return descendingMultiset = result;
     67     }
     68     return result;
     69   }
     70 
     71   @Override
     72   public Entry<E> firstEntry() {
     73     return delegate().firstEntry();
     74   }
     75 
     76   @Override
     77   public Entry<E> lastEntry() {
     78     return delegate().lastEntry();
     79   }
     80 
     81   @Override
     82   public Entry<E> pollFirstEntry() {
     83     throw new UnsupportedOperationException();
     84   }
     85 
     86   @Override
     87   public Entry<E> pollLastEntry() {
     88     throw new UnsupportedOperationException();
     89   }
     90 
     91   @Override
     92   public SortedMultiset<E> headMultiset(E upperBound, BoundType boundType) {
     93     return Multisets.unmodifiableSortedMultiset(
     94         delegate().headMultiset(upperBound, boundType));
     95   }
     96 
     97   @Override
     98   public SortedMultiset<E> subMultiset(
     99       E lowerBound, BoundType lowerBoundType,
    100       E upperBound, BoundType upperBoundType) {
    101     return Multisets.unmodifiableSortedMultiset(delegate().subMultiset(
    102         lowerBound, lowerBoundType, upperBound, upperBoundType));
    103   }
    104 
    105   @Override
    106   public SortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) {
    107     return Multisets.unmodifiableSortedMultiset(
    108         delegate().tailMultiset(lowerBound, boundType));
    109   }
    110 
    111   private static final long serialVersionUID = 0;
    112 }