Package adams.core
Class UnorderedRange
- java.lang.Object
-
- adams.core.UnorderedRange
-
- All Implemented Interfaces:
CloneHandler<UnorderedRange>,CustomDisplayStringProvider,ExampleProvider,HelpProvider,Serializable,Comparable<UnorderedRange>
- Direct Known Subclasses:
AbstractDataBackedUnorderedRange
public class UnorderedRange extends Object implements Serializable, CustomDisplayStringProvider, Comparable<UnorderedRange>, ExampleProvider, HelpProvider, CloneHandler<UnorderedRange>
LikeRange, but enforces no ordering on indices.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringALL"first-last" constant.static StringFIRSTthe special string "first".static StringLASTthe special string "last".static StringLAST_1the special string "last_1" (2nd to last).static StringLAST_2the special string "last_2" (3rd to last).protected gnu.trove.list.TIntListm_Indicesthe parsed indices.protected intm_Maxthe maximum for the 1-based range.protected Stringm_Rawthe raw range string.static StringRANGEthe special string "-".static StringSECONDthe special string "second".static StringSEPARATORthe special string ",".static StringTHIRDthe special string "third".
-
Constructor Summary
Constructors Constructor Description UnorderedRange()Initializes with no range.UnorderedRange(String range)Initializes with the given range, but no maximum.UnorderedRange(String range, int max)Initializes with the given range and maximum.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(UnorderedRange o)Compares this range with the specified range for order.UnorderedRangegetClone()Returns a clone of the object.StringgetExample()Returns the example.StringgetHelpDescription()Returns a long help description, e.g., used in tiptexts.StringgetHelpIcon()Returns the name of a help icon, e.g., used for buttons.StringgetHelpTitle()Returns a short title for the help, e.g., used for buttons.StringgetHelpURL()Returns a URL with additional information.int[]getIntIndices()Returns the integer indices.intgetMax()Returns the maximum.StringgetRange()Returns the currently set range.booleanhasRange()Checks whether a valid range has been supplied.protected voidinitialize()The initializes the members.booleanisAllRange()Returns whether the range encompasses all.booleanisEmpty()Returns whether the range is empty.booleanisInRange(int index)Checks whether the provided 0-based index is within the range.static booleanisValid(String s, int max)Returns whether the range string is valid.protected voidparse()Parses the range.protected int[]parseSubRange(String subrange)Parses the subrange.protected voidreset()Resets the state.voidsetIndices(int[] indices)Sets the selected indices.voidsetIndices(Integer[] indices)Sets the selected indices.voidsetMax(int value)Sets the maximum (1-max will be allowed).voidsetRange(String value)Sets the range.protected String[]splitRange(String range)Splits the range into subranges.StringtoDisplay()Returns the custom display string.StringtoExplicitRange()Returns the explicit range, i.e., just comma-separated (1-based) indices.static UnorderedRangetoRange(int[] indices)Turns the integer indices into a unordered range object.StringtoString()Returns a string representation of the range.
-
-
-
Field Detail
-
RANGE
public static final String RANGE
the special string "-".- See Also:
- Constant Field Values
-
SEPARATOR
public static final String SEPARATOR
the special string ",".- See Also:
- Constant Field Values
-
FIRST
public static final String FIRST
the special string "first".- See Also:
- Constant Field Values
-
SECOND
public static final String SECOND
the special string "second".- See Also:
- Constant Field Values
-
THIRD
public static final String THIRD
the special string "third".- See Also:
- Constant Field Values
-
LAST_1
public static final String LAST_1
the special string "last_1" (2nd to last).- See Also:
- Constant Field Values
-
LAST_2
public static final String LAST_2
the special string "last_2" (3rd to last).- See Also:
- Constant Field Values
-
LAST
public static final String LAST
the special string "last".- See Also:
- Constant Field Values
-
ALL
public static final String ALL
"first-last" constant.- See Also:
- Constant Field Values
-
m_Raw
protected String m_Raw
the raw range string.
-
m_Max
protected int m_Max
the maximum for the 1-based range.
-
m_Indices
protected gnu.trove.list.TIntList m_Indices
the parsed indices.
-
-
Constructor Detail
-
UnorderedRange
public UnorderedRange()
Initializes with no range.
-
UnorderedRange
public UnorderedRange(String range)
Initializes with the given range, but no maximum.- Parameters:
range- the range to use
-
UnorderedRange
public UnorderedRange(String range, int max)
Initializes with the given range and maximum.- Parameters:
range- the range to usemax- the maximum of the 1-based index (e.g., use "10" to allow "1-10" or -1 for uninitialized)
-
-
Method Detail
-
initialize
protected void initialize()
The initializes the members.
-
reset
protected void reset()
Resets the state.
-
setRange
public void setRange(String value)
Sets the range.- Parameters:
value- the range to use
-
getRange
public String getRange()
Returns the currently set range.- Returns:
- the range in use
-
hasRange
public boolean hasRange()
Checks whether a valid range has been supplied.- Returns:
- true if a valid range is available
-
isAllRange
public boolean isAllRange()
Returns whether the range encompasses all.
-
isEmpty
public boolean isEmpty()
Returns whether the range is empty.- Returns:
- true if empty
-
setMax
public void setMax(int value)
Sets the maximum (1-max will be allowed).- Parameters:
value- the maximum for the 1-based index
-
getMax
public int getMax()
Returns the maximum.- Returns:
- the maximum for the 1-based index
-
splitRange
protected String[] splitRange(String range)
Splits the range into subranges.- Parameters:
range- the range to split- Returns:
- the subranges
-
parseSubRange
protected int[] parseSubRange(String subrange)
Parses the subrange.- Parameters:
subrange- the subrange- Returns:
- the indices
-
parse
protected void parse()
Parses the range.
-
getIntIndices
public int[] getIntIndices()
Returns the integer indices. Gets always generated on-the-fly!- Returns:
- the indices, 0-length array if not possible
-
setIndices
public void setIndices(Integer[] indices)
Sets the selected indices. Generates a range string out of the array.- Parameters:
indices- the indices (0-based)
-
setIndices
public void setIndices(int[] indices)
Sets the selected indices. Generates a range string out of the array.- Parameters:
indices- the indices (0-based)
-
isInRange
public boolean isInRange(int index)
Checks whether the provided 0-based index is within the range.- Parameters:
index- the index to check- Returns:
- true if in range
-
getClone
public UnorderedRange getClone()
Returns a clone of the object.- Specified by:
getClonein interfaceCloneHandler<UnorderedRange>- Returns:
- the clone
-
getExample
public String getExample()
Returns the example.- Specified by:
getExamplein interfaceExampleProvider- Returns:
- the example
-
getHelpURL
public String getHelpURL()
Returns a URL with additional information.- Specified by:
getHelpURLin interfaceHelpProvider- Returns:
- the URL, null if not available
-
getHelpDescription
public String getHelpDescription()
Returns a long help description, e.g., used in tiptexts.- Specified by:
getHelpDescriptionin interfaceHelpProvider- Returns:
- the help text, null if not available
-
getHelpTitle
public String getHelpTitle()
Returns a short title for the help, e.g., used for buttons.- Specified by:
getHelpTitlein interfaceHelpProvider- Returns:
- the short title, null if not available
-
getHelpIcon
public String getHelpIcon()
Returns the name of a help icon, e.g., used for buttons.- Specified by:
getHelpIconin interfaceHelpProvider- Returns:
- the icon name, null if not available
-
compareTo
public int compareTo(UnorderedRange o)
Compares this range with the specified range for order. Returns a negative integer, zero, or a positive integer as this subrange is less than, equal to, or greater than the specified subrange. Uses the "from" as point of comparison and if those are equal, then the "to" (if available).- Specified by:
compareToin interfaceComparable<UnorderedRange>- Parameters:
o- the range to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
toExplicitRange
public String toExplicitRange()
Returns the explicit range, i.e., just comma-separated (1-based) indices.- Returns:
- the string
-
toDisplay
public String toDisplay()
Returns the custom display string.- Specified by:
toDisplayin interfaceCustomDisplayStringProvider- Returns:
- the string
-
toString
public String toString()
Returns a string representation of the range.
-
toRange
public static UnorderedRange toRange(int[] indices)
Turns the integer indices into a unordered range object.- Parameters:
indices- the 0-based indices- Returns:
- the generated range
-
isValid
public static boolean isValid(String s, int max)
Returns whether the range string is valid.- Parameters:
s- the range to checkmax- the maximum (-1 for uninitialized)- Returns:
- true if a valid range string
-
-