📄 stringvalue.java
字号:
* the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final boolean toBoolean(final boolean defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toBoolean(); } /** * Convert this text to a boolean. * * @return Converted text * @throws StringValueConversionException */ public final Boolean toBooleanObject() throws StringValueConversionException { return Strings.toBoolean(text); } /** * Convert this text to a char. * * @return This string value as a character * @throws StringValueConversionException */ public final char toChar() throws StringValueConversionException { return Strings.toChar(text); } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final char toChar(final char defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toChar(); } /** * Convert this text to a Character. * * @return Converted text * @throws StringValueConversionException */ public final Character toCharacter() throws StringValueConversionException { return new Character(toChar()); } /** * Convert this text to a double. * * @return Converted text * @throws StringValueConversionException */ public final double toDouble() throws StringValueConversionException { try { return NumberFormat.getNumberInstance(locale).parse(text).doubleValue(); } catch (ParseException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to a double value", e); } } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final double toDouble(final double defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toDouble(); } /** * Convert this text to a Double. * * @return Converted text * @throws StringValueConversionException */ public final Double toDoubleObject() throws StringValueConversionException { return new Double(toDouble()); } /** * Convert this text to a Duration instance. * * @return Converted text * @throws StringValueConversionException */ public final Duration toDuration() throws StringValueConversionException { return Duration.valueOf(text, locale); } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final Duration toDuration(final Duration defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toDuration(); } /** * Convert this text to an int. * * @return Converted text * @throws StringValueConversionException */ public final int toInt() throws StringValueConversionException { try { return Integer.parseInt(text); } catch (NumberFormatException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to an int value", e); } } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final int toInt(final int defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toInt(); } /** * Convert this text to an Integer. * * @return Converted text * @throws StringValueConversionException */ public final Integer toInteger() throws StringValueConversionException { try { return new Integer(text); } catch (NumberFormatException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to an Integer value", e); } } /** * Convert this text to a long. * * @return Converted text * @throws StringValueConversionException */ public final long toLong() throws StringValueConversionException { try { return Long.parseLong(text); } catch (NumberFormatException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to a long value", e); } } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final long toLong(final long defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toLong(); } /** * Convert this text to a Long. * * @return Converted text * @throws StringValueConversionException */ public final Long toLongObject() throws StringValueConversionException { try { return new Long(text); } catch (NumberFormatException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to a Long value", e); } } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Boolean toOptionalBoolean() throws StringValueConversionException { return (text == null) ? null : toBooleanObject(); } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Character toOptionalCharacter() throws StringValueConversionException { return (text == null) ? null : toCharacter(); } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Double toOptionalDouble() throws StringValueConversionException { return (text == null) ? null : toDoubleObject(); } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Duration toOptionalDuration() throws StringValueConversionException { return (text == null) ? null : toDuration(); } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Integer toOptionalInteger() throws StringValueConversionException { return (text == null) ? null : toInteger(); } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Long toOptionalLong() throws StringValueConversionException { return (text == null) ? null : toLongObject(); } /** * Convert to object types, returning null if text is null. * * @return converted */ public final String toOptionalString() { return text; } /** * Convert to object types, returning null if text is null. * * @return converted * @throws StringValueConversionException */ public final Time toOptionalTime() throws StringValueConversionException { return (text == null) ? null : toTime(); } /** * @return The string value */ public final String toString() { return text; } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null */ public final String toString(final String defaultValue) { return (text == null) ? defaultValue : text; } /** * Convert this text to a time instance. * * @return Converted text * @throws StringValueConversionException */ public final Time toTime() throws StringValueConversionException { try { return Time.valueOf(text); } catch (ParseException e) { throw new StringValueConversionException("Unable to convert '" + text + "' to a Time value", e); } } /** * Convert to primitive types, returning default value if text is null. * * @param defaultValue * the default value to return of text is null * @return the converted text as a primitive or the default if text is null * @throws StringValueConversionException */ public final Time toTime(final Time defaultValue) throws StringValueConversionException { return (text == null) ? defaultValue : toTime(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -