gov.sandia.cognition.collection
Class IntegerSpan

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Integer>
          extended by gov.sandia.cognition.collection.IntegerSpan
All Implemented Interfaces:
CloneableSerializable, Serializable, Cloneable, Iterable<Integer>, Collection<Integer>, Set<Integer>

public class IntegerSpan
extends AbstractSet<Integer>
implements CloneableSerializable

An Iterable that starts at a given Integer and goes until another, inclusive. For example, if I create an IntegerSpan foo = new IntegerSpan(8,9), then the for each loop will create Integers of 8 then 9. This is useful to describe the bounds on a function, for example, without having to create a List or Array that allocates memory.

Since:
2.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
IntegerSpan(int minValue, int maxValue)
          Creates a new instance of IntegerSpan
 
Method Summary
 IntegerSpan clone()
          Creates a new clone (shallow copy) of this object.
 boolean contains(int value)
          Determines if the given value is within the inclusive bounds
 boolean contains(Object o)
           
 int getMaxValue()
          Getter for maxValue
 int getMinValue()
          Getter for minValue
 Iterator<Integer> iterator()
           
protected  void setMaxValue(int maxValue)
          Setter for maxValue
protected  void setMinValue(int minValue)
          Setter for minValue
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray
 

Constructor Detail

IntegerSpan

public IntegerSpan(int minValue,
                   int maxValue)
Creates a new instance of IntegerSpan

Parameters:
minValue - Starting index, inclusive
maxValue - Stopping index, inclusive
Method Detail

clone

public IntegerSpan clone()
Description copied from interface: CloneableSerializable
Creates a new clone (shallow copy) of this object.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class Object
Returns:
A new clone (shallow copy) of this object.

getMinValue

public int getMinValue()
Getter for minValue

Returns:
Starting index, inclusive

setMinValue

protected void setMinValue(int minValue)
Setter for minValue

Parameters:
minValue - Starting index, inclusive

getMaxValue

public int getMaxValue()
Getter for maxValue

Returns:
Stopping index, inclusive

setMaxValue

protected void setMaxValue(int maxValue)
Setter for maxValue

Parameters:
maxValue - Stopping index, inclusive

iterator

public Iterator<Integer> iterator()
Specified by:
iterator in interface Iterable<Integer>
Specified by:
iterator in interface Collection<Integer>
Specified by:
iterator in interface Set<Integer>
Specified by:
iterator in class AbstractCollection<Integer>

size

public int size()
Specified by:
size in interface Collection<Integer>
Specified by:
size in interface Set<Integer>
Specified by:
size in class AbstractCollection<Integer>

contains

public boolean contains(int value)
Determines if the given value is within the inclusive bounds

Parameters:
value - Value to consider
Returns:
True if value is within the inclusive minValue/maxValue bounds

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<Integer>
Specified by:
contains in interface Set<Integer>
Overrides:
contains in class AbstractCollection<Integer>