edu.nrao.sss.math
Class NumberInterval

java.lang.Object
  extended by edu.nrao.sss.math.NumberInterval

public class NumberInterval
extends Object

An interval on the number line from one number to another. Whether or not the endpoints are part of an interval is determined by its type.

Version Info:

$Revision: 567 $
$Date: 2007-04-26 16:35:46 -0600 (Thu, 26 Apr 2007) $
$Author: dharland $

Since:
2007-04-25
Author:
David M. Harland

Nested Class Summary
static class NumberInterval.IntervalType
          Indicates whether or not the endpoints are inside or outside an interval.
 
Constructor Summary
NumberInterval(NumberInterval.IntervalType type, Number a, Number b)
          Creates a new interval with the given properties.
 
Method Summary
 boolean contains(Number candidate)
          Returns true if this interval contains candidate.
 void setInterval(Number a, Number b)
          Sets the endpoints of this interval.
 void setType(NumberInterval.IntervalType newType)
          Sets the value that determines which endpoints, if either, are in this interval.
 String toString()
          Returns a string of form [low..high), where a square bracket indicates that the interval is closed on that end and a rounded bracket that it is open.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberInterval

public NumberInterval(NumberInterval.IntervalType type,
                      Number a,
                      Number b)
Creates a new interval with the given properties.

Parameters:
type - determines which endpoints, if either, are part of this interval.
a - one of the endpoints.
b - the other endpoint.
Method Detail

setInterval

public void setInterval(Number a,
                        Number b)
Sets the endpoints of this interval. Clients do not need to present the endpoints in any particular order. This method will compare the two endpoints to determine which is higher and which is lower.

Parameters:
a - one of the endpoints.
b - the other endpoint.

setType

public void setType(NumberInterval.IntervalType newType)
Sets the value that determines which endpoints, if either, are in this interval.

Parameters:
newType - the type of this interval (open, closed, etc.).

contains

public boolean contains(Number candidate)
Returns true if this interval contains candidate.

Parameters:
candidate - a number that might be contained in this interval.
Returns:
true if this interval contains candidate.

toString

public String toString()
Returns a string of form [low..high), where a square bracket indicates that the interval is closed on that end and a rounded bracket that it is open.

Overrides:
toString in class Object


Copyright © 2009. All Rights Reserved.