List of usage examples for com.google.common.primitives Doubles tryParse
@Beta @Nullable @CheckForNull @GwtIncompatible("regular expressions") public static Double tryParse(String string)
From source file:de.bund.bfr.knime.nls.BackwardUtils.java
public static List<Double> stringToDoubleList(String s) { return stringToList(s).stream().map(v -> Doubles.tryParse(v)).collect(Collectors.toList()); }
From source file:com.przemo.etl.transformations.expressions.SimpleNumberEvaluator.java
@Override public boolean isValue(String val) { return ((currentValue = Doubles.tryParse(val)) != null); }
From source file:net.bafeimao.umbrella.support.data.entity.converter.StringToBooleanConverter.java
@Override @Nullable/*w ww.j a v a2 s. c om*/ protected Boolean doForward(String s) { if (!Strings.isNullOrEmpty(s)) { Double d = Doubles.tryParse(s); if (d != null) { return d.intValue() == 0 ? false : true; } else { s = s.trim(); if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t")) { return true; } } } return false; }
From source file:net.bafeimao.umbrella.servers.world.entity.converter.StringToQualityConverter.java
@Override @Nullable// www . j a va2 s.c o m protected Quality doForward(String s) { Double d = Doubles.tryParse(s); if (d != null) { int val = d.intValue(); for (Quality element : Quality.values()) { if (element.getValue() == val) { return element; } } } else { for (Quality element : Quality.values()) { if (s.equalsIgnoreCase(element.toString())) { return element; } } } return null; }
From source file:org.graylog2.inputs.converters.NumericConverter.java
/** * Attempts to convert the provided string value to a numeric type, * trying Integer, Long and Double in order until successful. */// w w w . ja v a 2 s .c o m @Override public Object convert(String value) { if (value == null || value.isEmpty()) { return value; } Object result = Ints.tryParse(value); if (result != null) { return result; } result = Longs.tryParse(value); if (result != null) { return result; } result = Doubles.tryParse(value); if (result != null) { return result; } return value; }
From source file:com.google.template.soy.basicfunctions.ParseFloatFunction.java
@Override public SoyValue computeForJava(List<SoyValue> args) { Double d = Doubles.tryParse(args.get(0).stringValue()); return (d == null || d.isNaN()) ? NullData.INSTANCE : FloatData.forValue(d); }
From source file:org.graylog.plugins.pipelineprocessor.functions.conversion.DoubleConversion.java
@Override public Double evaluate(FunctionArgs args, EvaluationContext context) { final Object evaluated = valueParam.required(args, context); final Double defaultValue = defaultParam.optional(args, context).orElse(0d); if (evaluated == null) { return defaultValue; }//from ww w .ja v a2 s . c o m return firstNonNull(Doubles.tryParse(evaluated.toString()), defaultValue); }
From source file:de.bund.bfr.knime.gis.views.canvas.highlighting.LogicalHighlightCondition.java
public <T extends Element> Map<T, Double> getValues(Collection<? extends T> elements) { doubleValue = value != null ? Doubles.tryParse(value) : null; if (value == null) { booleanValue = null;// www .j a va 2 s .com } else if (value.equalsIgnoreCase("true") || value.equals("1")) { booleanValue = true; } else if (value.equalsIgnoreCase("false") || value.equals("0")) { booleanValue = false; } else { booleanValue = null; } Map<T, Double> result = new LinkedHashMap<>(); elements.forEach(e -> result.put(e, evaluate(e))); return result; }
From source file:org.lbogdanov.poker.util.Settings.java
/** * Returns a value of a setting as <code>Double</code>. The value is returned as an instance of * {@link Optional} class to indicate the fact that it can be missing. * //w w w . ja va 2 s .c o m * @return the value of the setting */ public Optional<Double> asDouble() { return Optional.fromNullable(Doubles.tryParse(asString().or(""))); }
From source file:org.codice.ddf.catalog.ui.forms.model.FilterNodeValueSerializer.java
@Override public boolean serializeField(JsonSerializerInternal serializer, Object parent, FieldAccess fieldAccess, CharBuf builder) {/* ww w .j a va2 s.co m*/ Field field = fieldAccess.getField(); String name = field.getName(); boolean shouldManuallySerialize = ("value".equals(name) || "defaultValue".equals(name)) && field.getType().equals(String.class); if (!shouldManuallySerialize) { LOGGER.trace("Special serialization is not needed for field '{}'", name); return false; } String fieldValue = null; try { fieldValue = (String) field.get(parent); } catch (IllegalAccessException e) { throw new UncheckedIllegalAccessException("Access denied for field 'value' on FilterLeafNode", e); } if (fieldValue == null) { LOGGER.debug("Field '{}' held a null value, no special serialization needed", name); return false; } builder.addJsonFieldName(name); Integer i = Ints.tryParse(fieldValue); if (i != null) { LOGGER.debug("Found Integer '{}' on field '{}', serializing appropriately", i, name); builder.addInt(i); return true; } Double d = Doubles.tryParse(fieldValue); if (d != null) { LOGGER.debug("Found Double '{}' on field '{}', serializing appropriately", d, name); builder.addDouble(d); return true; } if (fieldValue.equalsIgnoreCase("true")) { LOGGER.debug("Found Boolean '{}' on field '{}', serializing appropriately", fieldValue, name); builder.addBoolean(true); return true; } if (fieldValue.equalsIgnoreCase("false")) { LOGGER.debug("Found Boolean '{}' on field '{}', serializing appropriately", fieldValue, name); builder.addBoolean(false); return true; } // Assume plain String LOGGER.debug("Found String '{}' on field '{}', serializing appropriately", fieldValue, name); builder.addQuoted(fieldValue); return true; }