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 public static <E> ImmutableSortedSet.Builder<E> builder() { 49 throw new UnsupportedOperationException(); 50 } 51 52 /** 53 * Not supported. <b>You are attempting to create a set that may contain a 54 * non-{@code Comparable} element.</b> Proper calls will resolve to the 55 * version in {@code ImmutableSortedSet}, not this dummy version. 56 * 57 * @throws UnsupportedOperationException always 58 * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link 59 * ImmutableSortedSet#of(Comparable)}.</b> 60 */ 61 @Deprecated public static <E> ImmutableSortedSet<E> of(E element) { 62 throw new UnsupportedOperationException(); 63 } 64 65 /** 66 * Not supported. <b>You are attempting to create a set that may contain a 67 * non-{@code Comparable} element.</b> Proper calls will resolve to the 68 * version in {@code ImmutableSortedSet}, not this dummy version. 69 * 70 * @throws UnsupportedOperationException always 71 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 72 * ImmutableSortedSet#of(Comparable, Comparable)}.</b> 73 */ 74 @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2) { 75 throw new UnsupportedOperationException(); 76 } 77 78 /** 79 * Not supported. <b>You are attempting to create a set that may contain a 80 * non-{@code Comparable} element.</b> Proper calls will resolve to the 81 * version in {@code ImmutableSortedSet}, not this dummy version. 82 * 83 * @throws UnsupportedOperationException always 84 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 85 * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b> 86 */ 87 @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) { 88 throw new UnsupportedOperationException(); 89 } 90 91 /** 92 * Not supported. <b>You are attempting to create a set that may contain a 93 * non-{@code Comparable} element.</b> Proper calls will resolve to the 94 * version in {@code ImmutableSortedSet}, not this dummy version. 95 * 96 * @throws UnsupportedOperationException always 97 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 98 * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. 99 * </b> 100 */ 101 @Deprecated public static <E> ImmutableSortedSet<E> of( 102 E e1, E e2, E e3, E e4) { 103 throw new UnsupportedOperationException(); 104 } 105 106 /** 107 * Not supported. <b>You are attempting to create a set that may contain a 108 * non-{@code Comparable} element.</b> Proper calls will resolve to the 109 * version in {@code ImmutableSortedSet}, not this dummy version. 110 * 111 * @throws UnsupportedOperationException always 112 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 113 * ImmutableSortedSet#of( 114 * Comparable, Comparable, Comparable, Comparable, Comparable)}. </b> 115 */ 116 @Deprecated public static <E> ImmutableSortedSet<E> of( 117 E e1, E e2, E e3, E e4, E e5) { 118 throw new UnsupportedOperationException(); 119 } 120 121 /** 122 * Not supported. <b>You are attempting to create a set that may contain a 123 * non-{@code Comparable} element.</b> Proper calls will resolve to the 124 * version in {@code ImmutableSortedSet}, not this dummy version. 125 * 126 * @throws UnsupportedOperationException always 127 * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link 128 * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, 129 * Comparable, Comparable, Comparable...)}. </b> 130 */ 131 @Deprecated public static <E> ImmutableSortedSet<E> of( 132 E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { 133 throw new UnsupportedOperationException(); 134 } 135 136 /** 137 * Not supported. <b>You are attempting to create a set that may contain 138 * non-{@code Comparable} elements.</b> Proper calls will resolve to the 139 * version in {@code ImmutableSortedSet}, not this dummy version. 140 * 141 * @throws UnsupportedOperationException always 142 * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link 143 * ImmutableSortedSet#copyOf(Comparable[])}.</b> 144 */ 145 @Deprecated public static <E> ImmutableSortedSet<E> copyOf(E[] elements) { 146 throw new UnsupportedOperationException(); 147 } 148 149 /* 150 * We would like to include an unsupported "<E> copyOf(Iterable<E>)" here, 151 * providing only the properly typed 152 * "<E extends Comparable<E>> copyOf(Iterable<E>)" in ImmutableSortedSet (and 153 * likewise for the Iterator equivalent). However, due to a change in Sun's 154 * interpretation of the JLS (as described at 155 * http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler 156 * available as of this writing rejects our attempts. To maintain 157 * compatibility with that version and with any other compilers that interpret 158 * the JLS similarly, there is no definition of copyOf() here, and the 159 * definition in ImmutableSortedSet matches that in ImmutableSet. 160 * 161 * The result is that ImmutableSortedSet.copyOf() may be called on 162 * non-Comparable elements. We have not discovered a better solution. In 163 * retrospect, the static factory methods should have gone in a separate class 164 * so that ImmutableSortedSet wouldn't "inherit" too-permissive factory 165 * methods from ImmutableSet. 166 */ 167} 168