public class IntRange extends Object implements EuclidConstants, Comparable<IntRange>
Default is range with low > high; this can be regarded as the uninitialised state. If points are added to a default IntRange it becomes initialised.
| Modifier and Type | Field and Description |
|---|---|
static org.xmlcml.euclid.IntRangeComparator |
ASCENDING_MIN_COMPARATOR |
protected int |
maxval
maximum of range
|
protected int |
minval
minimum of range
|
C_AMP, C_APOS, C_ATSIGN, C_BACKSLASH, C_BACKSPACE, C_CARET, C_COLON, C_COMMA, C_DEL, C_DOLLAR, C_EQUALS, C_FORMFEED, C_HASH, C_LANGLE, C_LBRAK, C_LCURLY, C_LSQUARE, C_MINUS, C_NBSP, C_NEWLINE, C_NL, C_PERCENT, C_PERIOD, C_PIPE, C_PLUS, C_POUND, C_QUERY, C_QUOT, C_RANGLE, C_RBRAK, C_RCURLY, C_RETURN, C_RSQUARE, C_SEMICOLON, C_SHRIEK, C_SLASH, C_SPACE, C_STAR, C_TAB, C_TILDE, C_UNDER, EPS, F_S, NONWHITEPUNC, NONWHITEPUNC0, NONWHITEPUNC0REGEX, ONE_THIRD, PUNC, S_AMP, S_APOS, S_ATSIGN, S_BACKSLASH, S_CARET, S_COLON, S_COMMA, S_DOLLAR, S_EMPTY, S_EQUALS, S_FORMFEED, S_HASH, S_LANGLE, S_LBRAK, S_LCURLY, S_LSQUARE, S_MINUS, S_NEWLINE, S_NL, S_PERCENT, S_PERIOD, S_PIPE, S_PLUS, S_POUND, S_QUERY, S_QUOT, S_RANGLE, S_RBRAK, S_RCURLY, S_RETURN, S_RSQUARE, S_SEMICOLON, S_SHRIEK, S_SLASH, S_SPACE, S_STAR, S_TAB, S_TILDE, S_UNDER, S_WHITEREGEX, TWO_THIRDS, U_S, WHITESPACE| Constructor and Description |
|---|
IntRange()
creates invalid range from MAX_VALUE to MIN_VALUE
|
IntRange(int minv,
int maxv)
initialise with min and max values; if minv > maxv create inValid
IntRange
|
IntRange(IntRange r)
copy constructor
|
IntRange(RealRange r) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int x)
add a value to a range
|
boolean |
canJoin(IntRange range,
int tolerance)
can two ranges be joined at a common point?
(1,5) and (5,10) can be joined.
|
int |
compareTo(IntRange intRange)
comparees on min values
|
boolean |
contains(int f)
synonym for includes()
|
static List<IntRange> |
createIntRangeList(List<String> tokens)
creates a list of IntRanges from {...} syntax.
|
boolean |
equals(Object o) |
int |
getMax()
get maximum value (MIN_VALUE if inValid)
|
int |
getMidPoint()
mid point of range.
|
int |
getMin()
get minimum value (MAX_VALUE if inValid)
|
int |
getRange()
get range (MIN_VALUE if invalid)
|
IntRange |
getRangeExtendedBy(int minExtend,
int maxExtend)
makes new IntRange extended by deltaMin and deltaMax.
|
int |
hashCode() |
boolean |
includes(int f)
is a int within a IntRange
|
boolean |
includes(IntRange r2)
does one range include another
|
IntRange |
intersectionWith(IntRange r2)
intersect two ranges and take the range common to both; return invalid
range if no overlap
|
boolean |
intersectsWith(IntRange r2) |
boolean |
isEqualTo(IntRange r)
invalid ranges return false
|
boolean |
isValid()
a Range is only valid if its maxval is not less than its minval; this
tests for uninitialised ranges
|
static List<IntRange> |
joinRanges(List<IntRange> rangeList,
int tolerance)
joins intRanges A and B when A.getMax() == B.getMin().
|
static IntRange |
parseCurlyBracketString(String token)
interprets a String as an IntRange.
|
IntRange |
plus(IntRange r2)
combine two ranges if both valid; takes greatest limits of both, else
returns InValid
|
void |
setMax(int max) |
void |
setMin(int min) |
String |
toString()
to string
|
boolean |
touches(IntRange range)
do ranges touch but not overlap?
range from [a,b] inclusive touches [c,a-1] or [b+1,c]
([a,b] overlaps with [b,c])
|
public static final org.xmlcml.euclid.IntRangeComparator ASCENDING_MIN_COMPARATOR
protected int maxval
protected int minval
public IntRange()
public IntRange(int minv,
int maxv)
minv - maxv - public IntRange(IntRange r)
r - public IntRange(RealRange r)
r - public boolean isValid()
public boolean isEqualTo(IntRange r)
r - public IntRange plus(IntRange r2)
r2 - public boolean intersectsWith(IntRange r2)
public IntRange intersectionWith(IntRange r2)
r2 - public int getMin()
public int getMax()
public int getRange()
public boolean includes(IntRange r2)
r2 - public boolean includes(int f)
f - public boolean contains(int f)
f - public void add(int x)
x - public int compareTo(IntRange intRange)
compareTo in interface Comparable<IntRange>intRange - public IntRange getRangeExtendedBy(int minExtend, int maxExtend)
Does not alter this.
minExtend - subtracted from minmaxExtend - added to maxpublic boolean touches(IntRange range)
range - public int getMidPoint()
public static IntRange parseCurlyBracketString(String token)
token - public static List<IntRange> createIntRangeList(List<String> tokens)
tokens - public static List<IntRange> joinRanges(List<IntRange> rangeList, int tolerance)
rangeList - can be in any order, not alteredtolerance - allows for overlap, i.e. (1,5) and (4,10) would "touch" , so would (1,5) and (6,10)public boolean canJoin(IntRange range, int tolerance)
range - tolerance - public void setMax(int max)
public void setMin(int min)
Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.