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;
 
 
A descriptor for a discrete Comparable domain such as all java.lang.Integers. A discrete domain is one that supports the three basic operations: next(java.lang.Comparable), previous(java.lang.Comparable) and distance(java.lang.Comparable,java.lang.Comparable), according to their specifications. The methods minValue() and maxValue() should also be overridden for bounded types.

A discrete domain always represents the entire set of values of its type; it cannot represent partial domains such as "prime integers" or "strings of length 5."

See the Guava User Guide section on DiscreteDomain.

Author(s):
Kevin Bourrillion
Since:
10.0
See also:
DiscreteDomains
 
 public abstract class DiscreteDomain<C extends Comparable> {
  
Constructor for use by subclasses.
 
   protected DiscreteDomain() {}

  
Returns the unique least value of type C that is greater than value, or null if none exists. Inverse operation to previous(java.lang.Comparable).

Parameters:
value any value of type C
Returns:
the least value greater than value, or null if value is maxValue()
 
   public abstract C next(C value);

  
Returns the unique greatest value of type C that is less than value, or null if none exists. Inverse operation to next(java.lang.Comparable).

Parameters:
value any value of type C
Returns:
the greatest value less than value, or null if value is minValue()
 
   public abstract C previous(C value);

  
Returns a signed value indicating how many nested invocations of next(java.lang.Comparable) (if positive) or previous(java.lang.Comparable) (if negative) are needed to reach end starting from start. For example, if end = next(next(next(start))), then distance(start, end) == 3 and distance(end, start) == -3. As well, distance(a, a) is always zero.

Note that this function is necessarily well-defined for any discrete type.

Returns:
the distance as described above, or java.lang.Long.MIN_VALUE or java.lang.Long.MAX_VALUE if the distance is too small or too large, respectively.
 
   public abstract long distance(C start, C end);

  
Returns the minimum value of type C, if it has one. The minimum value is the unique value for which java.lang.Comparable.compareTo(java.lang.Object) never returns a positive value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:
the minimum value of type C; never null
Throws:
java.util.NoSuchElementException if the type has no (practical) minimum value; for example, java.math.BigInteger
 
   public C minValue() {
    throw new NoSuchElementException();
  }

  
Returns the maximum value of type C, if it has one. The maximum value is the unique value for which java.lang.Comparable.compareTo(java.lang.Object) never returns a negative value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:
the maximum value of type C; never null
Throws:
java.util.NoSuchElementException if the type has no (practical) maximum value; for example, java.math.BigInteger
  public C maxValue() {
    throw new NoSuchElementException();
  }
New to GrepCode? Check out our FAQ X