Package adams.data.spreadsheet
Class SpreadSheetHelper
- java.lang.Object
-
- adams.data.spreadsheet.SpreadSheetUtils
-
- adams.data.spreadsheet.SpreadSheetHelper
-
- Direct Known Subclasses:
DatasetUtils
public class SpreadSheetHelper extends SpreadSheetUtils
A helper class for spreadsheet operations.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
-
Fields inherited from class adams.data.spreadsheet.SpreadSheetUtils
PREFIX_COL
-
-
Constructor Summary
Constructors Constructor Description SpreadSheetHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SpreadSheet
append(SpreadSheet first, SpreadSheet second, boolean noCopy)
Appends two spreadsheets.static String
compare(SpreadSheet first, SpreadSheet second)
Compares two spreadsheets.protected static String
compareCells(Cell first, Cell second)
Compares the two cells.static SpreadSheet
convertToNumeric(SpreadSheet sheet, Map<Integer,Map<String,Integer>> mappings, Double missing, double unhandled)
Turns non-numeric cells into numeric ones.static SpreadSheet
mapToSpreadSheet(Map map, String[] header)
Turns the map into a spreadsheet.-
Methods inherited from class adams.data.spreadsheet.SpreadSheetUtils
createHeader, getCellLocation, getCellPosition, getColumn, getColumn, getColumnPosition, getMinMax, getMinMax, getNumericColumn, getNumericRow, getNumericRow, split, split, split, uniqueValues
-
-
-
-
Method Detail
-
append
public static SpreadSheet append(SpreadSheet first, SpreadSheet second, boolean noCopy)
Appends two spreadsheets.- Parameters:
first
- the first spreadsheetsecond
- the second spreadsheetnoCopy
- whether to work with a copy of the first spreadsheet rather than appending the second one directly to it- Returns:
- the combined spreadsheet
-
compareCells
protected static String compareCells(Cell first, Cell second)
Compares the two cells.- Parameters:
first
- the first cellsecond
- the second cell- Returns:
- null if the same, otherwise message on difference
-
compare
public static String compare(SpreadSheet first, SpreadSheet second)
Compares two spreadsheets.- Parameters:
first
- the first spreadsheetsecond
- the second spreadsheet- Returns:
- null if the same, otherwise message indicating (first) difference
-
mapToSpreadSheet
public static SpreadSheet mapToSpreadSheet(Map map, String[] header)
Turns the map into a spreadsheet.- Parameters:
map
- the map to convertheader
- the header names, use null for default- Returns:
- the generated spreadsheet
-
convertToNumeric
public static SpreadSheet convertToNumeric(SpreadSheet sheet, Map<Integer,Map<String,Integer>> mappings, Double missing, double unhandled)
Turns non-numeric cells into numeric ones. Missing cells can get skipped. Booleans gets turned into 0/1 (false/true). Date/time types get turned into numeric ones by using their Java epoch. Strings (per column) get a 0-based index assigned in the order they appear. Any other cell type get flagged as missing or, if provided, set to the unhandled value.- Parameters:
sheet
- the spreadsheet to convertmappings
- the mappings (empty or already filled from previous run): col-index - (string - integer)missing
- the value to replace missing values with, null if to keep missing cellsunhandled
- the value to use for replacing unhandled cell types- Returns:
- the converted spreadsheet (copy)
-
-