adams.data.spreadsheet
Class SpreadSheetColumnIndex

java.lang.Object
  extended by adams.core.Index
      extended by adams.data.spreadsheet.SpreadSheetColumnIndex
All Implemented Interfaces:
CustomDisplayStringProvider, ExampleProvider, Serializable, Comparable<Index>

public class SpreadSheetColumnIndex
extends Index

Extended Index class that can use a column name to determine an index of a column as well.

Version:
$Revision: 6866 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
protected  HashMap<String,Integer> m_Indices
          the indices of the column names.
protected  List<String> m_Names
          the column names to replace.
protected  SpreadSheet m_Sheet
          the underlying spreadsheet.
 
Fields inherited from class adams.core.Index
FIRST, LAST, LAST_1, LAST_2, m_Index, m_IntIndex, m_Max, m_Raw, SECOND, THIRD
 
Constructor Summary
SpreadSheetColumnIndex()
          Initializes with no index.
SpreadSheetColumnIndex(String index)
          Initializes with the given index, but no maximum.
SpreadSheetColumnIndex(String index, int max)
          Initializes with the given index and maximum.
 
Method Summary
protected  String clean(String s)
          Cleanses the given string.
 String getExample()
          Returns the example.
 HashMap<String,Integer> getIndices()
          Returns the indices in use.
protected  List<String> getNames()
          Returns the column names.
 SpreadSheet getSpreadSheet()
          Returns the underlying spreadsheet.
protected  void initialize()
          For initializing the object.
protected  boolean isColumnName(String s)
          Checks whether the strings represents a column name.
protected  int parse(String s, int max)
          Parses the string and checks it against the maximum.
protected  String replaceColumnName(String s)
          Replaces any column name in the string with the actual 1-based index.
 void setSpreadSheet(SpreadSheet value)
          Sets the spreadsheet to use for interpreting the column name.
 
Methods inherited from class adams.core.Index
compareTo, equals, getIndex, getIntIndex, getMax, hashCode, hasIndex, isPlaceholder, parsePlaceholder, reset, setIndex, setMax, toDisplay, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Sheet

protected SpreadSheet m_Sheet
the underlying spreadsheet.


m_Names

protected List<String> m_Names
the column names to replace.


m_Indices

protected HashMap<String,Integer> m_Indices
the indices of the column names.

Constructor Detail

SpreadSheetColumnIndex

public SpreadSheetColumnIndex()
Initializes with no index.


SpreadSheetColumnIndex

public SpreadSheetColumnIndex(String index)
Initializes with the given index, but no maximum.

Parameters:
index - the index to use

SpreadSheetColumnIndex

public SpreadSheetColumnIndex(String index,
                              int max)
Initializes with the given index and maximum.

Parameters:
index - the index to use
max - 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 class Index

setSpreadSheet

public void setSpreadSheet(SpreadSheet value)
Sets the spreadsheet to use for interpreting the column name.

Parameters:
value - the spreadsheet to use, can be null

getSpreadSheet

public SpreadSheet getSpreadSheet()
Returns the underlying spreadsheet.

Returns:
the underlying spreadsheet, null if none set

getNames

protected List<String> getNames()
Returns the column names.

Returns:
the column names

getIndices

public HashMap<String,Integer> getIndices()
Returns the indices in use.

Returns:
the indices

replaceColumnName

protected String replaceColumnName(String s)
Replaces any column name in the string with the actual 1-based index.

Parameters:
s - the string to process
Returns:
the (potentially) updated string

isColumnName

protected boolean isColumnName(String s)
Checks whether the strings represents a column name.

Parameters:
s - the string to process
Returns:
true if string is a column name

clean

protected String clean(String s)
Cleanses the given string. Only allows "first", "last" and numbers.

Overrides:
clean in class Index
Parameters:
s - the string to clean
Returns:
the cleansed string, "" if invalid one provided; if no spreadsheet provided, all input is considered valid

parse

protected int parse(String s,
                    int max)
Parses the string and checks it against the maximum.

Overrides:
parse in class Index
Parameters:
s - the string to parse
max - the maximum to allow
Returns:
the parsed value, -1 if invalid

getExample

public String getExample()
Returns the example.

Specified by:
getExample in interface ExampleProvider
Overrides:
getExample in class Index
Returns:
the example


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.