1/* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15package com.google.common.collect; 16 17import javax.annotation.Nullable; 18 19/** 20 * A descending wrapper around an {@code ImmutableSortedMultiset} 21 * 22 * @author Louis Wasserman 23 */ 24final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E> { 25 private final transient ImmutableSortedMultiset<E> forward; 26 27 DescendingImmutableSortedMultiset(ImmutableSortedMultiset<E> forward) { 28 super(forward.reverseComparator()); 29 this.forward = forward; 30 } 31 32 @Override 33 public int count(@Nullable Object element) { 34 return forward.count(element); 35 } 36 37 @Override 38 public Entry<E> firstEntry() { 39 return forward.lastEntry(); 40 } 41 42 @Override 43 public Entry<E> lastEntry() { 44 return forward.firstEntry(); 45 } 46 47 @Override 48 public int size() { 49 return forward.size(); 50 } 51 52 @Override 53 ImmutableSortedSet<E> createElementSet() { 54 return forward.createDescendingElementSet(); 55 } 56 57 @Override 58 ImmutableSortedSet<E> createDescendingElementSet() { 59 return forward.elementSet(); 60 } 61 62 @Override 63 UnmodifiableIterator<Entry<E>> descendingEntryIterator() { 64 return forward.entryIterator(); 65 } 66 67 @Override 68 public ImmutableSortedMultiset<E> descendingMultiset() { 69 return forward; 70 } 71 72 @Override 73 public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) { 74 return forward.tailMultiset(upperBound, boundType).descendingMultiset(); 75 } 76 77 @Override 78 public ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) { 79 return forward.headMultiset(lowerBound, boundType).descendingMultiset(); 80 } 81 82 @Override 83 UnmodifiableIterator<Entry<E>> entryIterator() { 84 return forward.descendingEntryIterator(); 85 } 86 87 @Override 88 int distinctElements() { 89 return forward.distinctElements(); 90 } 91 92 @Override 93 boolean isPartialView() { 94 return forward.isPartialView(); 95 } 96} 97