MCPcopy
hub / github.com/google/guava / tryParse

Method tryParse

guava/src/com/google/common/primitives/Doubles.java:768–781  ·  view source on GitHub ↗

Parses the specified string as a double-precision floating point value. The ASCII character {@code '-'} (<code>'&#92;u002D'</code>) is recognized as the minus sign. <p>Unlike {@link Double#parseDouble(String)}, this method returns {@code null} instead of throwing an exception if parsing fails. Vali

(String string)

Source from the content-addressed store, hash-verified

766 * @since 14.0
767 */
768 @GwtIncompatible // regular expressions
769 public static @Nullable Double tryParse(String string) {
770 if (FLOATING_POINT_PATTERN.matcher(string).matches()) {
771 // TODO(lowasser): could be potentially optimized, but only with
772 // extensive testing
773 try {
774 return parseDouble(string);
775 } catch (NumberFormatException e) {
776 // Double.parseDouble has changed specs several times, so fall through
777 // gracefully
778 }
779 }
780 return null;
781 }
782}

Callers 3

checkTryParseMethod · 0.95
testTryParseFailuresMethod · 0.95

Calls 2

matchesMethod · 0.45
matcherMethod · 0.45

Tested by 3

checkTryParseMethod · 0.76
testTryParseFailuresMethod · 0.76