aboutsummaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/collect/RegularContiguousSet.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/collect/RegularContiguousSet.java')
-rw-r--r--guava/src/com/google/common/collect/RegularContiguousSet.java69
1 files changed, 26 insertions, 43 deletions
diff --git a/guava/src/com/google/common/collect/RegularContiguousSet.java b/guava/src/com/google/common/collect/RegularContiguousSet.java
index 7948fe8..10b26f9 100644
--- a/guava/src/com/google/common/collect/RegularContiguousSet.java
+++ b/guava/src/com/google/common/collect/RegularContiguousSet.java
@@ -41,38 +41,32 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
this.range = range;
}
- private ContiguousSet<C> intersectionInCurrentDomain(Range<C> other) {
- return (range.isConnected(other))
- ? ContiguousSet.create(range.intersection(other), domain)
- : new EmptyContiguousSet<C>(domain);
+ // Abstract method doesn't exist in GWT emulation
+ /* @Override */ ContiguousSet<C> headSetImpl(C toElement, boolean inclusive) {
+ return range.intersection(Ranges.upTo(toElement, BoundType.forBoolean(inclusive)))
+ .asSet(domain);
}
- @Override ContiguousSet<C> headSetImpl(C toElement, boolean inclusive) {
- return intersectionInCurrentDomain(Range.upTo(toElement, BoundType.forBoolean(inclusive)));
+ // Abstract method doesn't exist in GWT emulation
+ /* @Override */ int indexOf(Object target) {
+ return contains(target) ? (int) domain.distance(first(), (C) target) : -1;
}
- @Override ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement,
+ // Abstract method doesn't exist in GWT emulation
+ /* @Override */ ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement,
boolean toInclusive) {
- if (fromElement.compareTo(toElement) == 0 && !fromInclusive && !toInclusive) {
- // Range would reject our attempt to create (x, x).
- return new EmptyContiguousSet<C>(domain);
- }
- return intersectionInCurrentDomain(Range.range(
- fromElement, BoundType.forBoolean(fromInclusive),
- toElement, BoundType.forBoolean(toInclusive)));
+ return range.intersection(Ranges.range(fromElement, BoundType.forBoolean(fromInclusive),
+ toElement, BoundType.forBoolean(toInclusive))).asSet(domain);
}
- @Override ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive) {
- return intersectionInCurrentDomain(Range.downTo(fromElement, BoundType.forBoolean(inclusive)));
- }
-
- @GwtIncompatible("not used by GWT emulation")
- @Override int indexOf(Object target) {
- return contains(target) ? (int) domain.distance(first(), (C) target) : -1;
+ // Abstract method doesn't exist in GWT emulation
+ /* @Override */ ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive) {
+ return range.intersection(Ranges.downTo(fromElement, BoundType.forBoolean(inclusive)))
+ .asSet(domain);
}
@Override public UnmodifiableIterator<C> iterator() {
- return new AbstractSequentialIterator<C>(first()) {
+ return new AbstractLinkedIterator<C>(first()) {
final C last = last();
@Override
@@ -82,18 +76,6 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
};
}
- @GwtIncompatible("NavigableSet")
- @Override public UnmodifiableIterator<C> descendingIterator() {
- return new AbstractSequentialIterator<C>(last()) {
- final C first = first();
-
- @Override
- protected C computeNext(C previous) {
- return equalsOrThrow(previous, first) ? null : domain.previous(previous);
- }
- };
- }
-
private static boolean equalsOrThrow(Comparable<?> left, @Nullable Comparable<?> right) {
return right != null && Range.compareOrThrow(left, right) == 0;
}
@@ -115,10 +97,7 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
return (distance >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) distance + 1;
}
- @Override public boolean contains(@Nullable Object object) {
- if (object == null) {
- return false;
- }
+ @Override public boolean contains(Object object) {
try {
return range.contains((C) object);
} catch (ClassCastException e) {
@@ -127,7 +106,11 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
}
@Override public boolean containsAll(Collection<?> targets) {
- return Collections2.containsAllImpl(this, targets);
+ try {
+ return range.containsAll((Iterable<? extends C>) targets);
+ } catch (ClassCastException e) {
+ return false;
+ }
}
@Override public boolean isEmpty() {
@@ -153,7 +136,7 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
C lowerEndpoint = Ordering.natural().max(this.first(), other.first());
C upperEndpoint = Ordering.natural().min(this.last(), other.last());
return (lowerEndpoint.compareTo(upperEndpoint) < 0)
- ? ContiguousSet.create(Range.closed(lowerEndpoint, upperEndpoint), domain)
+ ? Ranges.closed(lowerEndpoint, upperEndpoint).asSet(domain)
: new EmptyContiguousSet<C>(domain);
}
}
@@ -163,14 +146,14 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
}
@Override public Range<C> range(BoundType lowerBoundType, BoundType upperBoundType) {
- return Range.create(range.lowerBound.withLowerBoundType(lowerBoundType, domain),
+ return Ranges.create(range.lowerBound.withLowerBoundType(lowerBoundType, domain),
range.upperBound.withUpperBoundType(upperBoundType, domain));
}
- @Override public boolean equals(@Nullable Object object) {
+ @Override public boolean equals(Object object) {
if (object == this) {
return true;
- } else if (object instanceof RegularContiguousSet) {
+ } else if (object instanceof RegularContiguousSet<?>) {
RegularContiguousSet<?> that = (RegularContiguousSet<?>) object;
if (this.domain.equals(that.domain)) {
return this.first().equals(that.first())