Coverage Summary for Class: DescendingMultiset (com.google.common.collect)
| Class | Method, % | Line, % |
|---|---|---|
| DescendingMultiset | 0% (0/18) | 0% (0/27) |
| DescendingMultiset$1EntrySetImpl | 0% (0/4) | 0% (0/4) |
| Total | 0% (0/22) | 0% (0/31) |
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.annotations.GwtCompatible; 20 import com.google.j2objc.annotations.WeakOuter; 21 import java.util.Comparator; 22 import java.util.Iterator; 23 import java.util.NavigableSet; 24 import java.util.Set; 25 import javax.annotation.CheckForNull; 26 import org.checkerframework.checker.nullness.qual.Nullable; 27 28 /** 29 * A skeleton implementation of a descending multiset. Only needs {@code forwardMultiset()} and 30 * {@code entryIterator()}. 31 * 32 * @author Louis Wasserman 33 */ 34 @GwtCompatible(emulated = true) 35 @ElementTypesAreNonnullByDefault 36 abstract class DescendingMultiset<E extends @Nullable Object> extends ForwardingMultiset<E> 37 implements SortedMultiset<E> { 38 abstract SortedMultiset<E> forwardMultiset(); 39 40 @CheckForNull private transient Comparator<? super E> comparator; 41 42 @Override 43 public Comparator<? super E> comparator() { 44 Comparator<? super E> result = comparator; 45 if (result == null) { 46 return comparator = Ordering.from(forwardMultiset().comparator()).<E>reverse(); 47 } 48 return result; 49 } 50 51 @CheckForNull private transient NavigableSet<E> elementSet; 52 53 @Override 54 public NavigableSet<E> elementSet() { 55 NavigableSet<E> result = elementSet; 56 if (result == null) { 57 return elementSet = new SortedMultisets.NavigableElementSet<E>(this); 58 } 59 return result; 60 } 61 62 @Override 63 @CheckForNull 64 public Entry<E> pollFirstEntry() { 65 return forwardMultiset().pollLastEntry(); 66 } 67 68 @Override 69 @CheckForNull 70 public Entry<E> pollLastEntry() { 71 return forwardMultiset().pollFirstEntry(); 72 } 73 74 @Override 75 public SortedMultiset<E> headMultiset(@ParametricNullness E toElement, BoundType boundType) { 76 return forwardMultiset().tailMultiset(toElement, boundType).descendingMultiset(); 77 } 78 79 @Override 80 public SortedMultiset<E> subMultiset( 81 @ParametricNullness E fromElement, 82 BoundType fromBoundType, 83 @ParametricNullness E toElement, 84 BoundType toBoundType) { 85 return forwardMultiset() 86 .subMultiset(toElement, toBoundType, fromElement, fromBoundType) 87 .descendingMultiset(); 88 } 89 90 @Override 91 public SortedMultiset<E> tailMultiset(@ParametricNullness E fromElement, BoundType boundType) { 92 return forwardMultiset().headMultiset(fromElement, boundType).descendingMultiset(); 93 } 94 95 @Override 96 protected Multiset<E> delegate() { 97 return forwardMultiset(); 98 } 99 100 @Override 101 public SortedMultiset<E> descendingMultiset() { 102 return forwardMultiset(); 103 } 104 105 @Override 106 @CheckForNull 107 public Entry<E> firstEntry() { 108 return forwardMultiset().lastEntry(); 109 } 110 111 @Override 112 @CheckForNull 113 public Entry<E> lastEntry() { 114 return forwardMultiset().firstEntry(); 115 } 116 117 abstract Iterator<Entry<E>> entryIterator(); 118 119 @CheckForNull private transient Set<Entry<E>> entrySet; 120 121 @Override 122 public Set<Entry<E>> entrySet() { 123 Set<Entry<E>> result = entrySet; 124 return (result == null) ? entrySet = createEntrySet() : result; 125 } 126 127 Set<Entry<E>> createEntrySet() { 128 @WeakOuter 129 class EntrySetImpl extends Multisets.EntrySet<E> { 130 @Override 131 Multiset<E> multiset() { 132 return DescendingMultiset.this; 133 } 134 135 @Override 136 public Iterator<Entry<E>> iterator() { 137 return entryIterator(); 138 } 139 140 @Override 141 public int size() { 142 return forwardMultiset().entrySet().size(); 143 } 144 } 145 return new EntrySetImpl(); 146 } 147 148 @Override 149 public Iterator<E> iterator() { 150 return Multisets.iteratorImpl(this); 151 } 152 153 @Override 154 public @Nullable Object[] toArray() { 155 return standardToArray(); 156 } 157 158 @Override 159 /* 160 * Our checker says "found: T[]; required: T[]." That sounds bogus. I discuss a possible reason 161 * for this error in https://github.com/jspecify/checker-framework/issues/10. 162 */ 163 @SuppressWarnings("nullness") 164 public <T extends @Nullable Object> T[] toArray(T[] array) { 165 return standardToArray(array); 166 } 167 168 @Override 169 public String toString() { 170 return entrySet().toString(); 171 } 172 }