/** * 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 an enum. * * @param eClass * enum type * @param defaultValue * This will be returned if there is an error converting the value * @return The value as an enum */ public final <T extends Enum<T>> T toEnum(Class<T> eClass, final T defaultValue) { if (text != null) { try { return toEnum(eClass); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("An error occurred while converting '%s' to a %s: %s", text, eClass, x.getMessage()), x); } } } return defaultValue; }
/** * Convert to time, returning default value if text is inconvertible. * * @param defaultValue * the default value * @return the converted text as a time or the default value if text is inconvertible. */ public final Time toTime(final Time defaultValue) { if (text != null) { try { return toTime(); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "An error occurred while converting '%s' to a Time: %s", text, x.getMessage()), x); } } } return defaultValue; }
/** * 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 boolean, returning default value if text is inconvertible. * * @param defaultValue * the default value * @return the converted text as a boolean or the default value if text is empty or * inconvertible * @see Strings#isTrue(String) */ public final boolean toBoolean(final boolean defaultValue) { if (text != null) { try { return toBoolean(); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "An error occurred while converting '%s' to a boolean: %s", text, x.getMessage()), x); } } } return defaultValue; }
/** * 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 integer, returning default value if text is inconvertible. * * @param defaultValue * the default value * @return the converted text as an integer or the default value if text is not an integer */ public final int toInt(final int defaultValue) { if (text != null) { try { return toInt(); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "An error occurred while converting '%s' to an integer: %s", text, x.getMessage()), x); } } } return defaultValue; }
/** * 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 character, returning default value if text is inconvertible. * * @param defaultValue * the default value * @return the converted text as a primitive char or the default value if text is not a single * character */ public final char toChar(final char defaultValue) { if (text != null) { try { return toChar(); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "An error occurred while converting '%s' to a character: %s", text, x.getMessage()), x); } } } return defaultValue; }
/** * 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 long integer, returning default value if text is inconvertible. * * @param defaultValue * the default value * @return the converted text as a long integer or the default value if text is empty or * inconvertible */ public final long toLong(final long defaultValue) { if (text != null) { try { return toLong(); } catch (StringValueConversionException x) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "An error occurred while converting '%s' to a long: %s", text, x.getMessage()), x); } } } return defaultValue; }
/** * 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 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 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 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 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 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); } }
/** * Converts the 1 character string s to a character. * * @param s * The 1 character string to convert to a char. * @return Character value to convert * @throws StringValueConversionException * when the string is longer or shorter than 1 character, or <code>null</code>. */ public static char toChar(final String s) throws StringValueConversionException { if (s != null) { if (s.length() == 1) { return s.charAt(0); } else { throw new StringValueConversionException("Expected single character, not \"" + s + "\""); } } throw new StringValueConversionException("Character value was null"); }
/** * Converts the 1 character string s to a character. * * @param s * The 1 character string to convert to a char. * @return Character value to convert * @throws StringValueConversionException * when the string is longer or shorter than 1 character, or <code>null</code>. */ public static char toChar(final String s) throws StringValueConversionException { if (s != null) { if (s.length() == 1) { return s.charAt(0); } else { throw new StringValueConversionException("Expected single character, not \"" + s + "\""); } } throw new StringValueConversionException("Character value was null"); }