Package adams.data.spreadsheet
Class FloatCell
- java.lang.Object
-
- adams.data.spreadsheet.FloatCell
-
- All Implemented Interfaces:
Cell
,Serializable
public class FloatCell extends Object implements Cell
Represents a single cell.
Any integer type gets turned into a Long and any floating point type into a Float.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface adams.data.spreadsheet.Cell
Cell.ContentType
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_Calculating
whether a cell calculation is currently happening.protected float
m_Content
the content of the cell.protected Cell.ContentType
m_ContentType
whether the content is numeric.protected String
m_Formula
the formula.protected Object
m_Object
the object.protected Row
m_Owner
the row this cell belongs to.-
Fields inherited from interface adams.data.spreadsheet.Cell
FORMULA_ERROR, PREFIX_FORMULA
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assign(Cell cell)
Obtains the content/type of the other cell, but not the owner.void
calculate()
Recalculates the value from the cell's formula.protected void
calculateIfRequired()
Calculates the cell value if necessary.protected boolean
checkBoolean(String s)
Checks whether the string represents a boolean.protected boolean
checkDate(String s)
Checks whether the string represents a date.protected boolean
checkDateTime(String s)
Checks whether the string represents a date/time.protected boolean
checkDateTimeMsec(String s)
Checks whether the string represents a date/time msec.protected boolean
checkFloat(String s)
Checks whether the string represents a float.protected boolean
checkFormula(String s)
Checks whether the string represents a valid formula.protected boolean
checkLong(String s)
Checks whether the string represents a long.protected boolean
checkTime(String s)
Checks whether the string represents a time.protected boolean
checkTimeMsec(String s)
Checks whether the string represents a time.String
getContent()
Returns the content of the cell.Cell.ContentType
getContentType()
Returns the content type.String
getFormula()
Returns the formula.Object
getNative()
Returns the cell as native object, according to its type.Object
getObject()
Returns the object.Row
getOwner()
Returns the row this cell belongs to.SpreadSheet
getSpreadSheet()
Returns the spreadsheet this cell belongs to.int
index()
Returns the column this cell is in.boolean
isAnyDateType()
Checks whether the cell represents a date, time or date/time value.boolean
isBoolean()
Checks whether the cell represents a boolean value.boolean
isDate()
Checks whether the cell represents a date value.boolean
isDateTime()
Checks whether the cell represents a date/time value.boolean
isDateTimeMsec()
Checks whether the cell represents a date/time value.boolean
isDouble()
Returns whether the content represents a double number.boolean
isFormula()
Returns whether the content represents a formula.boolean
isLong()
Returns whether the content represents a long number.boolean
isMissing()
Checks whether the cell contains a missing value.boolean
isNumeric()
Checks whether the stored string is numeric.boolean
isObject()
Returns whether the content represents an object.boolean
isTime()
Checks whether the cell represents a time value.boolean
isTimeMsec()
Checks whether the cell represents a time/msec value.Cell
parseContent(String value)
Attempts to determine the data type of the string.Object
parseContent(String value, Cell.ContentType type)
Parses the content of the cell using the specified type.Cell
setContent(DateTime value)
Sets the content of the cell.Cell
setContent(DateTimeMsec value)
Sets the content of the cell.Cell
setContent(Time value)
Sets the content of the cell.Cell
setContent(TimeMsec value)
Sets the content of the cell.Cell
setContent(Boolean value)
Sets the content of the cell.Cell
setContent(Byte value)
Sets the content of the cell.Cell
setContent(Double value)
Sets the content of the cell.Cell
setContent(Float value)
Sets the content of the cell.Cell
setContent(Integer value)
Sets the content of the cell.Cell
setContent(Long value)
Sets the content of the cell.Cell
setContent(Short value)
Sets the content of the cell.Cell
setContent(String value)
Sets the content of the cell.Cell
setContent(Date value)
Sets the content of the cell.Cell
setContentAs(String value, Cell.ContentType type)
Sets the content of the cell, trying to parse the content using the specified content type.Cell
setContentAsString(String value)
Sets the string content of the cell.Cell
setFormula(String value)
Sets the formula content of the cell.void
setMissing()
Sets the cell to missing.Cell
setNative(Object value)
Determines the best set-method based on the class of the provided object.Cell
setObject(Object value)
Sets the object content of the cell.void
setOwner(Row owner)
Sets the row this cell belongs to.Date
toAnyDateType()
Returns the date content, null if not a date, time or date/time.Boolean
toBoolean()
Returns the boolean content, null if not a boolean.Date
toDate()
Returns the date content, null if not a date.DateTime
toDateTime()
Returns the date/time content, null if not a date/time.DateTimeMsec
toDateTimeMsec()
Returns the date/time content, null if not a date/time.Double
toDouble()
Returns the content as double, if possible.Long
toLong()
Returns the content as long, if possible.String
toString()
Returns the content of the cell.Time
toTime()
Returns the time content, null if not a time.TimeMsec
toTimeMsec()
Returns the time/msec content, null if not a time/msec.
-
-
-
Field Detail
-
m_Owner
protected Row m_Owner
the row this cell belongs to.
-
m_Content
protected float m_Content
the content of the cell.
-
m_Formula
protected String m_Formula
the formula.
-
m_Object
protected Object m_Object
the object.
-
m_ContentType
protected Cell.ContentType m_ContentType
whether the content is numeric.
-
m_Calculating
protected boolean m_Calculating
whether a cell calculation is currently happening.
-
-
Constructor Detail
-
FloatCell
public FloatCell(Row owner)
Constructor.- Parameters:
owner
- the row this cell belongs to
-
-
Method Detail
-
setOwner
public void setOwner(Row owner)
Sets the row this cell belongs to.
-
getOwner
public Row getOwner()
Returns the row this cell belongs to.
-
getSpreadSheet
public SpreadSheet getSpreadSheet()
Returns the spreadsheet this cell belongs to.- Specified by:
getSpreadSheet
in interfaceCell
- Returns:
- the spreadsheet
-
assign
public void assign(Cell cell)
Obtains the content/type of the other cell, but not the owner.
-
setMissing
public void setMissing()
Sets the cell to missing.- Specified by:
setMissing
in interfaceCell
-
setContent
public Cell setContent(Boolean value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Byte value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Short value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Integer value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Long value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Float value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null or NaN is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Double value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null or NaN is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Date value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(DateTime value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(DateTimeMsec value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(Time value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null is intepreted as missing value- Returns:
- the cell itself
-
setContent
public Cell setContent(TimeMsec value)
Sets the content of the cell.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content; null is intepreted as missing value- Returns:
- the cell itself
-
checkFormula
protected boolean checkFormula(String s)
Checks whether the string represents a valid formula.- Parameters:
s
- the string to check- Returns:
- true if valid formula
-
checkBoolean
protected boolean checkBoolean(String s)
Checks whether the string represents a boolean.- Parameters:
s
- the string to check- Returns:
- true if boolean
-
checkTime
protected boolean checkTime(String s)
Checks whether the string represents a time.- Parameters:
s
- the string to check- Returns:
- true if time
- See Also:
SpreadSheet.getTimeFormat()
-
checkTimeMsec
protected boolean checkTimeMsec(String s)
Checks whether the string represents a time.- Parameters:
s
- the string to check- Returns:
- true if time
- See Also:
SpreadSheet.getTimeMsecFormat()
-
checkDate
protected boolean checkDate(String s)
Checks whether the string represents a date.- Parameters:
s
- the string to check- Returns:
- true if date
- See Also:
SpreadSheet.getDateFormat()
-
checkDateTime
protected boolean checkDateTime(String s)
Checks whether the string represents a date/time.- Parameters:
s
- the string to check- Returns:
- true if date/time
- See Also:
SpreadSheet.getDateTimeFormat()
-
checkDateTimeMsec
protected boolean checkDateTimeMsec(String s)
Checks whether the string represents a date/time msec.- Parameters:
s
- the string to check- Returns:
- true if date/time
- See Also:
SpreadSheet.getDateTimeMsecFormat()
-
checkLong
protected boolean checkLong(String s)
Checks whether the string represents a long.- Parameters:
s
- the string to check- Returns:
- true if time
- See Also:
SpreadSheet.getTimeFormat()
-
checkFloat
protected boolean checkFloat(String s)
Checks whether the string represents a float.- Parameters:
s
- the string to check- Returns:
- true if time
- See Also:
SpreadSheet.getTimeFormat()
-
parseContent
public Cell parseContent(String value)
Attempts to determine the data type of the string.- Specified by:
parseContent
in interfaceCell
- Parameters:
value
- the non-empty string to parse- Returns:
- the cell itself
-
setContent
public Cell setContent(String value)
Sets the content of the cell. Tries to determine whether the cell content is numeric or not.- Specified by:
setContent
in interfaceCell
- Parameters:
value
- the content- Returns:
- the cell itself
-
parseContent
public Object parseContent(String value, Cell.ContentType type)
Parses the content of the cell using the specified type. If the string cannot be parsed according to the type, missing is used instead.- Specified by:
parseContent
in interfaceCell
- Parameters:
value
- the contenttype
- the expected type- Returns:
- the parsed content
-
setContentAsString
public Cell setContentAsString(String value)
Sets the string content of the cell.- Specified by:
setContentAsString
in interfaceCell
- Parameters:
value
- the content- Returns:
- the cell itself
-
setContentAs
public Cell setContentAs(String value, Cell.ContentType type)
Sets the content of the cell, trying to parse the content using the specified content type.- Specified by:
setContentAs
in interfaceCell
- Parameters:
value
- the contenttype
- the type to use- Returns:
- the cell itself
-
setFormula
public Cell setFormula(String value)
Sets the formula content of the cell.- Specified by:
setFormula
in interfaceCell
- Parameters:
value
- the content- Returns:
- the cell itself
-
getFormula
public String getFormula()
Returns the formula.- Specified by:
getFormula
in interfaceCell
- Returns:
- the formula, null if none used
-
getObject
public Object getObject()
Returns the object.
-
getContent
public String getContent()
Returns the content of the cell.- Specified by:
getContent
in interfaceCell
- Returns:
- the content
-
getContentType
public Cell.ContentType getContentType()
Returns the content type.- Specified by:
getContentType
in interfaceCell
- Returns:
- the type
-
setNative
public Cell setNative(Object value)
Determines the best set-method based on the class of the provided object. Fallback is thesetObject(Object)
method.
-
getNative
public Object getNative()
Returns the cell as native object, according to its type. If a cell is missing, the result is theSpreadSheet.MISSING_VALUE
string.
-
index
public int index()
Returns the column this cell is in.
-
isNumeric
public boolean isNumeric()
Checks whether the stored string is numeric.
-
isMissing
public boolean isMissing()
Checks whether the cell contains a missing value.
-
isBoolean
public boolean isBoolean()
Checks whether the cell represents a boolean value.
-
toBoolean
public Boolean toBoolean()
Returns the boolean content, null if not a boolean.
-
isAnyDateType
public boolean isAnyDateType()
Checks whether the cell represents a date, time or date/time value.- Specified by:
isAnyDateType
in interfaceCell
- Returns:
- true if date, time or date/time value
-
toAnyDateType
public Date toAnyDateType()
Returns the date content, null if not a date, time or date/time.- Specified by:
toAnyDateType
in interfaceCell
- Returns:
- the date, null if not date, time or date/time
-
isDate
public boolean isDate()
Checks whether the cell represents a date value.
-
toDate
public Date toDate()
Returns the date content, null if not a date.
-
isDateTime
public boolean isDateTime()
Checks whether the cell represents a date/time value.- Specified by:
isDateTime
in interfaceCell
- Returns:
- true if date/time value
-
toDateTime
public DateTime toDateTime()
Returns the date/time content, null if not a date/time.- Specified by:
toDateTime
in interfaceCell
- Returns:
- the date/time, null if not date/time
-
isDateTimeMsec
public boolean isDateTimeMsec()
Checks whether the cell represents a date/time value.- Specified by:
isDateTimeMsec
in interfaceCell
- Returns:
- true if date/time value
-
toDateTimeMsec
public DateTimeMsec toDateTimeMsec()
Returns the date/time content, null if not a date/time.- Specified by:
toDateTimeMsec
in interfaceCell
- Returns:
- the date/time, null if not date/time
-
isTime
public boolean isTime()
Checks whether the cell represents a time value.
-
toTime
public Time toTime()
Returns the time content, null if not a time.
-
isTimeMsec
public boolean isTimeMsec()
Checks whether the cell represents a time/msec value.- Specified by:
isTimeMsec
in interfaceCell
- Returns:
- true if time/msec value
-
toTimeMsec
public TimeMsec toTimeMsec()
Returns the time/msec content, null if not a time/msec.- Specified by:
toTimeMsec
in interfaceCell
- Returns:
- the time/msec, null if not time/msec
-
toString
public String toString()
Returns the content of the cell.- Specified by:
toString
in interfaceCell
- Overrides:
toString
in classObject
- Returns:
- the content
- See Also:
getContent()
-
isDouble
public boolean isDouble()
Returns whether the content represents a double number.
-
toDouble
public Double toDouble()
Returns the content as double, if possible.
-
isLong
public boolean isLong()
Returns whether the content represents a long number.
-
toLong
public Long toLong()
Returns the content as long, if possible. First, a Float object is created and then the longValue() method called to return the value.
-
isFormula
public boolean isFormula()
Returns whether the content represents a formula.
-
isObject
public boolean isObject()
Returns whether the content represents an object.
-
calculate
public void calculate()
Recalculates the value from the cell's formula.
-
calculateIfRequired
protected void calculateIfRequired()
Calculates the cell value if necessary.
-
-