/** * <p>Convert a <code>String</code> to a <code>long</code>, returning * <code>zero</code> if the conversion fails.</p> * * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p> * * <pre> * NumberUtils.toLong(null) = 0L * NumberUtils.toLong("") = 0L * NumberUtils.toLong("1") = 1L * </pre> * * @param str the string to convert, may be null * @return the long represented by the string, or <code>0</code> if * conversion fails * @since 2.1 */ public static long toLong(String str) { return toLong(str, 0L); }
@Override public long queryServerId() throws IOException { ResultSetPacket resultSetPacket = query("show variables like 'server_id'"); List<String> fieldValues = resultSetPacket.getFieldValues(); if (fieldValues == null || fieldValues.size() != 2) { return 0; } return NumberUtils.toLong(fieldValues.get(1)); }
public static <A> Long firstLong( List<A> list ) { A a = first( list ); if ( a == null ) { return null; } if ( a instanceof Long ) { return ( Long ) a; } try { return NumberUtils.toLong( ( String ) a ); } catch ( Exception e ) { logger.warn( "Could not convert list item {} to long", a, e ); } return null; }
public static <A> Long firstLong( List<A> list ) { A a = first( list ); if ( a == null ) { return null; } if ( a instanceof Long ) { return ( Long ) a; } try { return NumberUtils.toLong( ( String ) a ); } catch ( Exception e ) { logger.warn( "Could not convert list item {} to long", a, e ); } return null; }
public static long getLong( Object obj ) { if ( obj instanceof Long ) { return ( Long ) obj; } if ( obj instanceof Number ) { return ( ( Number ) obj ).longValue(); } if ( obj instanceof String ) { return NumberUtils.toLong( ( String ) obj ); } if ( obj instanceof Date ) { return ( ( Date ) obj ).getTime(); } if ( obj instanceof byte[] ) { return getLong( ( byte[] ) obj ); } if ( obj instanceof ByteBuffer ) { return getLong( ( ByteBuffer ) obj ); } return 0; }
public static long getLong( Object obj ) { if ( obj instanceof Long ) { return ( Long ) obj; } if ( obj instanceof Number ) { return ( ( Number ) obj ).longValue(); } if ( obj instanceof String ) { return NumberUtils.toLong( ( String ) obj ); } if ( obj instanceof Date ) { return ( ( Date ) obj ).getTime(); } if ( obj instanceof byte[] ) { return getLong( ( byte[] ) obj ); } if ( obj instanceof ByteBuffer ) { return getLong( ( ByteBuffer ) obj ); } return 0; }
public static long parseLong(String s, long defaultValue) { return NumberUtils.toLong(s, defaultValue); }
/** * Get property as long. * * @param key property key * @return property long value */ public long getPropertyLong(String key) { return NumberUtils.toLong(getProperty(key)); }
/** * Get the parameter passed by controller. When it's executed in the * validation mode, always returns the given default value 0. * * @return param. 0 if the param was not provided. * @since 3.2.3 */ public static long getParamLong() { return NumberUtils.toLong(getParam("0"), 0); }
OVFDisk od = new OVFDisk(); String virtualSize = disk.getAttribute("ovf:capacity"); od._capacity = NumberUtils.toLong(virtualSize, 0L); String allocationUnits = disk.getAttribute("ovf:capacityAllocationUnits"); od._diskId = disk.getAttribute("ovf:diskId"); od._fileRef = disk.getAttribute("ovf:fileRef"); od._populatedSize = NumberUtils.toLong(disk.getAttribute("ovf:populatedSize"));
/** * Checks whether a given value is greater than given min value or not * * @param validationObject * @param annotate * @return */ private boolean validateMinValue(Object validationObject, Annotation annotate) { if (checkNullObject(validationObject)) { return true; } Long minValue = ((Min) annotate).value(); if (checkvalidDigitTypes(validationObject.getClass())) { if ((NumberUtils.toLong(toString(validationObject))) < minValue) { throwValidationException(((Min) annotate).message()); } } return true; }
/** * Checks whether a given value is lesser than given max value or not * * @param validationObject * @param annotate * @return */ private boolean validateMaxValue(Object validationObject, Annotation annotate) { if (checkNullObject(validationObject)) { return true; } Long maxValue = ((Max) annotate).value(); if (checkvalidDigitTypes(validationObject.getClass())) { if ((NumberUtils.toLong(toString(validationObject))) > maxValue) { throwValidationException(((Max) annotate).message()); } } return true; }
/** * Parse a number, passed as String, and return his Long * @param value the string to parse * @return the parsed long, or <code>0L</code> if parse fails * @see {@link NumberUtils#toLong()} */ public static Long toLong(String value) { return NumberUtils.toLong(value, 0); }
/** * Converts a text value to a long integer. * * @param text Value to convert. * @return The result of the conversion. */ public static long toLong(String text) { return NumberUtils.toLong(text); }
/** * Converts a text value to a long integer. * * @param text Value to convert. * @return The result of the conversion. */ public static long toLong(String text) { return NumberUtils.toLong(text); }
public long getXWikiPreferenceAsLong(String preference, String fallbackParameter, long defaultValue, XWikiContext context) { return NumberUtils.toLong(getXWikiPreference(preference, fallbackParameter, "", context), defaultValue); }
private void incrementSuperbatchVersion() { final String versionString = getSuperBatchVersion(); final Long superbatchVersion = NumberUtils.toLong(versionString, 1L); applicationProperties.setString(APKeys.WEB_RESOURCE_SUPER_BATCH_FLUSH_COUNTER, Long.toString(superbatchVersion + 1)); }
public long getMaxSize() { if (maxSize != Long.MIN_VALUE) { return maxSize; } final String maxSizeProperty = getApplicationProperties().getDefaultBackedString(APKeys.JIRA_ATTACHMENT_SIZE); maxSize = NumberUtils.toLong(maxSizeProperty, -1); return maxSize; }
long getLong(Object o) { if (o instanceof Integer || o instanceof Long) { return Field.getLong(o); } else if (o instanceof String && NumberUtils.isDigits((String) o)) { return NumberUtils.toLong((String) o, 0L); } else { return 0L; } }
public void sync() { rootElement.javascript().mouse().mouseover(); final PageElement syncIcon = getSyncIcon(); waitUntilTrue(syncIcon.timed().isPresent()); TimedQuery<Long> lastSync = Queries.forSupplier(timeouts, () -> NumberUtils.toLong(syncIcon.getAttribute("data-last-sync")), TimeoutType.SLOW_PAGE_LOAD); final long lastSyncBefore = lastSync.now(); syncIcon.javascript().mouse().click(); waitUntil(lastSync, greaterThan(lastSyncBefore)); waitUntilFalse(syncIcon.withTimeout(TimeoutType.SLOW_PAGE_LOAD).timed().hasClass("running")); }