Coverage Summary for Class: ImmutableSortedSetFauxverideShim (com.google.common.collect)

Class Class, % Method, % Line, %
ImmutableSortedSetFauxverideShim 100% (1/1) 9.1% (1/11) 9.1% (1/11)


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