Java Code Examples for org.apache.commons.lang3.math.NumberUtils.toLong()

The following are Jave code examples for showing how to use toLong() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cas-5.1.0   File: OidcAuthorizationRequestSupport.java   View Source Code Vote up 5 votes
/**
 * Gets oidc max age from authorization request.
 *
 * @param context the context
 * @return the oidc max age from authorization request
 */
public static Optional<Long> getOidcMaxAgeFromAuthorizationRequest(final WebContext context) {
    final URIBuilder builderContext = new URIBuilder(context.getFullRequestURL());
    final Optional<URIBuilder.BasicNameValuePair> parameter = builderContext.getQueryParams()
            .stream().filter(p -> OidcConstants.MAX_AGE.equals(p.getName()))
            .findFirst();

    if (parameter.isPresent()) {
        final long maxAge = NumberUtils.toLong(parameter.get().getValue(), -1);
        return Optional.of(maxAge);
    }
    return Optional.empty();
}
 
Example 2
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static final Long getBigFileThreshold() {
  if (bigFileThreshold == null) {
    String bigThresholdValue = configure.get("filecloud.bigfile-threshold");
    if (StringUtils.isNotBlank(bigThresholdValue) && NumberUtils.isNumber(bigThresholdValue.trim())) {
      bigFileThreshold = NumberUtils.toLong(bigThresholdValue.trim());
    } else {
      bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
    }
  }
  return bigFileThreshold;
}
 
Example 3
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static final Long getFileExpireTimeLength() {
  if (fileExpireTimeLength == null) {
    String fileExpireTimeValue = configure.get("filecloud.file-expire-time-length");
    if (StringUtils.isNotBlank(fileExpireTimeValue) && NumberUtils.isNumber(fileExpireTimeValue.trim())) {
      fileExpireTimeLength = NumberUtils.toLong(fileExpireTimeValue.trim());
    } else {
      fileExpireTimeLength = DEFAULT_FILE_EXPIRE_SECONDS;
    }
  }
  return fileExpireTimeLength;
}
 
Example 4
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static final Long getProtocolMaxSize() {
  if (protocolMaxSize == null) {
    String protocolMaxsizeValue = configure.get("filecloud.protocol-maxsize");
    if (StringUtils.isNotBlank(protocolMaxsizeValue) && NumberUtils.isNumber(protocolMaxsizeValue.trim())) {
      protocolMaxSize = NumberUtils.toLong(protocolMaxsizeValue.trim());
    } else {
      protocolMaxSize = DEFAULT_PROTOCOL_MAXSIZE;
    }
  }
  return protocolMaxSize;
}
 
Example 5
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static Long getMinExpireTimeLength() {
  if (minExpireTimeLength == null) {
    String minExpireTime = configure.get("filecloud.min-expire-time-length");
    if (StringUtils.isNotBlank(minExpireTime) && NumberUtils.isNumber(minExpireTime)) {
      minExpireTimeLength = NumberUtils.toLong(minExpireTime);
      if (minExpireTimeLength < 600) {
        minExpireTimeLength = 600L;
      }
    } else {
      minExpireTimeLength = 600L;
    }
  }
  return minExpireTimeLength;
}
 
Example 6
Project: vscrawler   File: BerkeleyDBSeedManager.java   View Source Code Vote up 5 votes
private BloomFilter<Seed> getOrCreate(String segment) {
    BloomFilter<Seed> seedBloomFilter = bloomFilters.get(segment);
    if (seedBloomFilter != null) {
        return seedBloomFilter;
    }
    synchronized (segment.intern()) {
        seedBloomFilter = bloomFilters.get(segment);
        if (seedBloomFilter != null) {
            return seedBloomFilter;
        }

        long expectedNumber = NumberUtils.toLong(VSCrawlerContext.vsCrawlerConfigFileWatcher.loadedProperties()
                .getProperty(VSCrawlerConstant.VSCRAWLER_SEED_MANAGER_EXPECTED_SEED_NUMBER), 1000000L);

        // any way, build a filter instance if not exist
        seedBloomFilter = BloomFilter.create(new Funnel<Seed>() {
            @Override
            public void funnel(Seed from, PrimitiveSink into) {
                into.putString(seedKeyResolver.resolveSeedKey(from), Charset.defaultCharset());
            }
        }, expectedNumber);

        bloomFilters.put(segment, seedBloomFilter);
    }
    return seedBloomFilter;
}
 
Example 7
Project: azeroth   File: RedisNumber.java   View Source Code Vote up 4 votes
public Long getLong() {
    String value = super.get();
    return value == null ? null : NumberUtils.toLong(value);
}
 
Example 8
Project: openmrs-contrib-addonindex   File: OpenmrsVersionCompareUtil.java   View Source Code Vote up 4 votes
/**
 * Compares <code>version</code> to <code>value</code> version and value are strings like
 * 1.9.2.0 Returns <code>0</code> if either <code>version</code> or <code>value</code> is null.
 *
 * @param version String like 1.9.2.0
 * @param value   String like 1.9.2.0
 * @return the value <code>0</code> if <code>version</code> is equal to the argument
 * <code>value</code>; a value less than <code>0</code> if <code>version</code> is
 * numerically less than the argument <code>value</code>; and a value greater than
 * <code>0</code> if <code>version</code> is numerically greater than the argument
 * <code>value</code>
 * @should correctly comparing two version numbers
 * @should treat SNAPSHOT as earliest version
 */
public static int compareVersion(String version, String value) {
	try {
		if (version == null || value == null) {
			return 0;
		}
		
		List<String> versions = new Vector<String>();
		List<String> values = new Vector<String>();
		String separator = "-";
		
		// strip off any qualifier e.g. "-SNAPSHOT"
		int qualifierIndex = version.indexOf(separator);
		if (qualifierIndex != -1) {
			version = version.substring(0, qualifierIndex);
		}
		
		qualifierIndex = value.indexOf(separator);
		if (qualifierIndex != -1) {
			value = value.substring(0, qualifierIndex);
		}
		
		Collections.addAll(versions, version.split("\\."));
		Collections.addAll(values, value.split("\\."));
		
		// match the sizes of the lists
		while (versions.size() < values.size()) {
			versions.add("0");
		}
		while (values.size() < versions.size()) {
			values.add("0");
		}
		
		for (int x = 0; x < versions.size(); x++) {
			String verNum = versions.get(x).trim();
			String valNum = values.get(x).trim();
			Long ver = NumberUtils.toLong(verNum, 0);
			Long val = NumberUtils.toLong(valNum, 0);
			
			int ret = ver.compareTo(val);
			if (ret != 0) {
				return ret;
			}
		}
	}
	catch (NumberFormatException e) {
		log.error("Error while converting a version/value to an integer: " + version + "/" + value, e);
	}
	
	// default return value if an error occurs or elements are equal
	return 0;
}
 
Example 9
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
/**
 * 将10进制的String安全的转化为long,当str为空或非数字字符串时,返回0
 */
public static long toLong(String str) {
	return NumberUtils.toLong(str, 0L);
}
 
Example 10
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
/**
 * 将10进制的String安全的转化为long,当str为空或非数字字符串时,返回default值
 */
public static long toLong(String str, long defaultValue) {
	return NumberUtils.toLong(str, defaultValue);
}
 
Example 11
Project: para-search-elasticsearch   File: ElasticSearchUtils.java   View Source Code Vote up 2 votes
/**
 * @param v search term
 * @return the long value of v if it is a number
 */
static Object getNumericValue(String v) {
	return NumberUtils.isDigits(v) ? NumberUtils.toLong(v, 0) : v;
}