public class Range extends Object implements Serializable, RevisionHandler, CustomDisplayStringProvider
first-last
1,2,3,4
or combinations thereof. The range is internally converted from 1-based to 0-based (so methods that set or get numbers not in string format should use 0-based numbers).
Constructor and Description |
---|
Range()
Default constructor.
|
Range(String rangeList)
Constructor to set initial range.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getInvert()
Gets whether the range sense is inverted, i.e.
|
String |
getRanges()
Gets the string representing the selected range of values.
|
String |
getRevision()
Returns the revision string.
|
int[] |
getSelection()
Gets an array containing all the selected values, in the order that they
were selected (or ascending order if range inversion is on).
|
static String |
indicesToRangeList(int[] indices)
Creates a string representation of the indices in the supplied array.
|
boolean |
isInRange(int index)
Gets whether the supplied cardinal number is included in the current range.
|
static void |
main(String[] argv)
Main method for testing this class.
|
void |
setInvert(boolean newSetting)
Sets whether the range sense is inverted, i.e.
|
void |
setRanges(String rangeList)
Sets the ranges from a string representation.
|
void |
setUpper(int newUpper)
Sets the value of "last".
|
String |
toDisplay()
Returns the custom display string.
|
String |
toString()
Constructs a representation of the current range.
|
public Range()
public Range(String rangeList)
rangeList
- the initial rangeIllegalArgumentException
- if the range list is invalidpublic void setUpper(int newUpper)
newUpper
- the value of "last"public boolean getInvert()
public void setInvert(boolean newSetting)
newSetting
- true if the matching sense is invertedpublic String getRanges()
public void setRanges(String rangeList)
rangeList
- the comma separated list of ranges. The empty string sets
the range to empty.IllegalArgumentException
- if the rangeList was not well formedpublic boolean isInRange(int index)
index
- the number of interestRuntimeException
- if the upper limit of the range hasn't been
definedpublic String toString()
public int[] getSelection()
RuntimeException
- if the upper limit of the range hasn't been
definedpublic static String indicesToRangeList(int[] indices)
indices
- an array containing indices to select. Since the array will
typically come from a program, indices are assumed from 0, and
thus will have 1 added in the String representation.public String getRevision()
getRevision
in interface RevisionHandler
public String toDisplay()
toDisplay
in interface CustomDisplayStringProvider
public static void main(String[] argv)
argv
- one parameter: a test range specificationCopyright © 2018 University of Waikato, Hamilton, NZ. All Rights Reserved.