@Test public void isValidId() { assertFalse(TrackingManager.isValidId(null)); assertFalse(TrackingManager.isValidId("")); assertFalse(TrackingManager.isValidId("ABC")); assertFalse(TrackingManager.isValidId("AA123123123BB")); assertFalse(TrackingManager.isValidId("AA12312312312")); assertFalse(TrackingManager.isValidId("12123123123BB")); assertFalse(TrackingManager.isValidId("1212312312300")); assertFalse(TrackingManager.isValidId("12123123123002")); assertFalse(TrackingManager.isValidId("1212312312312345678")); assertTrue(TrackingManager.isValidId("AA473124829AA")); assertTrue(TrackingManager.isValidId("RA517378152CN")); assertTrue(TrackingManager.isValidId("RA478236464CN")); assertTrue(TrackingManager.isValidId("PH092352111BR")); assertTrue(TrackingManager.isValidId("RA288891469CN")); assertTrue(TrackingManager.isValidId("SG092222385BR")); assertTrue(TrackingManager.isValidId("CF102557845US")); }
public static boolean isValidId(String id) { boolean result = false; if (id != null) { Pattern idPattern = Pattern.compile("^\\w{2}(\\d{9})\\w{2}$"); Matcher matcher = idPattern.matcher(id); if (matcher.matches()) { String number = matcher.group(1); int sum = 0; int mult[] = { 8, 6, 4, 2, 3, 5, 9, 7 }; for (int i = 0; i < 8; i++) { sum += Integer.parseInt(number.substring(i, i + 1)) * mult[i]; } int rest = (sum % 11); int digit; if (rest == 0) { digit = 5; } else if (rest == 1) { digit = 0; } else { digit = 11 - rest; } if (Integer.parseInt(number.substring(8, 9)) == digit) { result = true; } } } return result; }
TrackingManager { public static boolean isValidId(String id) { boolean result = false; if (id != null) { Pattern idPattern = Pattern.compile("^\\w{2}(\\d{9})\\w{2}$"); Matcher matcher = idPattern.matcher(id); if (matcher.matches()) { String number = matcher.group(1); int sum = 0; int mult[] = { 8, 6, 4, 2, 3, 5, 9, 7 }; for (int i = 0; i < 8; i++) { sum += Integer.parseInt(number.substring(i, i + 1)) * mult[i]; } int rest = (sum % 11); int digit; if (rest == 0) { digit = 5; } else if (rest == 1) { digit = 0; } else { digit = 11 - rest; } if (Integer.parseInt(number.substring(8, 9)) == digit) { result = true; } } } return result; } }
TrackingManager { public static boolean isValidId(String id) { boolean result = false; if (id != null) { Pattern idPattern = Pattern.compile("^\\w{2}(\\d{9})\\w{2}$"); Matcher matcher = idPattern.matcher(id); if (matcher.matches()) { String number = matcher.group(1); int sum = 0; int mult[] = { 8, 6, 4, 2, 3, 5, 9, 7 }; for (int i = 0; i < 8; i++) { sum += Integer.parseInt(number.substring(i, i + 1)) * mult[i]; } int rest = (sum % 11); int digit; if (rest == 0) { digit = 5; } else if (rest == 1) { digit = 0; } else { digit = 11 - rest; } if (Integer.parseInt(number.substring(8, 9)) == digit) { result = true; } } } return result; }  }
TrackingManager { public static boolean isValidId(String id) { boolean result = false; if (id != null) { Pattern idPattern = Pattern.compile("^\\w{2}(\\d{9})\\w{2}$"); Matcher matcher = idPattern.matcher(id); if (matcher.matches()) { String number = matcher.group(1); int sum = 0; int mult[] = { 8, 6, 4, 2, 3, 5, 9, 7 }; for (int i = 0; i < 8; i++) { sum += Integer.parseInt(number.substring(i, i + 1)) * mult[i]; } int rest = (sum % 11); int digit; if (rest == 0) { digit = 5; } else if (rest == 1) { digit = 0; } else { digit = 11 - rest; } if (Integer.parseInt(number.substring(8, 9)) == digit) { result = true; } } } return result; }  static boolean isValidId(String id); static Tracking search(String id); static Tracking search(String trackId, Integer start, Integer end, String clientId); }
TrackingManager { public static boolean isValidId(String id) { boolean result = false; if (id != null) { Pattern idPattern = Pattern.compile("^\\w{2}(\\d{9})\\w{2}$"); Matcher matcher = idPattern.matcher(id); if (matcher.matches()) { String number = matcher.group(1); int sum = 0; int mult[] = { 8, 6, 4, 2, 3, 5, 9, 7 }; for (int i = 0; i < 8; i++) { sum += Integer.parseInt(number.substring(i, i + 1)) * mult[i]; } int rest = (sum % 11); int digit; if (rest == 0) { digit = 5; } else if (rest == 1) { digit = 0; } else { digit = 11 - rest; } if (Integer.parseInt(number.substring(8, 9)) == digit) { result = true; } } } return result; }  static boolean isValidId(String id); static Tracking search(String id); static Tracking search(String trackId, Integer start, Integer end, String clientId);  }