Strings { public static int convertPollingIntervalString(String pollingInterval) { if ((pollingInterval != null) && (pollingInterval.trim().length() != 0)) { pollingInterval = pollingInterval.trim(); char lastChar = pollingInterval.charAt(pollingInterval.length()-1); String timePart = pollingInterval.substring(0, pollingInterval.length()-1); switch (lastChar) { case 's': return Integer.parseInt(timePart) * 1000; case 'm': return Integer.parseInt(timePart) * 1000 * 60; case 'h': return Integer.parseInt(timePart) * 1000 * 60 * 60; default: return Integer.parseInt(pollingInterval); } } return -1; } private  Strings(); static String byteToUnsignedHexString(byte b); static String bytesToHex(byte[] bytes); static String toUpperCase(String str); static String toLowerCase(String str); static int convertPollingIntervalString(String pollingInterval);  }
@Test public void testPollingIntervalConversion() { String _empty = ""; String _empty2 = " "; String _null = null; String _500milli = "500"; String _2s = "2s"; String _23s = "23s"; String _3m = "3m"; String _132m = "132m"; String _2h = "2h"; String _13h = "13h"; Assert.assertEquals(-1, Strings.convertPollingIntervalString(_empty)); Assert.assertEquals(-1, Strings.convertPollingIntervalString(_empty2)); Assert.assertEquals(-1, Strings.convertPollingIntervalString(_null)); Assert.assertEquals(500, Strings.convertPollingIntervalString(_500milli)); Assert.assertEquals(2 * 1000, Strings.convertPollingIntervalString(_2s)); Assert.assertEquals(23 * 1000, Strings.convertPollingIntervalString(_23s)); Assert.assertEquals(3 * 1000 * 60, Strings.convertPollingIntervalString(_3m)); Assert.assertEquals(132 * 1000 * 60, Strings.convertPollingIntervalString(_132m)); Assert.assertEquals(2 * 1000 * 60 * 60, Strings.convertPollingIntervalString(_2h)); Assert.assertEquals(13 * 1000 * 60 * 60, Strings.convertPollingIntervalString(_13h)); }