ParseUtil { public static long parseDHMSOrDefault(String s, long defaultLong) { Matcher m = DHMS.matcher(s); if (m.matches()) { long milliseconds = 0L; if (m.group(1) != null) { milliseconds += parseLongOrDefault(m.group(1), 0L) * 86_400_000L; } if (m.group(2) != null) { milliseconds += parseLongOrDefault(m.group(2), 0L) * 3_600_000L; } if (m.group(3) != null) { milliseconds += parseLongOrDefault(m.group(3), 0L) * 60_000L; } milliseconds += parseLongOrDefault(m.group(4), 0L) * 1000L; milliseconds += (long) (1000 * parseDoubleOrDefault("0." + m.group(5), 0d)); return milliseconds; } return defaultLong; } 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 testParseDHMSOrDefault() { assertEquals(93784050L, ParseUtil.parseDHMSOrDefault("1-02:03:04.05", 0L)); assertEquals(93784000L, ParseUtil.parseDHMSOrDefault("1-02:03:04", 0L)); assertEquals(7384000L, ParseUtil.parseDHMSOrDefault("02:03:04", 0L)); assertEquals(184050L, ParseUtil.parseDHMSOrDefault("03:04.05", 0L)); assertEquals(184000L, ParseUtil.parseDHMSOrDefault("03:04", 0L)); assertEquals(4000L, ParseUtil.parseDHMSOrDefault("04", 0L)); assertEquals(0L, ParseUtil.parseDHMSOrDefault("04:05-06", 0L)); }