PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/guava25/collect/ImmutableSortedMultisetFauxverideShim.java

http://github.com/WindowsAzure/azure-sdk-for-java
Java | 202 lines | 49 code | 14 blank | 139 comment | 0 complexity | 22ffad0dc706cecc19ac0a2481b871e9 MD5 | raw file
Possible License(s): MIT
  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. * Portions Copyright (c) Microsoft Corporation
  16. */
  17. package com.azure.cosmos.implementation.guava25.collect;
  18. import java.util.function.Function;
  19. import java.util.function.ToIntFunction;
  20. import java.util.stream.Collector;
  21. /**
  22. * "Overrides" the {@link ImmutableMultiset} static methods that lack {@link
  23. * ImmutableSortedMultiset} equivalents with deprecated, exception-throwing versions. This prevents
  24. * accidents like the following:
  25. *
  26. * <pre>{@code
  27. * List<Object> objects = ...;
  28. * // Sort them:
  29. * Set<Object> sorted = ImmutableSortedMultiset.copyOf(objects);
  30. * // BAD CODE! The returned multiset is actually an unsorted ImmutableMultiset!
  31. * }</pre>
  32. *
  33. * <p>While we could put the overrides in {@link ImmutableSortedMultiset} itself, it seems clearer
  34. * to separate these "do not call" methods from those intended for normal use.
  35. *
  36. * @author Louis Wasserman
  37. */
  38. abstract class ImmutableSortedMultisetFauxverideShim<E> extends ImmutableMultiset<E> {
  39. /**
  40. * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This
  41. * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of
  42. * {@code ImmutableSortedMultiset}.
  43. *
  44. * @throws UnsupportedOperationException always
  45. * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}.
  46. * @since 21.0
  47. */
  48. @Deprecated
  49. public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() {
  50. throw new UnsupportedOperationException();
  51. }
  52. /**
  53. * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This
  54. * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of
  55. * {@code ImmutableSortedMultiset}.
  56. *
  57. * @throws UnsupportedOperationException always
  58. * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}.
  59. * @since 22.0
  60. */
  61. @Deprecated
  62. public static <T, E> Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset(
  63. Function<? super T, ? extends E> elementFunction, ToIntFunction<? super T> countFunction) {
  64. throw new UnsupportedOperationException();
  65. }
  66. /**
  67. * Not supported. Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better
  68. * type-safety, instead. This method exists only to hide {@link ImmutableMultiset#builder} from
  69. * consumers of {@code ImmutableSortedMultiset}.
  70. *
  71. * @throws UnsupportedOperationException always
  72. * @deprecated Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better type-safety.
  73. */
  74. @Deprecated
  75. public static <E> ImmutableSortedMultiset.Builder<E> builder() {
  76. throw new UnsupportedOperationException();
  77. }
  78. /**
  79. * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code
  80. * Comparable} element.</b> Proper calls will resolve to the version in {@code
  81. * ImmutableSortedMultiset}, not this dummy version.
  82. *
  83. * @throws UnsupportedOperationException always
  84. * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link
  85. * ImmutableSortedMultiset#of(Comparable)}.</b>
  86. */
  87. @Deprecated
  88. public static <E> ImmutableSortedMultiset<E> of(E element) {
  89. throw new UnsupportedOperationException();
  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 the parameters of type {@code Comparable} to use {@link
  98. * ImmutableSortedMultiset#of(Comparable, Comparable)}.</b>
  99. */
  100. @Deprecated
  101. public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) {
  102. throw new UnsupportedOperationException();
  103. }
  104. /**
  105. * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code
  106. * Comparable} element.</b> Proper calls will resolve to the version in {@code
  107. * ImmutableSortedMultiset}, not this dummy version.
  108. *
  109. * @throws UnsupportedOperationException always
  110. * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
  111. * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable)}.</b>
  112. */
  113. @Deprecated
  114. public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) {
  115. throw new UnsupportedOperationException();
  116. }
  117. /**
  118. * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code
  119. * Comparable} element.</b> Proper calls will resolve to the version in {@code
  120. * ImmutableSortedMultiset}, not this dummy version.
  121. *
  122. * @throws UnsupportedOperationException always
  123. * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
  124. * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable)}. </b>
  125. */
  126. @Deprecated
  127. public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) {
  128. throw new UnsupportedOperationException();
  129. }
  130. /**
  131. * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code
  132. * Comparable} element.</b> Proper calls will resolve to the version in {@code
  133. * ImmutableSortedMultiset}, not this dummy version.
  134. *
  135. * @throws UnsupportedOperationException always
  136. * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
  137. * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable)} .
  138. * </b>
  139. */
  140. @Deprecated
  141. public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) {
  142. throw new UnsupportedOperationException();
  143. }
  144. /**
  145. * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code
  146. * Comparable} element.</b> Proper calls will resolve to the version in {@code
  147. * ImmutableSortedMultiset}, not this dummy version.
  148. *
  149. * @throws UnsupportedOperationException always
  150. * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
  151. * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable,
  152. * Comparable, Comparable...)} . </b>
  153. */
  154. @SuppressWarnings("unchecked")
  155. @Deprecated
  156. public static <E> ImmutableSortedMultiset<E> of(
  157. E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) {
  158. throw new UnsupportedOperationException();
  159. }
  160. /**
  161. * Not supported. <b>You are attempting to create a multiset that may contain non-{@code
  162. * Comparable} elements.</b> Proper calls will resolve to the version in {@code
  163. * ImmutableSortedMultiset}, not this dummy version.
  164. *
  165. * @throws UnsupportedOperationException always
  166. * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link
  167. * ImmutableSortedMultiset#copyOf(Comparable[])}.</b>
  168. */
  169. @Deprecated
  170. public static <E> ImmutableSortedMultiset<E> copyOf(E[] elements) {
  171. throw new UnsupportedOperationException();
  172. }
  173. /*
  174. * We would like to include an unsupported "<E> copyOf(Iterable<E>)" here, providing only the
  175. * properly typed "<E extends Comparable<E>> copyOf(Iterable<E>)" in ImmutableSortedMultiset (and
  176. * likewise for the Iterator equivalent). However, due to a change in Sun's interpretation of the
  177. * JLS (as described at http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler
  178. * available as of this writing rejects our attempts. To maintain compatibility with that version
  179. * and with any other compilers that interpret the JLS similarly, there is no definition of
  180. * copyOf() here, and the definition in ImmutableSortedMultiset matches that in
  181. * ImmutableMultiset.
  182. *
  183. * The result is that ImmutableSortedMultiset.copyOf() may be called on non-Comparable elements.
  184. * We have not discovered a better solution. In retrospect, the static factory methods should
  185. * have gone in a separate class so that ImmutableSortedMultiset wouldn't "inherit"
  186. * too-permissive factory methods from ImmutableMultiset.
  187. */
  188. }