Coverage Summary for Class: ImmutableSortedMultisetFauxverideShim (com.google.common.collect)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| ImmutableSortedMultisetFauxverideShim | 100% (1/1) | 9.1% (1/11) | 9.1% (1/11) |
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 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 * express or implied. See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 package com.google.common.collect; 16 17 import com.google.common.annotations.GwtIncompatible; 18 import com.google.errorprone.annotations.DoNotCall; 19 import java.util.function.Function; 20 import java.util.function.ToIntFunction; 21 import java.util.stream.Collector; 22 import org.checkerframework.checker.nullness.qual.Nullable; 23 24 /** 25 * "Overrides" the {@link ImmutableMultiset} static methods that lack {@link 26 * ImmutableSortedMultiset} equivalents with deprecated, exception-throwing versions. This prevents 27 * accidents like the following: 28 * 29 * <pre>{@code 30 * List<Object> objects = ...; 31 * // Sort them: 32 * Set<Object> sorted = ImmutableSortedMultiset.copyOf(objects); 33 * // BAD CODE! The returned multiset is actually an unsorted ImmutableMultiset! 34 * }</pre> 35 * 36 * <p>While we could put the overrides in {@link ImmutableSortedMultiset} itself, it seems clearer 37 * to separate these "do not call" methods from those intended for normal use. 38 * 39 * @author Louis Wasserman 40 */ 41 @GwtIncompatible 42 @ElementTypesAreNonnullByDefault 43 abstract class ImmutableSortedMultisetFauxverideShim<E> extends ImmutableMultiset<E> { 44 /** 45 * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This 46 * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of 47 * {@code ImmutableSortedMultiset}. 48 * 49 * @throws UnsupportedOperationException always 50 * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. 51 * @since 21.0 52 */ 53 @DoNotCall("Use toImmutableSortedMultiset.") 54 @Deprecated 55 public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() { 56 throw new UnsupportedOperationException(); 57 } 58 59 /** 60 * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This 61 * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of 62 * {@code ImmutableSortedMultiset}. 63 * 64 * @throws UnsupportedOperationException always 65 * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. 66 * @since 22.0 67 */ 68 @DoNotCall("Use toImmutableSortedMultiset.") 69 @Deprecated 70 public static <T extends @Nullable Object, E> 71 Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset( 72 Function<? super T, ? extends E> elementFunction, 73 ToIntFunction<? super T> countFunction) { 74 throw new UnsupportedOperationException(); 75 } 76 77 /** 78 * Not supported. Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better 79 * type-safety, instead. This method exists only to hide {@link ImmutableMultiset#builder} from 80 * consumers of {@code ImmutableSortedMultiset}. 81 * 82 * @throws UnsupportedOperationException always 83 * @deprecated Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better type-safety. 84 */ 85 @DoNotCall("Use naturalOrder.") 86 @Deprecated 87 public static <E> ImmutableSortedMultiset.Builder<E> builder() { 88 throw new UnsupportedOperationException(); 89 } 90 91 /** 92 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 93 * Comparable} element.</b> Proper calls will resolve to the version in {@code 94 * ImmutableSortedMultiset}, not this dummy version. 95 * 96 * @throws UnsupportedOperationException always 97 * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link 98 * ImmutableSortedMultiset#of(Comparable)}.</b> 99 */ 100 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 101 @Deprecated 102 public static <E> ImmutableSortedMultiset<E> of(E element) { 103 throw new UnsupportedOperationException(); 104 } 105 106 /** 107 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 108 * Comparable} element.</b> Proper calls will resolve to the version in {@code 109 * ImmutableSortedMultiset}, not this dummy version. 110 * 111 * @throws UnsupportedOperationException always 112 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 113 * ImmutableSortedMultiset#of(Comparable, Comparable)}.</b> 114 */ 115 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 116 @Deprecated 117 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) { 118 throw new UnsupportedOperationException(); 119 } 120 121 /** 122 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 123 * Comparable} element.</b> Proper calls will resolve to the version in {@code 124 * ImmutableSortedMultiset}, not this dummy version. 125 * 126 * @throws UnsupportedOperationException always 127 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 128 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable)}.</b> 129 */ 130 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 131 @Deprecated 132 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { 133 throw new UnsupportedOperationException(); 134 } 135 136 /** 137 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 138 * Comparable} element.</b> Proper calls will resolve to the version in {@code 139 * ImmutableSortedMultiset}, not this dummy version. 140 * 141 * @throws UnsupportedOperationException always 142 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 143 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable)}. </b> 144 */ 145 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 146 @Deprecated 147 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) { 148 throw new UnsupportedOperationException(); 149 } 150 151 /** 152 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 153 * Comparable} element.</b> Proper calls will resolve to the version in {@code 154 * ImmutableSortedMultiset}, not this dummy version. 155 * 156 * @throws UnsupportedOperationException always 157 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 158 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable)} . 159 * </b> 160 */ 161 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 162 @Deprecated 163 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) { 164 throw new UnsupportedOperationException(); 165 } 166 167 /** 168 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 169 * Comparable} element.</b> Proper calls will resolve to the version in {@code 170 * ImmutableSortedMultiset}, not this dummy version. 171 * 172 * @throws UnsupportedOperationException always 173 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 174 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable, 175 * Comparable, Comparable...)} . </b> 176 */ 177 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 178 @Deprecated 179 public static <E> ImmutableSortedMultiset<E> of( 180 E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { 181 throw new UnsupportedOperationException(); 182 } 183 184 /** 185 * Not supported. <b>You are attempting to create a multiset that may contain non-{@code 186 * Comparable} elements.</b> Proper calls will resolve to the version in {@code 187 * ImmutableSortedMultiset}, not this dummy version. 188 * 189 * @throws UnsupportedOperationException always 190 * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link 191 * ImmutableSortedMultiset#copyOf(Comparable[])}.</b> 192 */ 193 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 194 @Deprecated 195 public static <E> ImmutableSortedMultiset<E> copyOf(E[] elements) { 196 throw new UnsupportedOperationException(); 197 } 198 199 /* 200 * We would like to include an unsupported "<E> copyOf(Iterable<E>)" here, providing only the 201 * properly typed "<E extends Comparable<E>> copyOf(Iterable<E>)" in ImmutableSortedMultiset (and 202 * likewise for the Iterator equivalent). However, due to a change in Sun's interpretation of the 203 * JLS (as described at http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler 204 * available as of this writing rejects our attempts. To maintain compatibility with that version 205 * and with any other compilers that interpret the JLS similarly, there is no definition of 206 * copyOf() here, and the definition in ImmutableSortedMultiset matches that in 207 * ImmutableMultiset. 208 * 209 * The result is that ImmutableSortedMultiset.copyOf() may be called on non-Comparable elements. 210 * We have not discovered a better solution. In retrospect, the static factory methods should 211 * have gone in a separate class so that ImmutableSortedMultiset wouldn't "inherit" 212 * too-permissive factory methods from ImmutableMultiset. 213 */ 214 }