Package adams.core
Class AbstractDataBackedIndex<T>
- java.lang.Object
-
- adams.core.Index
-
- adams.core.AbstractDataBackedIndex<T>
-
- Type Parameters:
T- the type of the underlying data
- All Implemented Interfaces:
CloneHandler<Index>,CustomDisplayStringProvider,ExampleProvider,HelpProvider,Serializable,Comparable<Index>
- Direct Known Subclasses:
SheetIndex,SpreadSheetColumnIndex,SpreadSheetRowIndex,WekaAttributeIndex,WekaLabelIndex
public abstract class AbstractDataBackedIndex<T> extends Index
Ancestor for index classes that can use names as index as well as the placeholders like 'first' and 'last'. Numeric indices can be forced by using a "#" at start (eg "#12"). Names can be surrounded by double quotes.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractDataBackedIndex()Initializes with no index.AbstractDataBackedIndex(String index)Initializes with the given index, but no maximum.AbstractDataBackedIndex(String index, int max)Initializes with the given index and maximum.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Stringclean(String s)Cleanses the given string.AbstractDataBackedIndex<T>getClone()Returns a clone of the object.TgetData()Returns the underlying dataset.HashMap<String,Integer>getIndices()Returns the indices in use.intgetIntIndex(T data)Returns the integer representation of the index.protected abstract StringgetName(T data, int colIndex)Returns the name at the specified index.protected List<String>getNames()Returns the names.protected abstract intgetNumNames(T data)Returns the number of names the data has.protected voidinitialize()For initializing the object.protected booleanisName(String s)Checks whether the strings represents a name.protected intparse(String s, int max)Parses the string and checks it against the maximum.protected StringreplaceName(String s)Replaces any name in the string with the actual 1-based index.voidsetData(T value)Sets the dataset to use for interpreting the name.-
Methods inherited from class adams.core.Index
compareTo, equals, getExample, getHelpDescription, getHelpIcon, getHelpTitle, getHelpURL, getIndex, getIntIndex, getMax, hashCode, hasIndex, isEmpty, isPlaceholder, parsePlaceholder, reset, setIndex, setMax, toDisplay, toString
-
-
-
-
Constructor Detail
-
AbstractDataBackedIndex
public AbstractDataBackedIndex()
Initializes with no index.
-
AbstractDataBackedIndex
public AbstractDataBackedIndex(String index)
Initializes with the given index, but no maximum.- Parameters:
index- the index to use
-
AbstractDataBackedIndex
public AbstractDataBackedIndex(String index, int max)
Initializes with the given index and maximum.- Parameters:
index- the index 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:
initializein classIndex
-
setData
public void setData(T value)
Sets the dataset to use for interpreting the name.- Parameters:
value- the dataset to use, can be null
-
getData
public T getData()
Returns the underlying dataset.- Returns:
- the underlying dataset, null if none set
-
getIntIndex
public int getIntIndex(T data)
Returns the integer representation of the index. Uses on a clone of itself as not to keep a reference to the data.- Parameters:
data- the data to use for determining the index- Returns:
- the integer index, -1 if not possible
-
getClone
public AbstractDataBackedIndex<T> getClone()
Returns a clone of the object.- Specified by:
getClonein interfaceCloneHandler<T>- Overrides:
getClonein classIndex- Returns:
- the clone
-
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
-
getIndices
public HashMap<String,Integer> getIndices()
Returns the indices in use.- Returns:
- the indices
-
replaceName
protected String replaceName(String s)
Replaces any name in the string with the actual 1-based index.- Parameters:
s- the string to process- Returns:
- the (potentially) updated string
-
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
-
clean
protected String clean(String s)
Cleanses the given string. Only allows "first", "last" and numbers.
-
-