Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect;
 
 
Static methods pertaining to Range instances. Each of the nine types of ranges can be constructed with a corresponding factory method:
(a..b)
open(java.lang.Comparable,java.lang.Comparable)
[a..b]
closed(java.lang.Comparable,java.lang.Comparable)
[a..b)
closedOpen(java.lang.Comparable,java.lang.Comparable)
(a..b]
openClosed(java.lang.Comparable,java.lang.Comparable)
(a..+∞)
greaterThan(java.lang.Comparable)
[a..+∞)
atLeast(java.lang.Comparable)
(-∞..b)
lessThan(java.lang.Comparable)
(-∞..b]
atMost(java.lang.Comparable)
(-∞..+∞)
all()

Additionally, Range instances can be constructed by passing the bound types explicitly.

Bounded on both ends
range(java.lang.Comparable,com.google.common.collect.BoundType,java.lang.Comparable,com.google.common.collect.BoundType)
Unbounded on top ((a..+∞) or (a..+∞))
downTo(java.lang.Comparable,com.google.common.collect.BoundType)
Unbounded on bottom ((-∞..b) or (-∞..b])
upTo(java.lang.Comparable,com.google.common.collect.BoundType)

See the Guava User Guide article on Range.

Deprecated:
Use the corresponding method in Range.
Author(s):
Kevin Bourrillion
Gregory Kick
Since:
10.0
 
 public final class Ranges {
   private Ranges() {}

  
Returns a range that contains all values strictly greater than lower and strictly less than upper.

Throws:
java.lang.IllegalArgumentException if lower is greater than or equal to upper
 
   public static <C extends Comparable<?>> Range<C> open(C lower, C upper) {
     return Range.open(lowerupper);
   }

  
Returns a range that contains all values greater than or equal to lower and less than or equal to upper.

Throws:
java.lang.IllegalArgumentException if lower is greater than upper
 
   public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) {
     return Range.closed(lowerupper);
   }

  
Returns a range that contains all values greater than or equal to lower and strictly less than upper.

Throws:
java.lang.IllegalArgumentException if lower is greater than upper
  public static <C extends Comparable<?>> Range<C> closedOpen(
      C lower, C upper) {
    return Range.closedOpen(lowerupper);
  }

  
Returns a range that contains all values strictly greater than lower and less than or equal to upper.

Throws:
java.lang.IllegalArgumentException if lower is greater than upper
  public static <C extends Comparable<?>> Range<C> openClosed(
      C lower, C upper) {
    return Range.openClosed(lowerupper);
  }

  
Returns a range that contains any value from lower to upper, where each endpoint may be either inclusive (closed) or exclusive (open).

Throws:
java.lang.IllegalArgumentException if lower is greater than upper
  public static <C extends Comparable<?>> Range<C> range(
      C lowerBoundType lowerType, C upperBoundType upperType) {
    return Range.range(lowerlowerTypeupperupperType);
  }

  
Returns a range that contains all values strictly less than endpoint.
  public static <C extends Comparable<?>> Range<C> lessThan(C endpoint) {
    return Range.lessThan(endpoint);
  }

  
Returns a range that contains all values less than or equal to endpoint.
  public static <C extends Comparable<?>> Range<C> atMost(C endpoint) {
    return Range.atMost(endpoint);
  }

  
Returns a range with no lower bound up to the given endpoint, which may be either inclusive (closed) or exclusive (open).
  public static <C extends Comparable<?>> Range<C> upTo(
      C endpointBoundType boundType) {
    return Range.upTo(endpointboundType);
  }

  
Returns a range that contains all values strictly greater than endpoint.
  public static <C extends Comparable<?>> Range<C> greaterThan(C endpoint) {
    return Range.greaterThan(endpoint);
  }

  
Returns a range that contains all values greater than or equal to endpoint.
  public static <C extends Comparable<?>> Range<C> atLeast(C endpoint) {
    return Range.atLeast(endpoint);
  }

  
Returns a range from the given endpoint, which may be either inclusive (closed) or exclusive (open), with no upper bound.
  public static <C extends Comparable<?>> Range<C> downTo(
      C endpointBoundType boundType) {
    return Range.downTo(endpointboundType);
  }

  
Returns a range that contains every value of type C.
  public static <C extends Comparable<?>> Range<C> all() {
    return Range.all();
  }

  
Returns a range that contains only the given value. The returned range is closed on both ends.
  public static <C extends Comparable<?>> Range<C> singleton(C value) {
    return Range.singleton(value);
  }

  
Returns the minimal range that contains all of the given values. The returned range is closed on both ends.

Throws:
java.lang.ClassCastException if the parameters are not mutually comparable
java.util.NoSuchElementException if values is empty
java.lang.NullPointerException if any of values is null
  public static <C extends Comparable<?>> Range<C> encloseAll(
      Iterable<C> values) {
    return Range.encloseAll(values);
  }
New to GrepCode? Check out our FAQ X