com.google.common.collect
Class ContiguousSet<C extends Comparable>

java.lang.Object
  extended by com.google.common.collect.ImmutableCollection<E>
      extended by com.google.common.collect.ImmutableSet<E>
          extended by com.google.common.collect.ImmutableSortedSet<C>
              extended by com.google.common.collect.ContiguousSet<C>
All Implemented Interfaces:
Serializable, Iterable<C>, Collection<C>, Set<C>, SortedSet<C>

@Beta
@GwtCompatible
public abstract class ContiguousSet<C extends Comparable>
extends ImmutableSortedSet<C>

A sorted set of contiguous values in a given DiscreteDomain.

Since:
10.0
Author:
Gregory Kick
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.common.collect.ImmutableSortedSet
ImmutableSortedSet.Builder<E>
 
Method Summary
static
<E> ImmutableSortedSet.Builder<E>
builder()
          Deprecated. Use ImmutableSortedSet.naturalOrder(), which offers better type-safety.
 ContiguousSet<C> headSet(C toElement)
          
abstract  ContiguousSet<C> intersection(ContiguousSet<C> other)
          Returns the set of values that are contained in both this set and the other.
abstract  Range<C> range()
          Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set.
abstract  Range<C> range(BoundType lowerBoundType, BoundType upperBoundType)
          Returns the minimal range with the given boundary types for which all values in this set are contained within the range.
 ContiguousSet<C> subSet(C fromElement, C toElement)
          
 ContiguousSet<C> tailSet(C fromElement)
          
 String toString()
          Returns a short-hand representation of the contents such as "[1..100]".
 
Methods inherited from class com.google.common.collect.ImmutableSortedSet
comparator, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOf, copyOfSorted, iterator, naturalOrder, of, of, of, of, of, of, of, of, orderedBy, reverseOrder
 
Methods inherited from class com.google.common.collect.ImmutableSet
equals, hashCode
 
Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, asList, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.SortedSet
first, last
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
 

Method Detail

headSet

public ContiguousSet<C> headSet(C toElement)
Description copied from class: ImmutableSortedSet

This method returns a serializable ImmutableSortedSet.

The SortedSet.headSet(E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a toElement greater than an earlier toElement. However, this method doesn't throw an exception in that situation, but instead keeps the original toElement.

Specified by:
headSet in interface SortedSet<C extends Comparable>
Overrides:
headSet in class ImmutableSortedSet<C extends Comparable>

subSet

public ContiguousSet<C> subSet(C fromElement,
                               C toElement)
Description copied from class: ImmutableSortedSet

This method returns a serializable ImmutableSortedSet.

The SortedSet.subSet(E, E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a fromElement smaller than an earlier fromElement. However, this method doesn't throw an exception in that situation, but instead keeps the original fromElement. Similarly, this method keeps the original toElement, instead of throwing an exception, if passed a toElement greater than an earlier toElement.

Specified by:
subSet in interface SortedSet<C extends Comparable>
Overrides:
subSet in class ImmutableSortedSet<C extends Comparable>

tailSet

public ContiguousSet<C> tailSet(C fromElement)
Description copied from class: ImmutableSortedSet

This method returns a serializable ImmutableSortedSet.

The SortedSet.tailSet(E) documentation states that a subset of a subset throws an IllegalArgumentException if passed a fromElement smaller than an earlier fromElement. However, this method doesn't throw an exception in that situation, but instead keeps the original fromElement.

Specified by:
tailSet in interface SortedSet<C extends Comparable>
Overrides:
tailSet in class ImmutableSortedSet<C extends Comparable>

intersection

public abstract ContiguousSet<C> intersection(ContiguousSet<C> other)
Returns the set of values that are contained in both this set and the other.

This method should always be used instead of Sets.intersection(java.util.Set, java.util.Set) for ContiguousSet instances.


range

public abstract Range<C> range()
Returns a range, closed on both ends, whose endpoints are the minimum and maximum values contained in this set. This is equivalent to range(CLOSED, CLOSED).

Throws:
NoSuchElementException - if this set is empty

range

public abstract Range<C> range(BoundType lowerBoundType,
                               BoundType upperBoundType)
Returns the minimal range with the given boundary types for which all values in this set are contained within the range.

Note that this method will return ranges with unbounded endpoints if BoundType.OPEN is requested for a domain minimum or maximum. For example, if set was created from the range [1..Integer.MAX_VALUE] then set.range(CLOSED, OPEN) must return [1..∞).

Throws:
NoSuchElementException - if this set is empty

toString

public String toString()
Returns a short-hand representation of the contents such as "[1..100]".

Overrides:
toString in class ImmutableCollection<C extends Comparable>

builder

@Deprecated
public static <E> ImmutableSortedSet.Builder<E> builder()
Deprecated. Use ImmutableSortedSet.naturalOrder(), which offers better type-safety.

Not supported. Use ImmutableSortedSet.naturalOrder(), which offers better type-safety, instead. This method exists only to hide ImmutableSet.builder() from consumers of ImmutableSortedSet.

Throws:
UnsupportedOperationException - always


Copyright © 2010-2011. All Rights Reserved.