Class Range
- java.lang.Object
-
- org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.Range
-
- All Implemented Interfaces:
java.io.Serializable
public class Range extends java.lang.Object implements java.io.SerializableClass representing a range of cardinal numbers. The range is set by a string representation such as:all first-last 1,2,3,4or 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).
- Version:
- $Revision: 1.14 $
- Author:
- Len Trigg (trigg@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetInvert()Gets whether the range sense is inverted, i.e.java.lang.StringgetRanges()Gets the string representing the selected range of valuesint[]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 java.lang.StringindicesToRangeList(int[] indices)Creates a string representation of the indices in the supplied array.booleanisInRange(int index)Gets whether the supplied cardinal number is included in the current range.protected booleanisValidRange(java.lang.String range)Determines if a string represents a valid index or simple range.static voidmain(java.lang.String[] argv)Main method for testing this class.protected intrangeLower(java.lang.String range)Translates a range into it's lower index.protected intrangeSingle(java.lang.String single)Translates a single string selection into it's internal 0-based equivalentprotected intrangeUpper(java.lang.String range)Translates a range into it's upper index.protected voidsetFlags()Sets the flags array.voidsetInvert(boolean newSetting)Sets whether the range sense is inverted, i.e.voidsetRanges(java.lang.String rangeList)Sets the ranges from a string representation.voidsetUpper(int newUpper)Sets the value of "last".java.lang.StringtoString()Constructs a representation of the current range.
-
-
-
Method Detail
-
setUpper
public void setUpper(int newUpper)
Sets the value of "last".- Parameters:
newUpper- the value of "last"
-
getInvert
public boolean getInvert()
Gets whether the range sense is inverted, i.e. all except the values included by the range string are selected.- Returns:
- whether the matching sense is inverted
-
setInvert
public void setInvert(boolean newSetting)
Sets whether the range sense is inverted, i.e. all except the values included by the range string are selected.- Parameters:
newSetting- true if the matching sense is inverted
-
getRanges
public java.lang.String getRanges()
Gets the string representing the selected range of values- Returns:
- the range selection string
-
setRanges
public void setRanges(java.lang.String rangeList)
Sets the ranges from a string representation. Note that setUpper() must be called afterwards for ranges to be actually set internally.- Parameters:
rangeList- the comma separated list of ranges. The empty string sets the range to empty.- Throws:
java.lang.IllegalArgumentException- if the rangeList was not well formed
-
isInRange
public boolean isInRange(int index)
Gets whether the supplied cardinal number is included in the current range.- Parameters:
index- the number of interest- Returns:
- true if index is in the current range
- Throws:
java.lang.RuntimeException- if the upper limit of the range hasn't been defined
-
toString
public java.lang.String toString()
Constructs a representation of the current range. Being a string representation, the numbers are based from 1.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation of the current range
-
getSelection
public 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)- Returns:
- the array of selected values
- Throws:
java.lang.RuntimeException- if the upper limit of the range hasn't been defined
-
indicesToRangeList
public static java.lang.String indicesToRangeList(int[] indices)
Creates a string representation of the indices in the supplied array.- Parameters:
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.
-
setFlags
protected void setFlags()
Sets the flags array.
-
rangeSingle
protected int rangeSingle(java.lang.String single)
Translates a single string selection into it's internal 0-based equivalent- Parameters:
single- the string representing the selection (eg: 1 first last)- Returns:
- the number corresponding to the selected value
-
rangeLower
protected int rangeLower(java.lang.String range)
Translates a range into it's lower index.- Parameters:
range- the string representation of the range- Returns:
- the lower index of the range
-
rangeUpper
protected int rangeUpper(java.lang.String range)
Translates a range into it's upper index. Must only be called once setUpper has been called.- Parameters:
range- the string representation of the range- Returns:
- the upper index of the range
-
isValidRange
protected boolean isValidRange(java.lang.String range)
Determines if a string represents a valid index or simple range. Examples:first last 2 first-last first-4 4-lastDoesn't check that a < b for a-b- Parameters:
range-- Returns:
- true if the range is valid
-
main
public static void main(java.lang.String[] argv)
Main method for testing this class.- Parameters:
argv- one parameter: a test range specification
-
-