/** * Parse the given {@link Object} as long with radix {@value #DEFAULT_RADIX}. * * @param aObject * The object to parse. May be <code>null</code>. * @param nDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the object does not represent a valid value. */ public static long parseLong (@Nullable final Object aObject, final long nDefault) { return parseLong (aObject, DEFAULT_RADIX, nDefault); }
/** * Parse the given {@link String} as long with radix {@value #DEFAULT_RADIX}. * * @param sStr * The string to parse. May be <code>null</code>. * @param nDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default if the string does not represent a valid value. */ public static long parseLong (@Nullable final String sStr, final long nDefault) { return parseLong (sStr, DEFAULT_RADIX, nDefault); }
@Nonnull public Date convert (@Nonnull final Object aSource) { return new Date (StringParser.parseLong ((String) aSource, 0)); } });
@Nonnull public Calendar convert (@Nonnull final Object aSource) { final Calendar aCal = Calendar.getInstance (); aCal.setTimeInMillis (StringParser.parseLong ((String) aSource, 0)); return aCal; } });
public static long getAsLong (@Nullable final String sParamName, @Nullable final Object aValue, final long nDefault) { if (aValue == null) return nDefault; if (aValue instanceof Number) return ((Number) aValue).longValue (); // Interpret as String final String sValue = getAsString (sParamName, aValue, null); return StringParser.parseLong (sValue, nDefault); }
/** * Parse the given {@link Object} as long with the specified radix. * * @param aObject * The object to parse. May be <code>null</code>. * @param nRadix * The radix to use. Must be ≥ {@link Character#MIN_RADIX} and ≤ * {@link Character#MAX_RADIX}. * @param nDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the object does not represent a valid value. */ public static long parseLong (@Nullable final Object aObject, @Nonnegative final int nRadix, final long nDefault) { if (aObject == null) return nDefault; if (aObject instanceof Number) return ((Number) aObject).longValue (); return parseLong (aObject.toString (), nRadix, nDefault); }
@Override protected final long readAndUpdateIDCounter (@Nonnegative final int nReserveCount) { final String sContent = SimpleFileIO.readFileAsString (m_aFile, CHARSET_TO_USE); final long nRead = sContent != null ? StringParser.parseLong (sContent.trim (), 0) : 0; SimpleFileIO.writeFile (m_aFile, Long.toString (nRead + nReserveCount), CHARSET_TO_USE); return nRead; }