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