001/* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the 010 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 011 * express or implied. See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package com.google.common.collect; 016 017import static com.google.common.base.Preconditions.checkArgument; 018import static com.google.common.base.Preconditions.checkNotNull; 019import static com.google.common.collect.Lists.newArrayList; 020import static com.google.common.collect.Lists.newArrayListWithCapacity; 021 022import com.google.common.annotations.GwtIncompatible; 023import com.google.common.annotations.J2ktIncompatible; 024import com.google.errorprone.annotations.CanIgnoreReturnValue; 025import com.google.errorprone.annotations.DoNotCall; 026import com.google.errorprone.annotations.concurrent.LazyInit; 027import java.io.InvalidObjectException; 028import java.io.ObjectInputStream; 029import java.io.Serializable; 030import java.util.ArrayList; 031import java.util.Arrays; 032import java.util.Collection; 033import java.util.Collections; 034import java.util.Comparator; 035import java.util.Iterator; 036import java.util.List; 037import java.util.function.Function; 038import java.util.function.ToIntFunction; 039import java.util.stream.Collector; 040import org.jspecify.annotations.Nullable; 041 042/** 043 * A {@link SortedMultiset} whose contents will never change, with many other important properties 044 * detailed at {@link ImmutableCollection}. 045 * 046 * <p><b>Warning:</b> as with any sorted collection, you are strongly advised not to use a {@link 047 * Comparator} or {@link Comparable} type whose comparison behavior is <i>inconsistent with 048 * equals</i>. That is, {@code a.compareTo(b)} or {@code comparator.compare(a, b)} should equal zero 049 * <i>if and only if</i> {@code a.equals(b)}. If this advice is not followed, the resulting 050 * collection will not correctly obey its specification. 051 * 052 * <p>See the Guava User Guide article on <a href= 053 * "https://github.com/google/guava/wiki/ImmutableCollectionsExplained">immutable collections</a>. 054 * 055 * @author Louis Wasserman 056 * @since 12.0 057 */ 058@GwtIncompatible // hasn't been tested yet 059public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E> 060 implements SortedMultiset<E> { 061 // TODO(lowasser): GWT compatibility 062 063 /** 064 * Returns a {@code Collector} that accumulates the input elements into a new {@code 065 * ImmutableMultiset}. Elements are sorted by the specified comparator. 066 * 067 * <p><b>Warning:</b> {@code comparator} should be <i>consistent with {@code equals}</i> as 068 * explained in the {@link Comparator} documentation. 069 * 070 * @since 21.0 071 */ 072 public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( 073 Comparator<? super E> comparator) { 074 return toImmutableSortedMultiset(comparator, Function.identity(), e -> 1); 075 } 076 077 /** 078 * Returns a {@code Collector} that accumulates elements into an {@code ImmutableSortedMultiset} 079 * whose elements are the result of applying {@code elementFunction} to the inputs, with counts 080 * equal to the result of applying {@code countFunction} to the inputs. 081 * 082 * <p>If the mapped elements contain duplicates (according to {@code comparator}), the first 083 * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of 084 * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element. 085 * 086 * @since 22.0 087 */ 088 public static <T extends @Nullable Object, E> 089 Collector<T, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( 090 Comparator<? super E> comparator, 091 Function<? super T, ? extends E> elementFunction, 092 ToIntFunction<? super T> countFunction) { 093 checkNotNull(comparator); 094 checkNotNull(elementFunction); 095 checkNotNull(countFunction); 096 return Collector.of( 097 () -> TreeMultiset.create(comparator), 098 (multiset, t) -> 099 multiset.add(checkNotNull(elementFunction.apply(t)), countFunction.applyAsInt(t)), 100 (multiset1, multiset2) -> { 101 multiset1.addAll(multiset2); 102 return multiset1; 103 }, 104 (Multiset<E> multiset) -> copyOfSortedEntries(comparator, multiset.entrySet())); 105 } 106 107 /** 108 * Returns the empty immutable sorted multiset. 109 * 110 * <p><b>Performance note:</b> the instance returned is a singleton. 111 */ 112 @SuppressWarnings("unchecked") 113 public static <E> ImmutableSortedMultiset<E> of() { 114 return (ImmutableSortedMultiset) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET; 115 } 116 117 /** Returns an immutable sorted multiset containing a single element. */ 118 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1) { 119 RegularImmutableSortedSet<E> elementSet = 120 (RegularImmutableSortedSet<E>) ImmutableSortedSet.of(e1); 121 long[] cumulativeCounts = {0, 1}; 122 return new RegularImmutableSortedMultiset<>(elementSet, cumulativeCounts, 0, 1); 123 } 124 125 /** 126 * Returns an immutable sorted multiset containing the given elements sorted by their natural 127 * ordering. 128 * 129 * @throws NullPointerException if any element is null 130 */ 131 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2) { 132 return copyOf(Ordering.natural(), Arrays.asList(e1, e2)); 133 } 134 135 /** 136 * Returns an immutable sorted multiset containing the given elements sorted by their natural 137 * ordering. 138 * 139 * @throws NullPointerException if any element is null 140 */ 141 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { 142 return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3)); 143 } 144 145 /** 146 * Returns an immutable sorted multiset containing the given elements sorted by their natural 147 * ordering. 148 * 149 * @throws NullPointerException if any element is null 150 */ 151 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( 152 E e1, E e2, E e3, E e4) { 153 return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3, e4)); 154 } 155 156 /** 157 * Returns an immutable sorted multiset containing the given elements sorted by their natural 158 * ordering. 159 * 160 * @throws NullPointerException if any element is null 161 */ 162 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( 163 E e1, E e2, E e3, E e4, E e5) { 164 return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3, e4, e5)); 165 } 166 167 /** 168 * Returns an immutable sorted multiset containing the given elements sorted by their natural 169 * ordering. 170 * 171 * @throws NullPointerException if any element is null 172 */ 173 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( 174 E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { 175 int size = remaining.length + 6; 176 List<E> all = newArrayListWithCapacity(size); 177 Collections.addAll(all, e1, e2, e3, e4, e5, e6); 178 Collections.addAll(all, remaining); 179 return copyOf(Ordering.natural(), all); 180 } 181 182 /** 183 * Returns an immutable sorted multiset containing the given elements sorted by their natural 184 * ordering. 185 * 186 * @throws NullPointerException if any of {@code elements} is null 187 */ 188 public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> copyOf(E[] elements) { 189 return copyOf(Ordering.natural(), Arrays.asList(elements)); 190 } 191 192 /** 193 * Returns an immutable sorted multiset containing the given elements sorted by their natural 194 * ordering. To create a copy of a {@code SortedMultiset} that preserves the comparator, call 195 * {@link #copyOfSorted} instead. This method iterates over {@code elements} at most once. 196 * 197 * <p>Note that if {@code s} is a {@code Multiset<String>}, then {@code 198 * ImmutableSortedMultiset.copyOf(s)} returns an {@code ImmutableSortedMultiset<String>} 199 * containing each of the strings in {@code s}, while {@code ImmutableSortedMultiset.of(s)} 200 * returns an {@code ImmutableSortedMultiset<Multiset<String>>} containing one element (the given 201 * multiset itself). 202 * 203 * <p>Despite the method name, this method attempts to avoid actually copying the data when it is 204 * safe to do so. The exact circumstances under which a copy will or will not be performed are 205 * undocumented and subject to change. 206 * 207 * <p>This method is not type-safe, as it may be called on elements that are not mutually 208 * comparable. 209 * 210 * @throws ClassCastException if the elements are not mutually comparable 211 * @throws NullPointerException if any of {@code elements} is null 212 */ 213 public static <E> ImmutableSortedMultiset<E> copyOf(Iterable<? extends E> elements) { 214 // Hack around E not being a subtype of Comparable. 215 // Unsafe, see ImmutableSortedMultisetFauxverideShim. 216 @SuppressWarnings("unchecked") 217 Ordering<E> naturalOrder = (Ordering<E>) Ordering.<Comparable<?>>natural(); 218 return copyOf(naturalOrder, elements); 219 } 220 221 /** 222 * Returns an immutable sorted multiset containing the given elements sorted by their natural 223 * ordering. 224 * 225 * <p>This method is not type-safe, as it may be called on elements that are not mutually 226 * comparable. 227 * 228 * @throws ClassCastException if the elements are not mutually comparable 229 * @throws NullPointerException if any of {@code elements} is null 230 */ 231 public static <E> ImmutableSortedMultiset<E> copyOf(Iterator<? extends E> elements) { 232 // Hack around E not being a subtype of Comparable. 233 // Unsafe, see ImmutableSortedMultisetFauxverideShim. 234 @SuppressWarnings("unchecked") 235 Ordering<E> naturalOrder = (Ordering<E>) Ordering.<Comparable<?>>natural(); 236 return copyOf(naturalOrder, elements); 237 } 238 239 /** 240 * Returns an immutable sorted multiset containing the given elements sorted by the given {@code 241 * Comparator}. 242 * 243 * @throws NullPointerException if {@code comparator} or any of {@code elements} is null 244 */ 245 public static <E> ImmutableSortedMultiset<E> copyOf( 246 Comparator<? super E> comparator, Iterator<? extends E> elements) { 247 checkNotNull(comparator); 248 return new Builder<E>(comparator).addAll(elements).build(); 249 } 250 251 /** 252 * Returns an immutable sorted multiset containing the given elements sorted by the given {@code 253 * Comparator}. This method iterates over {@code elements} at most once. 254 * 255 * <p>Despite the method name, this method attempts to avoid actually copying the data when it is 256 * safe to do so. The exact circumstances under which a copy will or will not be performed are 257 * undocumented and subject to change. 258 * 259 * @throws NullPointerException if {@code comparator} or any of {@code elements} is null 260 */ 261 public static <E> ImmutableSortedMultiset<E> copyOf( 262 Comparator<? super E> comparator, Iterable<? extends E> elements) { 263 if (elements instanceof ImmutableSortedMultiset) { 264 @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts 265 ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements; 266 if (comparator.equals(multiset.comparator())) { 267 if (multiset.isPartialView()) { 268 return copyOfSortedEntries(comparator, multiset.entrySet().asList()); 269 } else { 270 return multiset; 271 } 272 } 273 } 274 elements = newArrayList(elements); // defensive copy 275 TreeMultiset<E> sortedCopy = TreeMultiset.create(checkNotNull(comparator)); 276 Iterables.addAll(sortedCopy, elements); 277 return copyOfSortedEntries(comparator, sortedCopy.entrySet()); 278 } 279 280 /** 281 * Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by 282 * the same {@code Comparator}. That behavior differs from {@link #copyOf(Iterable)}, which always 283 * uses the natural ordering of the elements. 284 * 285 * <p>Despite the method name, this method attempts to avoid actually copying the data when it is 286 * safe to do so. The exact circumstances under which a copy will or will not be performed are 287 * undocumented and subject to change. 288 * 289 * <p>This method is safe to use even when {@code sortedMultiset} is a synchronized or concurrent 290 * collection that is currently being modified by another thread. 291 * 292 * @throws NullPointerException if {@code sortedMultiset} or any of its elements is null 293 */ 294 public static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset) { 295 return copyOfSortedEntries( 296 sortedMultiset.comparator(), new ArrayList<>(sortedMultiset.entrySet())); 297 } 298 299 private static <E> ImmutableSortedMultiset<E> copyOfSortedEntries( 300 Comparator<? super E> comparator, Collection<Entry<E>> entries) { 301 if (entries.isEmpty()) { 302 return emptyMultiset(comparator); 303 } 304 ImmutableList.Builder<E> elementsBuilder = new ImmutableList.Builder<>(entries.size()); 305 long[] cumulativeCounts = new long[entries.size() + 1]; 306 int i = 0; 307 for (Entry<E> entry : entries) { 308 elementsBuilder.add(entry.getElement()); 309 cumulativeCounts[i + 1] = cumulativeCounts[i] + entry.getCount(); 310 i++; 311 } 312 return new RegularImmutableSortedMultiset<>( 313 new RegularImmutableSortedSet<E>(elementsBuilder.build(), comparator), 314 cumulativeCounts, 315 0, 316 entries.size()); 317 } 318 319 @SuppressWarnings("unchecked") 320 static <E> ImmutableSortedMultiset<E> emptyMultiset(Comparator<? super E> comparator) { 321 if (Ordering.natural().equals(comparator)) { 322 return (ImmutableSortedMultiset<E>) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET; 323 } else { 324 return new RegularImmutableSortedMultiset<>(comparator); 325 } 326 } 327 328 ImmutableSortedMultiset() {} 329 330 @Override 331 public final Comparator<? super E> comparator() { 332 return elementSet().comparator(); 333 } 334 335 @Override 336 public abstract ImmutableSortedSet<E> elementSet(); 337 338 @LazyInit transient @Nullable ImmutableSortedMultiset<E> descendingMultiset; 339 340 @Override 341 public ImmutableSortedMultiset<E> descendingMultiset() { 342 ImmutableSortedMultiset<E> result = descendingMultiset; 343 if (result == null) { 344 result = 345 descendingMultiset = 346 this.isEmpty() 347 ? emptyMultiset(Ordering.from(comparator()).reverse()) 348 : new DescendingImmutableSortedMultiset<E>(this); 349 } 350 return result; 351 } 352 353 /** 354 * {@inheritDoc} 355 * 356 * <p>This implementation is guaranteed to throw an {@link UnsupportedOperationException}. 357 * 358 * @throws UnsupportedOperationException always 359 * @deprecated Unsupported operation. 360 */ 361 @CanIgnoreReturnValue 362 @Deprecated 363 @Override 364 @DoNotCall("Always throws UnsupportedOperationException") 365 public final @Nullable Entry<E> pollFirstEntry() { 366 throw new UnsupportedOperationException(); 367 } 368 369 /** 370 * {@inheritDoc} 371 * 372 * <p>This implementation is guaranteed to throw an {@link UnsupportedOperationException}. 373 * 374 * @throws UnsupportedOperationException always 375 * @deprecated Unsupported operation. 376 */ 377 @CanIgnoreReturnValue 378 @Deprecated 379 @Override 380 @DoNotCall("Always throws UnsupportedOperationException") 381 public final @Nullable Entry<E> pollLastEntry() { 382 throw new UnsupportedOperationException(); 383 } 384 385 @Override 386 public abstract ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType); 387 388 @Override 389 public final ImmutableSortedMultiset<E> subMultiset( 390 E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) { 391 checkArgument( 392 comparator().compare(lowerBound, upperBound) <= 0, 393 "Expected lowerBound <= upperBound but %s > %s", 394 lowerBound, 395 upperBound); 396 return tailMultiset(lowerBound, lowerBoundType).headMultiset(upperBound, upperBoundType); 397 } 398 399 @Override 400 public abstract ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType); 401 402 /** 403 * Returns a builder that creates immutable sorted multisets with an explicit comparator. If the 404 * comparator has a more general type than the set being generated, such as creating a {@code 405 * SortedMultiset<Integer>} with a {@code Comparator<Number>}, use the {@link Builder} constructor 406 * instead. 407 * 408 * @throws NullPointerException if {@code comparator} is null 409 */ 410 public static <E> Builder<E> orderedBy(Comparator<E> comparator) { 411 return new Builder<>(comparator); 412 } 413 414 /** 415 * Returns a builder that creates immutable sorted multisets whose elements are ordered by the 416 * reverse of their natural ordering. 417 * 418 * <p>Note: the type parameter {@code E} extends {@code Comparable<?>} rather than {@code 419 * Comparable<? super E>} in order to accommodate users of obsolete javac versions affected by <a 420 * href="https://bugs.openjdk.org/browse/JDK-6468354">JDK-6468354</a>. 421 */ 422 public static <E extends Comparable<?>> Builder<E> reverseOrder() { 423 return new Builder<>(Ordering.<E>natural().reverse()); 424 } 425 426 /** 427 * Returns a builder that creates immutable sorted multisets whose elements are ordered by their 428 * natural ordering. The sorted multisets use {@link Ordering#natural()} as the comparator. This 429 * method provides more type-safety than {@link #builder}, as it can be called only for classes 430 * that implement {@link Comparable}. 431 * 432 * <p>Note: the type parameter {@code E} extends {@code Comparable<?>} rather than {@code 433 * Comparable<? super E>} in order to accommodate users of obsolete javac versions affected by <a 434 * href="https://bugs.openjdk.org/browse/JDK-6468354">JDK-6468354</a>. 435 */ 436 public static <E extends Comparable<?>> Builder<E> naturalOrder() { 437 return new Builder<>(Ordering.natural()); 438 } 439 440 /** 441 * A builder for creating immutable multiset instances, especially {@code public static final} 442 * multisets ("constant multisets"). Example: 443 * 444 * {@snippet : 445 * public static final ImmutableSortedMultiset<Bean> BEANS = 446 * new ImmutableSortedMultiset.Builder<Bean>(colorComparator()) 447 * .addCopies(Bean.COCOA, 4) 448 * .addCopies(Bean.GARDEN, 6) 449 * .addCopies(Bean.RED, 8) 450 * .addCopies(Bean.BLACK_EYED, 10) 451 * .build(); 452 * } 453 * 454 * <p>Builder instances can be reused; it is safe to call {@link #build} multiple times to build 455 * multiple multisets in series. 456 * 457 * @since 12.0 458 */ 459 public static class Builder<E> extends ImmutableMultiset.Builder<E> { 460 /** 461 * Creates a new builder. The returned builder is equivalent to the builder generated by {@link 462 * ImmutableSortedMultiset#orderedBy(Comparator)}. 463 */ 464 public Builder(Comparator<? super E> comparator) { 465 super(TreeMultiset.create(checkNotNull(comparator))); 466 } 467 468 /** 469 * Adds {@code element} to the {@code ImmutableSortedMultiset}. 470 * 471 * @param element the element to add 472 * @return this {@code Builder} object 473 * @throws NullPointerException if {@code element} is null 474 */ 475 @CanIgnoreReturnValue 476 @Override 477 public Builder<E> add(E element) { 478 super.add(element); 479 return this; 480 } 481 482 /** 483 * Adds each element of {@code elements} to the {@code ImmutableSortedMultiset}. 484 * 485 * @param elements the elements to add 486 * @return this {@code Builder} object 487 * @throws NullPointerException if {@code elements} is null or contains a null element 488 */ 489 @CanIgnoreReturnValue 490 @Override 491 public Builder<E> add(E... elements) { 492 super.add(elements); 493 return this; 494 } 495 496 /** 497 * Adds a number of occurrences of an element to this {@code ImmutableSortedMultiset}. 498 * 499 * @param element the element to add 500 * @param occurrences the number of occurrences of the element to add. May be zero, in which 501 * case no change will be made. 502 * @return this {@code Builder} object 503 * @throws NullPointerException if {@code element} is null 504 * @throws IllegalArgumentException if {@code occurrences} is negative, or if this operation 505 * would result in more than {@link Integer#MAX_VALUE} occurrences of the element 506 */ 507 @CanIgnoreReturnValue 508 @Override 509 public Builder<E> addCopies(E element, int occurrences) { 510 super.addCopies(element, occurrences); 511 return this; 512 } 513 514 /** 515 * Adds or removes the necessary occurrences of an element such that the element attains the 516 * desired count. 517 * 518 * @param element the element to add or remove occurrences of 519 * @param count the desired count of the element in this multiset 520 * @return this {@code Builder} object 521 * @throws NullPointerException if {@code element} is null 522 * @throws IllegalArgumentException if {@code count} is negative 523 */ 524 @CanIgnoreReturnValue 525 @Override 526 public Builder<E> setCount(E element, int count) { 527 super.setCount(element, count); 528 return this; 529 } 530 531 /** 532 * Adds each element of {@code elements} to the {@code ImmutableSortedMultiset}. 533 * 534 * @param elements the {@code Iterable} to add to the {@code ImmutableSortedMultiset} 535 * @return this {@code Builder} object 536 * @throws NullPointerException if {@code elements} is null or contains a null element 537 */ 538 @CanIgnoreReturnValue 539 @Override 540 public Builder<E> addAll(Iterable<? extends E> elements) { 541 super.addAll(elements); 542 return this; 543 } 544 545 /** 546 * Adds each element of {@code elements} to the {@code ImmutableSortedMultiset}. 547 * 548 * @param elements the elements to add to the {@code ImmutableSortedMultiset} 549 * @return this {@code Builder} object 550 * @throws NullPointerException if {@code elements} is null or contains a null element 551 */ 552 @CanIgnoreReturnValue 553 @Override 554 public Builder<E> addAll(Iterator<? extends E> elements) { 555 super.addAll(elements); 556 return this; 557 } 558 559 /** 560 * Returns a newly-created {@code ImmutableSortedMultiset} based on the contents of the {@code 561 * Builder}. 562 */ 563 @Override 564 public ImmutableSortedMultiset<E> build() { 565 return copyOfSorted((SortedMultiset<E>) contents); 566 } 567 } 568 569 @J2ktIncompatible // serialization 570 private static final class SerializedForm<E> implements Serializable { 571 final Comparator<? super E> comparator; 572 final E[] elements; 573 final int[] counts; 574 575 @SuppressWarnings("unchecked") 576 SerializedForm(SortedMultiset<E> multiset) { 577 this.comparator = multiset.comparator(); 578 int n = multiset.entrySet().size(); 579 elements = (E[]) new Object[n]; 580 counts = new int[n]; 581 int i = 0; 582 for (Entry<E> entry : multiset.entrySet()) { 583 elements[i] = entry.getElement(); 584 counts[i] = entry.getCount(); 585 i++; 586 } 587 } 588 589 Object readResolve() { 590 int n = elements.length; 591 Builder<E> builder = new Builder<>(comparator); 592 for (int i = 0; i < n; i++) { 593 builder.addCopies(elements[i], counts[i]); 594 } 595 return builder.build(); 596 } 597 } 598 599 @Override 600 @J2ktIncompatible // serialization 601 Object writeReplace() { 602 return new SerializedForm<E>(this); 603 } 604 605 @J2ktIncompatible // java.io.ObjectInputStream 606 private void readObject(ObjectInputStream stream) throws InvalidObjectException { 607 throw new InvalidObjectException("Use SerializedForm"); 608 } 609 610 /** 611 * Not supported. Use {@link #toImmutableSortedMultiset} instead. This method exists only to hide 612 * {@link ImmutableMultiset#toImmutableMultiset} from consumers of {@code 613 * ImmutableSortedMultiset}. 614 * 615 * @throws UnsupportedOperationException always 616 * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. 617 * @since 21.0 618 */ 619 @DoNotCall("Use toImmutableSortedMultiset.") 620 @Deprecated 621 public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() { 622 throw new UnsupportedOperationException(); 623 } 624 625 /** 626 * Not supported. Use {@link #toImmutableSortedMultiset} instead. This method exists only to hide 627 * {@link ImmutableMultiset#toImmutableMultiset} from consumers of {@code 628 * ImmutableSortedMultiset}. 629 * 630 * @throws UnsupportedOperationException always 631 * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. 632 * @since 22.0 633 */ 634 @DoNotCall("Use toImmutableSortedMultiset.") 635 @Deprecated 636 public static <T extends @Nullable Object, E> 637 Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset( 638 Function<? super T, ? extends E> elementFunction, 639 ToIntFunction<? super T> countFunction) { 640 throw new UnsupportedOperationException(); 641 } 642 643 /** 644 * Not supported. Use {@link #naturalOrder}, which offers better type-safety, instead. This method 645 * exists only to hide {@link ImmutableMultiset#builder} from consumers of {@code 646 * ImmutableSortedMultiset}. 647 * 648 * @throws UnsupportedOperationException always 649 * @deprecated Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better type-safety. 650 */ 651 @DoNotCall("Use naturalOrder.") 652 @Deprecated 653 public static <E> ImmutableSortedMultiset.Builder<E> builder() { 654 throw new UnsupportedOperationException(); 655 } 656 657 /** 658 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 659 * Comparable} element.</b> Proper calls will resolve to the version in {@code 660 * ImmutableSortedMultiset}, not this dummy version. 661 * 662 * @throws UnsupportedOperationException always 663 * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link 664 * ImmutableSortedMultiset#of(Comparable)}.</b> 665 */ 666 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 667 @Deprecated 668 public static <E> ImmutableSortedMultiset<E> of(E e1) { 669 throw new UnsupportedOperationException(); 670 } 671 672 /** 673 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 674 * Comparable} element.</b> Proper calls will resolve to the version in {@code 675 * ImmutableSortedMultiset}, not this dummy version. 676 * 677 * @throws UnsupportedOperationException always 678 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 679 * ImmutableSortedMultiset#of(Comparable, Comparable)}.</b> 680 */ 681 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 682 @Deprecated 683 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) { 684 throw new UnsupportedOperationException(); 685 } 686 687 /** 688 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 689 * Comparable} element.</b> Proper calls will resolve to the version in {@code 690 * ImmutableSortedMultiset}, not this dummy version. 691 * 692 * @throws UnsupportedOperationException always 693 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 694 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable)}.</b> 695 */ 696 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 697 @Deprecated 698 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { 699 throw new UnsupportedOperationException(); 700 } 701 702 /** 703 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 704 * Comparable} element.</b> Proper calls will resolve to the version in {@code 705 * ImmutableSortedMultiset}, not this dummy version. 706 * 707 * @throws UnsupportedOperationException always 708 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 709 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable)}. </b> 710 */ 711 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 712 @Deprecated 713 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) { 714 throw new UnsupportedOperationException(); 715 } 716 717 /** 718 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 719 * Comparable} element.</b> Proper calls will resolve to the version in {@code 720 * ImmutableSortedMultiset}, not this dummy version. 721 * 722 * @throws UnsupportedOperationException always 723 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 724 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable)} . 725 * </b> 726 */ 727 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 728 @Deprecated 729 public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) { 730 throw new UnsupportedOperationException(); 731 } 732 733 /** 734 * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code 735 * Comparable} element.</b> Proper calls will resolve to the version in {@code 736 * ImmutableSortedMultiset}, not this dummy version. 737 * 738 * @throws UnsupportedOperationException always 739 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 740 * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable, 741 * Comparable, Comparable...)} . </b> 742 */ 743 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 744 @Deprecated 745 public static <E> ImmutableSortedMultiset<E> of( 746 E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { 747 throw new UnsupportedOperationException(); 748 } 749 750 /** 751 * Not supported. <b>You are attempting to create a multiset that may contain non-{@code 752 * Comparable} elements.</b> Proper calls will resolve to the version in {@code 753 * ImmutableSortedMultiset}, not this dummy version. 754 * 755 * @throws UnsupportedOperationException always 756 * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link 757 * ImmutableSortedMultiset#copyOf(Comparable[])}.</b> 758 */ 759 @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") 760 @Deprecated 761 // The usage of "Z" here works around bugs in Javadoc (JDK-8318093) and JDiff. 762 public static <Z> ImmutableSortedMultiset<Z> copyOf(Z[] elements) { 763 throw new UnsupportedOperationException(); 764 } 765 766 @J2ktIncompatible private static final long serialVersionUID = 0xcafebabe; 767}