Record Class CellData
- Record Components:
columnIndex- the column index of the cell (0-based)formattedValue- the formatted string value extracted from Excel
Provides utility methods to convert the cell's value into various Java types, including number, string, boolean, date/time, etc.
- Since:
- 2025-07-19
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDateFormat(String pattern) Adds a custom date format pattern forasLocalDate().static voidaddDateTimeFormat(String pattern) Adds a custom date-time format pattern forasLocalDateTime().<R> @Nullable RConverts the cell value using a custom conversion function.<R> RConverts the cell value using a custom function, returning the given default if blank.@Nullable BigDecimalConverts the value toBigDecimalwith full precision.booleanConverts the value to a boolean.@Nullable BooleanConverts the value to a nullableBoolean.@Nullable DoubleasDouble()Converts the value toDouble.doubleasDouble(double defaultValue) Converts the cell value toDouble, returning the given default if blank.<E extends Enum<E>>
@Nullable EConverts the value to an enum constant by name (case-insensitive).@Nullable FloatasFloat()Converts the value toFloat.@Nullable IntegerasInt()Converts the value toInteger.intasInt(int defaultValue) Converts the cell value toInteger, returning the given default if blank.@Nullable LocalDateConverts the formatted value toLocalDateusing multiple supported date formats.@Nullable LocalDateasLocalDate(String format) Converts the value toLocalDateusing the specified format.@Nullable LocalDateTimeConverts the formatted value toLocalDateTimeusing multiple supported date-time formats.@Nullable LocalDateTimeasLocalDateTime(String format) Converts the value toLocalDateTimeusing the specified format.@Nullable LocalTimeConverts the value toLocalTimeusing ISO format (HH:mm:ss).@Nullable LocalTimeasLocalTime(String format) Converts the value toLocalTimeusing the specified format.@Nullable LongasLong()Converts the value toLong.longasLong(long defaultValue) Converts the cell value toLong, returning the given default if blank.@Nullable NumberasNumber()Parses the value as aNumberusing the configured default locale.@Nullable NumberParses the value as aNumberusing the given locale.asString()Returns the raw string as-is.Returns the string value, or the given default if blank.@Nullable ZonedDateTimeasZonedDateTime(String format, ZoneId zone) Converts the value toZonedDateTimeusing the specified format and time zone.@Nullable ZonedDateTimeasZonedDateTime(ZoneId zone) Converts the value toZonedDateTimeby parsing asLocalDateTimeand attaching the given time zone.intReturns the value of thecolumnIndexrecord component.final booleanIndicates whether some other object is "equal to" this one.@Nullable StringReturns the value of theformattedValuerecord component.static List<DateTimeFormatter> Returns an unmodifiable view of the currently registered date format patterns.static List<DateTimeFormatter> Returns an unmodifiable view of the currently registered date-time format patterns.static LocaleReturns the default locale used by no-arg number parsing methods.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Checks if the value is empty or blank.static voidResets the date format patterns to the built-in defaults.static voidResets the date-time format patterns to the built-in defaults.static voidsetDefaultLocale(Locale locale) Sets the default locale for number parsing.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
CellData
Validates and normalizes the cell data.
-
-
Method Details
-
getDefaultLocale
Returns the default locale used by no-arg number parsing methods.- Returns:
- The current default locale
-
setDefaultLocale
Sets the default locale for number parsing. Affects all subsequent calls toasNumber(),asLong(),asInt(),asDouble(),asFloat(), andasBigDecimal().The default value is
Locale.getDefault().- Parameters:
locale- The locale to use as default (must not be null)
-
addDateFormat
Adds a custom date format pattern forasLocalDate(). The pattern is inserted at the beginning of the list so it takes priority over built-in patterns.This method is thread-safe.
- Parameters:
pattern- the date pattern (e.g., "dd.MM.yyyy")
-
addDateTimeFormat
Adds a custom date-time format pattern forasLocalDateTime(). The pattern is inserted at the beginning of the list so it takes priority over built-in patterns.This method is thread-safe.
- Parameters:
pattern- the date-time pattern (e.g., "dd.MM.yyyy HH:mm:ss")
-
getDateFormats
Returns an unmodifiable view of the currently registered date format patterns.- Returns:
- the list of date format patterns
-
getDateTimeFormats
Returns an unmodifiable view of the currently registered date-time format patterns.- Returns:
- the list of date-time format patterns
-
resetDateFormats
public static void resetDateFormats()Resets the date format patterns to the built-in defaults. Removes any custom patterns previously added viaaddDateFormat(String).This method is thread-safe.
-
resetDateTimeFormats
public static void resetDateTimeFormats()Resets the date-time format patterns to the built-in defaults. Removes any custom patterns previously added viaaddDateTimeFormat(String).This method is thread-safe.
-
asNumber
Parses the value as aNumberusing the given locale. This method removes formatting characters such as commas, currency symbols, and percent signs. Returnsnullif the value is empty or blank.- Parameters:
locale- the locale to use for number formatting (e.g.Locale.KOREA)- Returns:
- parsed number, or
nullif empty or blank - Throws:
IllegalArgumentException- if parsing fails
-
asNumber
Parses the value as aNumberusing the configured default locale. Returnsnullif the value is empty or blank.- Returns:
- parsed number, or
nullif blank - See Also:
-
asLong
Converts the value toLong. Returnsnullif the value is empty or blank.- Returns:
- the long value, or
nullif blank
-
asInt
Converts the value toInteger. Returnsnullif the value is empty or blank. Throws if the long value is out of int range.- Returns:
- the integer value, or
nullif blank
-
asString
Returns the raw string as-is.- Returns:
- the formatted string value
-
asBoolean
public boolean asBoolean()Converts the value to a boolean.Accepts "true", "1", "y", "yes" (case-insensitive) as
true. Returnsfalseif the value is empty, blank, or does not match any recognized true value.- Returns:
trueif the value represents a true-like string, otherwisefalse
-
asBooleanOrNull
Converts the value to a nullableBoolean.Returns
nullif the value is empty or blank, allowing callers to distinguish between "no value" and an explicitfalse. Accepts "true", "1", "y", "yes" (case-insensitive) astrue; all other non-blank values are treated asfalse.- Returns:
Boolean.TRUE,Boolean.FALSE, ornullif blank
-
asLocalDateTime
Converts the formatted value toLocalDateTimeusing multiple supported date-time formats. Returnsnullif the value is empty or blank. Supported formats include: - yyyy-MM-dd[ HH:mm[:ss]] - yyyy/MM/dd[ HH:mm[:ss]] - MM/dd/yy[ HH:mm[:ss]] - M/d/yy[ HH:mm[:ss]] - ISO_LOCAL_DATE_TIME The patterns support optional sections for time (hours, minutes, seconds). If all patterns fail, aDateTimeParseExceptionwill be thrown.- Returns:
- the parsed date-time, or
nullif blank
-
asLocalDateTime
Converts the value toLocalDateTimeusing the specified format. Returnsnullif the value is empty or blank.- Parameters:
format- the date-time pattern (e.g., "yyyy-MM-dd HH:mm:ss")- Returns:
- the parsed date-time, or
nullif blank
-
asLocalDate
Converts the formatted value toLocalDateusing multiple supported date formats. Returnsnullif the value is empty or blank. Supported formats include: - yyyy-MM-dd - yyyy/MM/dd - MM/dd/yy - M/d/yy - ISO_LOCAL_DATE If all patterns fail, aDateTimeParseExceptionwill be thrown.- Returns:
- the parsed date, or
nullif blank
-
asLocalDate
Converts the value toLocalDateusing the specified format. Returnsnullif the value is empty or blank.- Parameters:
format- the date pattern (e.g., "yyyy/MM/dd")- Returns:
- the parsed date, or
nullif blank
-
asLocalTime
Converts the value toLocalTimeusing ISO format (HH:mm:ss). Returnsnullif the value is empty or blank.- Returns:
- the parsed time, or
nullif blank
-
asLocalTime
Converts the value toLocalTimeusing the specified format. Returnsnullif the value is empty or blank.- Parameters:
format- the time pattern (e.g., "HH:mm")- Returns:
- the parsed time, or
nullif blank
-
asZonedDateTime
Converts the value toZonedDateTimeby parsing asLocalDateTimeand attaching the given time zone. Returnsnullif the value is empty or blank.- Parameters:
zone- the time zone to apply- Returns:
- the zoned date-time, or
nullif blank - Since:
- 0.9.2
-
asZonedDateTime
Converts the value toZonedDateTimeusing the specified format and time zone. Returnsnullif the value is empty or blank.- Parameters:
format- the date-time patternzone- the time zone to apply- Returns:
- the zoned date-time, or
nullif blank - Since:
- 0.9.2
-
asDouble
Converts the value toDouble. Returnsnullif the value is empty or blank.- Returns:
- the double value, or
nullif blank
-
asFloat
Converts the value toFloat. Returnsnullif the value is empty or blank.- Returns:
- the float value, or
nullif blank
-
asBigDecimal
Converts the value toBigDecimalwith full precision.Unlike
asNumber(), this method parses the cleaned string directly as aBigDecimal, avoiding intermediateDoubleconversion that can lose precision for large or high-precision values. Returnsnullif the value is empty or blank.- Returns:
- the BigDecimal value, or
nullif blank - Throws:
IllegalArgumentException- if the value cannot be parsed as a number
-
isEmpty
public boolean isEmpty()Checks if the value is empty or blank.- Returns:
trueif the formatted value is empty or consists only of whitespace
-
asEnum
Converts the value to an enum constant by name (case-insensitive). Returnsnullif the value is empty or blank.- Type Parameters:
E- the enum type- Parameters:
enumType- the enum class- Returns:
- the matching enum constant, or
nullif blank - Throws:
IllegalArgumentException- if no matching constant is found
-
as
Converts the cell value using a custom conversion function.The function receives the raw string value and returns the converted result. Returns
nullif the value is empty or blank.UUID id = cell.as(UUID::fromString); MyType obj = cell.as(MyType::parse);- Type Parameters:
R- the return type- Parameters:
converter- the conversion function- Returns:
- the converted value, or
nullif blank
-
asInt
public int asInt(int defaultValue) Converts the cell value toInteger, returning the given default if blank.- Parameters:
defaultValue- the value to return if the cell is blank- Returns:
- the parsed integer or the default value
-
asLong
public long asLong(long defaultValue) Converts the cell value toLong, returning the given default if blank.- Parameters:
defaultValue- the value to return if the cell is blank- Returns:
- the parsed long or the default value
-
asDouble
public double asDouble(double defaultValue) Converts the cell value toDouble, returning the given default if blank.- Parameters:
defaultValue- the value to return if the cell is blank- Returns:
- the parsed double or the default value
-
asString
Returns the string value, or the given default if blank.- Parameters:
defaultValue- the value to return if the cell is blank- Returns:
- the string value or the default value
-
as
Converts the cell value using a custom function, returning the given default if blank.UUID id = cell.as(UUID::fromString, DEFAULT_UUID);- Type Parameters:
R- the return type- Parameters:
converter- the conversion functiondefaultValue- the value to return if the cell is blank- Returns:
- the converted value or the default value
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
columnIndex
public int columnIndex()Returns the value of thecolumnIndexrecord component.- Returns:
- the value of the
columnIndexrecord component
-
formattedValue
Returns the value of theformattedValuerecord component.- Returns:
- the value of the
formattedValuerecord component
-