List of usage examples for java.util OptionalDouble of
public static OptionalDouble of(double value)
From source file:com.addthis.bundle.util.AutoField.java
default OptionalDouble getDouble(Bundle bundle) { ValueObject valueObject = getValue(bundle); if (valueObject == null) { return OptionalDouble.empty(); }/*from w w w .j av a2 s .c om*/ return OptionalDouble.of(ValueUtil.asNumberOrParse(valueObject).asDouble().asNative()); }
From source file:ffx.potential.extended.ExtUtils.java
/** * Parse system properties of type String, Boolean, Integer, Double, OptionalInt, and OptionalDouble. * Default value determines the return type. Provides case-insensitivity in property keys. *//*from w w w.j a v a 2s. c o m*/ @SuppressWarnings("unchecked") public static final <T> T prop(String key, T defaultVal) throws NoSuchElementException, NumberFormatException { if (defaultVal == null) { throw new IllegalArgumentException(); } T parsed = null; try { if (System.getProperty(key) == null) { if (System.getProperty(key.toLowerCase()) != null) { key = key.toLowerCase(); } else if (System.getProperty(key.toUpperCase()) != null) { key = key.toUpperCase(); } else { boolean found = false; for (Object search : System.getProperties().keySet()) { if (search instanceof String && ((String) search).equalsIgnoreCase(key)) { key = (String) search; } } if (!found) { return defaultVal; } } } if (defaultVal instanceof String) { parsed = (System.getProperty(key) != null) ? (T) System.getProperty(key) : defaultVal; } else if (defaultVal instanceof Integer) { return (System.getProperty(key) != null) ? (T) Integer.valueOf(System.getProperty(key)) : defaultVal; } else if (defaultVal instanceof OptionalInt) { parsed = (System.getProperty(key) != null) ? (T) OptionalInt.of(Integer.parseInt(System.getProperty(key))) : defaultVal; } else if (defaultVal instanceof Double) { parsed = (System.getProperty(key) != null) ? (T) Double.valueOf(System.getProperty(key)) : defaultVal; } else if (defaultVal instanceof OptionalDouble) { parsed = (System.getProperty(key) != null) ? (T) OptionalDouble.of(Double.parseDouble(System.getProperty(key))) : defaultVal; } else if (defaultVal instanceof Boolean) { if (System.getProperty(key) != null) { if (System.getProperty(key).isEmpty()) { System.setProperty(key, "true"); } parsed = (T) Boolean.valueOf(System.getProperty(key)); } } else { throw new IllegalArgumentException(); } } catch (IllegalArgumentException ex) { String value = (System.getProperty(key) != null) ? System.getProperty(key) : "null"; logger.warning(String.format("Error parsing property %s with value %s; the default is %s.", key, value, defaultVal.toString())); throw ex; } config.addProperty(key, parsed); return parsed; }
From source file:org.apache.lens.cube.parse.SegmentationCandidate.java
@Override public OptionalDouble getCost() { if (areCandidatesPicked()) { double cost = 0.0; for (Candidate candidate : getChildren()) { if (candidate.getCost().isPresent()) { cost += candidate.getCost().getAsDouble(); } else { return OptionalDouble.empty(); }/*from ww w .ja v a 2s . c o m*/ } return OptionalDouble.of(cost); } else { return OptionalDouble.empty(); } }
From source file:org.apache.lens.cube.parse.StorageCandidate.java
@Override public OptionalDouble getCost() { return OptionalDouble.of(fact.weight()); }