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 String
ALL
"first-last" constant.static String
FIRST
the special string "first".static String
LAST
the special string "last".static String
LAST_1
the special string "last_1" (2nd to last).static String
LAST_2
the special string "last_2" (3rd to last).protected gnu.trove.list.TIntList
m_Indices
the parsed indices.protected int
m_Max
the maximum for the 1-based range.protected String
m_Raw
the raw range string.static String
RANGE
the special string "-".static String
SECOND
the special string "second".static String
SEPARATOR
the special string ",".static String
THIRD
the 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 int
compareTo(UnorderedRange o)
Compares this range with the specified range for order.UnorderedRange
getClone()
Returns a clone of the object.String
getExample()
Returns the example.String
getHelpDescription()
Returns a long help description, e.g., used in tiptexts.String
getHelpIcon()
Returns the name of a help icon, e.g., used for buttons.String
getHelpTitle()
Returns a short title for the help, e.g., used for buttons.String
getHelpURL()
Returns a URL with additional information.int[]
getIntIndices()
Returns the integer indices.int
getMax()
Returns the maximum.String
getRange()
Returns the currently set range.boolean
hasRange()
Checks whether a valid range has been supplied.protected void
initialize()
The initializes the members.boolean
isAllRange()
Returns whether the range encompasses all.boolean
isEmpty()
Returns whether the range is empty.boolean
isInRange(int index)
Checks whether the provided 0-based index is within the range.static boolean
isValid(String s, int max)
Returns whether the range string is valid.protected void
parse()
Parses the range.protected int[]
parseSubRange(String subrange)
Parses the subrange.protected void
reset()
Resets the state.void
setIndices(int[] indices)
Sets the selected indices.void
setIndices(Integer[] indices)
Sets the selected indices.void
setMax(int value)
Sets the maximum (1-max will be allowed).void
setRange(String value)
Sets the range.protected String[]
splitRange(String range)
Splits the range into subranges.String
toDisplay()
Returns the custom display string.String
toExplicitRange()
Returns the explicit range, i.e., just comma-separated (1-based) indices.static UnorderedRange
toRange(int[] indices)
Turns the integer indices into a unordered range object.String
toString()
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:
getClone
in interfaceCloneHandler<UnorderedRange>
- Returns:
- the clone
-
getExample
public String getExample()
Returns the example.- Specified by:
getExample
in interfaceExampleProvider
- Returns:
- the example
-
getHelpURL
public String getHelpURL()
Returns a URL with additional information.- Specified by:
getHelpURL
in interfaceHelpProvider
- Returns:
- the URL, null if not available
-
getHelpDescription
public String getHelpDescription()
Returns a long help description, e.g., used in tiptexts.- Specified by:
getHelpDescription
in 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:
getHelpTitle
in 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:
getHelpIcon
in 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:
compareTo
in 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:
toDisplay
in 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
-
-