@Test public void testValidateDistrictKey() { String[] validKeys = new String[]{"2015ne", "2016in", "2014mar"}; String[] invliadKeys = new String[]{"f", "meowne"}; for (String key : validKeys) { assertTrue(DistrictHelper.validateDistrictKey(key)); } for (String key : invliadKeys) { assertFalse(DistrictHelper.validateDistrictKey(key)); } }
public static boolean validateDistrictKey(String key) { if (key == null || key.isEmpty()) return false; return key.matches("^[1-9]\\d{3}[a-z,0-9]+$"); }
DistrictHelper { public static boolean validateDistrictKey(String key) { if (key == null || key.isEmpty()) return false; return key.matches("^[1-9]\\d{3}[a-z,0-9]+$"); } }
DistrictHelper { public static boolean validateDistrictKey(String key) { if (key == null || key.isEmpty()) return false; return key.matches("^[1-9]\\d{3}[a-z,0-9]+$"); } private  DistrictHelper(); }
DistrictHelper { public static boolean validateDistrictKey(String key) { if (key == null || key.isEmpty()) return false; return key.matches("^[1-9]\\d{3}[a-z,0-9]+$"); } private  DistrictHelper(); static boolean validateDistrictKey(String key); static int extractYearFromKey(String key); static String extractAbbrevFromKey(String key); static String generateKey(String districtAbbrev, int year); }
DistrictHelper { public static boolean validateDistrictKey(String key) { if (key == null || key.isEmpty()) return false; return key.matches("^[1-9]\\d{3}[a-z,0-9]+$"); } private  DistrictHelper(); static boolean validateDistrictKey(String key); static int extractYearFromKey(String key); static String extractAbbrevFromKey(String key); static String generateKey(String districtAbbrev, int year);  }