aboutsummaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/collect/ContiguousSet.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/collect/ContiguousSet.java')
-rw-r--r--guava/src/com/google/common/collect/ContiguousSet.java72
1 files changed, 8 insertions, 64 deletions
diff --git a/guava/src/com/google/common/collect/ContiguousSet.java b/guava/src/com/google/common/collect/ContiguousSet.java
index dc9aa83..439f675 100644
--- a/guava/src/com/google/common/collect/ContiguousSet.java
+++ b/guava/src/com/google/common/collect/ContiguousSet.java
@@ -19,63 +19,19 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
-import java.util.Collections;
import java.util.NoSuchElementException;
-import java.util.Set;
/**
* A sorted set of contiguous values in a given {@link DiscreteDomain}.
*
- * <p><b>Warning:</b> Be extremely careful what you do with conceptually large instances (such as
- * {@code ContiguousSet.create(Range.greaterThan(0), DiscreteDomains.integers()}). Certain
- * operations on such a set can be performed efficiently, but others (such as {@link Set#hashCode}
- * or {@link Collections#frequency}) can cause major performance problems.
- *
* @author Gregory Kick
* @since 10.0
*/
@Beta
-@GwtCompatible(emulated = true)
-@SuppressWarnings("rawtypes") // allow ungenerified Comparable types
+@GwtCompatible
+@SuppressWarnings("unchecked") // allow ungenerified Comparable types
public abstract class ContiguousSet<C extends Comparable> extends ImmutableSortedSet<C> {
- /**
- * Returns a {@code ContiguousSet} containing the same values in the given domain
- * {@linkplain Range#contains contained} by the range.
- *
- * @throws IllegalArgumentException if neither range nor the domain has a lower bound, or if
- * neither has an upper bound
- *
- * @since 13.0
- */
- public static <C extends Comparable> ContiguousSet<C> create(
- Range<C> range, DiscreteDomain<C> domain) {
- checkNotNull(range);
- checkNotNull(domain);
- Range<C> effectiveRange = range;
- try {
- if (!range.hasLowerBound()) {
- effectiveRange = effectiveRange.intersection(Range.atLeast(domain.minValue()));
- }
- if (!range.hasUpperBound()) {
- effectiveRange = effectiveRange.intersection(Range.atMost(domain.maxValue()));
- }
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException(e);
- }
-
- // Per class spec, we are allowed to throw CCE if necessary
- boolean empty = effectiveRange.isEmpty()
- || Range.compareOrThrow(
- range.lowerBound.leastValueAbove(domain),
- range.upperBound.greatestValueBelow(domain)) > 0;
-
- return empty
- ? new EmptyContiguousSet<C>(domain)
- : new RegularContiguousSet<C>(effectiveRange, domain);
- }
-
final DiscreteDomain<C> domain;
ContiguousSet(DiscreteDomain<C> domain) {
@@ -84,14 +40,10 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte
}
@Override public ContiguousSet<C> headSet(C toElement) {
- return headSetImpl(checkNotNull(toElement), false);
+ return headSet(checkNotNull(toElement), false);
}
- /**
- * @since 12.0
- */
- @GwtIncompatible("NavigableSet")
- @Override public ContiguousSet<C> headSet(C toElement, boolean inclusive) {
+ @Override ContiguousSet<C> headSet(C toElement, boolean inclusive) {
return headSetImpl(checkNotNull(toElement), inclusive);
}
@@ -99,14 +51,10 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte
checkNotNull(fromElement);
checkNotNull(toElement);
checkArgument(comparator().compare(fromElement, toElement) <= 0);
- return subSetImpl(fromElement, true, toElement, false);
+ return subSet(fromElement, true, toElement, false);
}
- /**
- * @since 12.0
- */
- @GwtIncompatible("NavigableSet")
- @Override public ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement,
+ @Override ContiguousSet<C> subSet(C fromElement, boolean fromInclusive, C toElement,
boolean toInclusive) {
checkNotNull(fromElement);
checkNotNull(toElement);
@@ -115,14 +63,10 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte
}
@Override public ContiguousSet<C> tailSet(C fromElement) {
- return tailSetImpl(checkNotNull(fromElement), true);
+ return tailSet(checkNotNull(fromElement), true);
}
- /**
- * @since 12.0
- */
- @GwtIncompatible("NavigableSet")
- @Override public ContiguousSet<C> tailSet(C fromElement, boolean inclusive) {
+ @Override ContiguousSet<C> tailSet(C fromElement, boolean inclusive){
return tailSetImpl(checkNotNull(fromElement), inclusive);
}