Package adams.core
Class AbstractDataBackedRange<T>
- java.lang.Object
-
- adams.core.Range
-
- adams.core.AbstractDataBackedRange<T>
-
- Type Parameters:
T
- the type of the underlying data
- All Implemented Interfaces:
CloneHandler<Range>
,CustomDisplayStringProvider
,ExampleProvider
,HelpProvider
,Serializable
,Comparable<Range>
- Direct Known Subclasses:
SheetRange
,SpreadSheetColumnRange
,SpreadSheetRowRange
,WekaAttributeRange
,WekaLabelRange
public abstract class AbstractDataBackedRange<T> extends Range
Ancestor for range classes that allow additional names in the range string, just like placeholders for 'first', 'second', etc). If names contain "-" or "," then they need to be surrounded by double-quotes.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractDataBackedRange.InvertedStringLengthComparator
Simply compares the length of the strings, with longer strings rating lower.-
Nested classes/interfaces inherited from class adams.core.Range
Range.SubRange
-
-
Field Summary
Fields Modifier and Type Field Description protected T
m_Data
the underlying dataset.protected HashMap<String,Integer>
m_Indices
the indices of the names.protected List<String>
m_Names
the names to replace.-
Fields inherited from class adams.core.Range
ALL, FIRST, INV_END, INV_START, LAST, LAST_1, LAST_2, m_ActualRange, m_Inverted, m_Max, m_Range, m_Raw, m_SubRanges, NUMERIC_START, RANGE, SECOND, SEPARATOR, THIRD
-
-
Constructor Summary
Constructors Constructor Description AbstractDataBackedRange()
Initializes with no range.AbstractDataBackedRange(String range)
Initializes with the given range, but no maximum.AbstractDataBackedRange(String range, int max)
Initializes with the given range and maximum.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
canReplaceInvalidChars()
Returns whether invalid characters should get removed.static String
escapeName(String col)
Escapes the name, if necessary.AbstractDataBackedRange<T>
getClone()
Returns a clone of the object.T
getData()
Returns the underlying data.HashMap<String,Integer>
getIndices()
Returns the indices in use.HashMap<String,Integer>
getIndices(T data)
Returns the indices in use.int[]
getIntIndices(T data)
Returns the integer indices.int[][]
getIntSegments(T data)
Turns the range into a list of from-to segements.protected abstract String
getName(T data, int colIndex)
Returns the name at the specified index.protected List<String>
getNames()
Returns the names.protected abstract int
getNumNames(T data)
Returns the number of names the data has.protected void
initialize()
For initializing the object.protected void
initLookUp()
Initializes the lookup tables.boolean
isInRange(T data, int index)
Checks whether the provided 0-based index is within the range.protected boolean
isName(String s)
Checks whether the strings represents a name.protected int
parse(String s, int max)
Parses the 1-based index, 'first' and 'last' are accepted as well.protected void
reset()
Resets the object.void
setData(T value)
Sets the data to use for interpreting the names.protected String[]
splitList(String s)
Attempts to split a list into the parts resembling it.protected String[]
splitRange(String s)
Attempts to split a range into the parts resembling it.static String
unescapeName(String col)
Unescapes the name, if necessary.-
Methods inherited from class adams.core.Range
clean, compareTo, equals, getActualRange, getExample, getHelpDescription, getHelpIcon, getHelpTitle, getHelpURL, getIntIndices, getIntSegments, getMax, getRange, getSubRanges, hashCode, hasRange, isAllRange, isEmpty, isInRange, isInverted, isPlaceholder, isValid, parse, parse, parsePlaceholder, setIndices, setIndices, setInverted, setMax, setRange, toDisplay, toExplicitRange, toRange, toString
-
-
-
-
Constructor Detail
-
AbstractDataBackedRange
public AbstractDataBackedRange()
Initializes with no range.
-
AbstractDataBackedRange
public AbstractDataBackedRange(String range)
Initializes with the given range, but no maximum.- Parameters:
range
- the range to use
-
AbstractDataBackedRange
public AbstractDataBackedRange(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()
For initializing the object.- Overrides:
initialize
in classRange
-
getClone
public AbstractDataBackedRange<T> getClone()
Returns a clone of the object.- Specified by:
getClone
in interfaceCloneHandler<T>
- Overrides:
getClone
in classRange
- Returns:
- the clone
-
setData
public void setData(T value)
Sets the data to use for interpreting the names.- Parameters:
value
- the data to use, can be null
-
getData
public T getData()
Returns the underlying data.- Returns:
- the underlying data, null if none set
-
getIndices
public HashMap<String,Integer> getIndices(T data)
Returns the indices in use. Uses on a clone of itself as not to keep a reference to the data.- Parameters:
data
- the data to use for the indices- Returns:
- the indices
-
getIntIndices
public int[] getIntIndices(T data)
Returns the integer indices. Gets always generated on-the-fly! Uses on a clone of itself as not to keep a reference to the data.- Parameters:
data
- the data to use for the indices- Returns:
- the indices, 0-length array if not possible
-
getIntSegments
public int[][] getIntSegments(T data)
Turns the range into a list of from-to segements. The indices are 0-based. In case a subrange consists only of a single index, the second one is the same. NB: Does not check for inverted flag! Uses on a clone of itself as not to keep a reference to the data.- Parameters:
data
- the data to use for the indices- Returns:
- the segments
-
isInRange
public boolean isInRange(T data, int index)
Checks whether the provided 0-based index is within the range. Uses on a clone of itself as not to keep a reference to the data.- Parameters:
data
- the data to use for the indicesindex
- the index to check- Returns:
- true if in range
-
getNumNames
protected abstract int getNumNames(T data)
Returns the number of names the data has.- Parameters:
data
- the data to retrieve the number of names
-
getName
protected abstract String getName(T data, int colIndex)
Returns the name at the specified index.- Parameters:
data
- the data to usecolIndex
- the name index- Returns:
- the name
-
initLookUp
protected void initLookUp()
Initializes the lookup tables.
-
getIndices
public HashMap<String,Integer> getIndices()
Returns the indices in use.- Returns:
- the indices
-
isName
protected boolean isName(String s)
Checks whether the strings represents a name.- Parameters:
s
- the string to process- Returns:
- true if string is a name
-
canReplaceInvalidChars
protected boolean canReplaceInvalidChars()
Returns whether invalid characters should get removed.- Overrides:
canReplaceInvalidChars
in classRange
- Returns:
- true if to replace invalid chars
-
splitRange
protected String[] splitRange(String s)
Attempts to split a range into the parts resembling it.- Overrides:
splitRange
in classRange
- Parameters:
s
- the string to split- Returns:
- the parts (single array element if no range)
-
splitList
protected String[] splitList(String s)
Attempts to split a list into the parts resembling it.
-
parse
protected int parse(String s, int max)
Parses the 1-based index, 'first' and 'last' are accepted as well.
-
escapeName
public static String escapeName(String col)
Escapes the name, if necessary.- Parameters:
col
- the name to (potentially) escape- Returns:
- the processed name
-
-