UnmodifiableSortedMultiset.java revision 7dd252788645e940eada959bdde927426e2531c9
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 17package com.google.common.collect; 18 19import com.google.common.annotations.GwtCompatible; 20import com.google.common.collect.Multisets.UnmodifiableMultiset; 21 22import java.util.Collections; 23import java.util.Comparator; 24import java.util.SortedSet; 25 26/** 27 * Implementation of {@link Multisets#unmodifiableSortedMultiset(SortedMultiset)}, 28 * split out into its own file so it can be GWT emulated (to deal with the differing 29 * elementSet() types in GWT and non-GWT). 30 * 31 * @author Louis Wasserman 32 */ 33@GwtCompatible(emulated = true) 34final class UnmodifiableSortedMultiset<E> extends UnmodifiableMultiset<E> implements 35 SortedMultiset<E> { 36 UnmodifiableSortedMultiset(SortedMultiset<E> delegate) { 37 super(delegate); 38 } 39 40 @Override 41 protected SortedMultiset<E> delegate() { 42 return (SortedMultiset<E>) super.delegate(); 43 } 44 45 public Comparator<? super E> comparator() { 46 return delegate().comparator(); 47 } 48 49 @Override 50 SortedSet<E> createElementSet() { 51 return Collections.unmodifiableSortedSet(delegate().elementSet()); 52 } 53 54 @Override 55 public SortedSet<E> elementSet() { 56 return (SortedSet<E>) super.elementSet(); 57 } 58 59 private transient UnmodifiableSortedMultiset<E> descendingMultiset; 60 61 public SortedMultiset<E> descendingMultiset() { 62 UnmodifiableSortedMultiset<E> result = descendingMultiset; 63 if (result == null) { 64 result = new UnmodifiableSortedMultiset<E>(delegate().descendingMultiset()); 65 result.descendingMultiset = this; 66 return descendingMultiset = result; 67 } 68 return result; 69 } 70 71 public Entry<E> firstEntry() { 72 return delegate().firstEntry(); 73 } 74 75 public Entry<E> lastEntry() { 76 return delegate().lastEntry(); 77 } 78 79 public Entry<E> pollFirstEntry() { 80 throw new UnsupportedOperationException(); 81 } 82 83 public Entry<E> pollLastEntry() { 84 throw new UnsupportedOperationException(); 85 } 86 87 public SortedMultiset<E> headMultiset(E upperBound, BoundType boundType) { 88 return Multisets.unmodifiableSortedMultiset(delegate().headMultiset(upperBound, boundType)); 89 } 90 91 public SortedMultiset<E> subMultiset(E lowerBound, BoundType lowerBoundType, E upperBound, 92 BoundType upperBoundType) { 93 return Multisets.unmodifiableSortedMultiset(delegate().subMultiset(lowerBound, lowerBoundType, 94 upperBound, upperBoundType)); 95 } 96 97 public SortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) { 98 return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType)); 99 } 100 101 private static final long serialVersionUID = 0; 102}