java.lang.Object de.luschny.math.util.PositiveRange
A PositiveRange is an intervall of integers, given by a lower bound L and an upper bound U, such that 0 <= L and L <= U. A PositiveRange is immutable.
Field Summary | |
---|---|
private
int |
max |
private
int |
min |
Constructor Summary | |
---|---|
PositiveRange(int
low, int high) Creates a PositiveRange, i.e. a range of integers, such that 0 <= low <= high. |
Method Summary | |
---|---|
java.lang.Object |
clone()
Creates and returns a copy of this object. |
boolean |
contains(int
value) Checks, if the given value lies within the range, i.e. min <= value and value <= max. |
boolean |
contains(PositiveRange
range) Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max. |
boolean |
containsOrFail(int
value) Checks, if the given value lies within the range, i.e. min <= value and value <= max. If the value ist not contained an IndexOutOfBoundsException will be raised. |
boolean |
containsOrFail(PositiveRange
range) Checks, if the given range is a subrange, i.e. this.min <= range.min and range.max <= this.max. If the range ist not contained an IndexOutOfBoundsException will be raised. |
boolean |
equals(java.lang.Object
o) Compares this range to the specified object. |
int |
getMax()
Get upper bound (maximum) of the range. |
int |
getMin()
Get the lower bound (minimum) of the range. |
int |
hashCode()
A hash code value for this range. |
int |
size()
Computes the size of the range. |
java.lang.String |
toString()
Gets the range as a
String . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final int max
private final int min
Constructor Detail |
---|
public PositiveRange(int low, int high)
low
- The low bound (minimum) of the range.high
- The high bound (maximum) of the range. java.lang.IllegalArgumentException
Method Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(int value)
value
- The value to checked. containsOrFail(int
value)
public boolean contains(PositiveRange range)
range
- The range to be checked. containsOrFail(PositiveRange range)
public boolean containsOrFail(int value)
value
- The value to checked. java.lang.IndexOutOfBoundsException
public boolean containsOrFail(PositiveRange range)
range
- The range to be checked. java.lang.IndexOutOfBoundsException
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- The object to compare with. public int getMax()
public int getMin()
public int hashCode()
hashCode
in class java.lang.Object
public int size()
public java.lang.String toString()
Gets the range as a String
.
The format of the String is '[min,max]'.
toString
in class java.lang.Object
String
representation of this range.