ParseUtil { public static double parseDoubleOrDefault(String s, double defaultDouble) { try { return Double.parseDouble(s); } catch (NumberFormatException e) { LOG.trace(DEFAULT_LOG_MSG, s, e); return defaultDouble; } } private  ParseUtil(); static long parseHertz(String hertz); static int parseLastInt(String s, int i); static long parseLastLong(String s, long li); static double parseLastDouble(String s, double d); static String parseLastString(String s); static String byteArrayToHexString(byte[] bytes); static byte[] hexStringToByteArray(String digits); static byte[] asciiStringToByteArray(String text, int length); static byte[] longToByteArray(long value, int valueSize, int length); static long strToLong(String str, int size); static long byteArrayToLong(byte[] bytes, int size); static float byteArrayToFloat(byte[] bytes, int size, int fpBits); static long unsignedIntToLong(int unsignedValue); static long unsignedLongToSignedLong(long unsignedValue); static String hexStringToString(String hexString); static int parseIntOrDefault(String s, int defaultInt); static long parseLongOrDefault(String s, long defaultLong); static long parseUnsignedLongOrDefault(String s, long defaultLong); static double parseDoubleOrDefault(String s, double defaultDouble); static long parseDHMSOrDefault(String s, long defaultLong); static String parseUuidOrDefault(String s, String defaultStr); static String getSingleQuoteStringValue(String line); static String getDoubleQuoteStringValue(String line); static String getStringBetween(String line, char c); static int getFirstIntValue(String line); static int getNthIntValue(String line, int n); static String removeMatchingString(final String original, final String toRemove); static long[] parseStringToLongArray(String s, int[] indices, int length, char delimiter); static int countStringToLongArray(String s, char delimiter); static String getTextBetweenStrings(String text, String before, String after); static long filetimeToUtcMs(long filetime, boolean local); static String parseMmDdYyyyToYyyyMmDD(String dateString); static OffsetDateTime parseCimDateTimeToOffset(String cimDateTime); static boolean filePathStartsWith(List<String> prefixList, String path); static long parseDecimalMemorySizeToBinary(String size); static Pair<String, String> parsePnPDeviceIdToVendorProductId(String pnpDeviceId); static long parseLshwResourceString(String resources); static Pair<String, String> parseLspciMachineReadable(String line); static long parseLspciMemorySize(String line); static List<Integer> parseHyphenatedIntList(String str); static String parseUtAddrV6toIP(int[] utAddrV6); static long hexStringToLong(String hexString, long defaultValue); static String removeLeadingDots(String dotPrefixedStr); static final Pattern whitespacesColonWhitespace; static final Pattern whitespaces; static final Pattern notDigits; static final Pattern startWithNotDigits; static final Pattern slash; }
@Test public void testParseDoubleOrDefault() { assertEquals(1.23d, ParseUtil.parseDoubleOrDefault("1.23", 4.5d), Double.MIN_VALUE); assertEquals(4.5d, ParseUtil.parseDoubleOrDefault("one.twentythree", 4.5d), Double.MIN_VALUE); }