JavaGenes, NASA Ames. Written largely by Al Globus

gov.nasa.alsUtility
Class IntegerInterval

java.lang.Object
  extended bygov.nasa.alsUtility.IntegerInterval
All Implemented Interfaces:
java.io.Serializable

public class IntegerInterval
extends java.lang.Object
implements java.io.Serializable

represent an interval from some low to some high integer

See Also:
Serialized Form

Field Summary
protected  int bottom
           
protected  int top
           
 
Constructor Summary
IntegerInterval()
          create an interval from 0 to 1
IntegerInterval(IntegerInterval interval)
           
IntegerInterval(int x, int y)
          create an interval from x to y or y to x depending on which is lower
 
Method Summary
 void addToHigh(int x)
           
 void addToLow(int x)
           
protected  void assertLegal()
           
 IntegerInterval copy()
           
 int distanceFrom(int value)
           
 int equalIncrements(int divisions)
           
 boolean equals(java.lang.Object obj)
           
 boolean equalsExtremes(int value)
           
 void expand(int factor)
          change the interval of this by a factor keeping the center of the interval the same.
 int[] getArrayOfAllValues()
           
 int[] getRandomUniqueIndices(int number)
          for good performance, number must be fairly small and much smaller than intervalInclusive()
 int hashCode()
           
 int high()
           
 int interval()
           
 int intervalInclusive()
           
 boolean isBetween(int value)
           
 boolean isNonNegative()
           
 IntegerInterval limitTo(IntegerInterval interval)
           
 int low()
           
 int random()
           
 void set(int x, int y)
          sets the interval from x to y or y to x depending on which is lower
 void setHigh(int x)
           
 void setLow(int x)
           
 void setToExtremes(int[] array)
          sets the interval to the low and high values of array
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

bottom

protected int bottom

top

protected int top
Constructor Detail

IntegerInterval

public IntegerInterval()
create an interval from 0 to 1


IntegerInterval

public IntegerInterval(int x,
                       int y)
create an interval from x to y or y to x depending on which is lower


IntegerInterval

public IntegerInterval(IntegerInterval interval)
Method Detail

limitTo

public IntegerInterval limitTo(IntegerInterval interval)
Returns:
this limited to interval

expand

public void expand(int factor)
change the interval of this by a factor keeping the center of the interval the same.


copy

public IntegerInterval copy()

set

public void set(int x,
                int y)
sets the interval from x to y or y to x depending on which is lower


setLow

public void setLow(int x)

setHigh

public void setHigh(int x)

addToHigh

public void addToHigh(int x)

addToLow

public void addToLow(int x)

isNonNegative

public boolean isNonNegative()

assertLegal

protected void assertLegal()

isBetween

public boolean isBetween(int value)

distanceFrom

public int distanceFrom(int value)
Returns:
0 if value within the interval, negative distance if value below interval, positive distance if value above interval

setToExtremes

public void setToExtremes(int[] array)
sets the interval to the low and high values of array


equalsExtremes

public boolean equalsExtremes(int value)

toString

public java.lang.String toString()

random

public int random()
Returns:
a random interval between bottom and top inclusive

getRandomUniqueIndices

public int[] getRandomUniqueIndices(int number)
for good performance, number must be fairly small and much smaller than intervalInclusive()

Returns:
an array of unique integers within this

low

public int low()

high

public int high()

interval

public int interval()
Returns:
the distance between top and bottom

intervalInclusive

public int intervalInclusive()

getArrayOfAllValues

public int[] getArrayOfAllValues()

equalIncrements

public int equalIncrements(int divisions)
Returns:
a value that will divide the interval into division increments, or as close as possible.

equals

public boolean equals(java.lang.Object obj)

hashCode

public int hashCode()

JavaGenes, NASA Ames. Written largely by Al Globus