View Javadoc
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  
15  package com.google.common.collect;
16  
17  import com.google.common.annotations.GwtIncompatible;
18  import javax.annotation.Nullable;
19  
20  /**
21   * A descending wrapper around an {@code ImmutableSortedMultiset}
22   *
23   * @author Louis Wasserman
24   */
25  @SuppressWarnings("serial") // uses writeReplace, not default serialization
26  @GwtIncompatible
27  final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E> {
28    private final transient ImmutableSortedMultiset<E> forward;
29  
30    DescendingImmutableSortedMultiset(ImmutableSortedMultiset<E> forward) {
31      this.forward = forward;
32    }
33  
34    @Override
35    public int count(@Nullable Object element) {
36      return forward.count(element);
37    }
38  
39    @Override
40    public Entry<E> firstEntry() {
41      return forward.lastEntry();
42    }
43  
44    @Override
45    public Entry<E> lastEntry() {
46      return forward.firstEntry();
47    }
48  
49    @Override
50    public int size() {
51      return forward.size();
52    }
53  
54    @Override
55    public ImmutableSortedSet<E> elementSet() {
56      return forward.elementSet().descendingSet();
57    }
58  
59    @Override
60    Entry<E> getEntry(int index) {
61      return forward.entrySet().asList().reverse().get(index);
62    }
63  
64    @Override
65    public ImmutableSortedMultiset<E> descendingMultiset() {
66      return forward;
67    }
68  
69    @Override
70    public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) {
71      return forward.tailMultiset(upperBound, boundType).descendingMultiset();
72    }
73  
74    @Override
75    public ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) {
76      return forward.headMultiset(lowerBound, boundType).descendingMultiset();
77    }
78  
79    @Override
80    boolean isPartialView() {
81      return forward.isPartialView();
82    }
83  }