@Test public void test03() { String regular = "pt=*"; List<String> matched = FilterUtil.filterByRegular(ALL_STRS, regular); System.out.println("matched:" + matched); List<String> expected = new ArrayList<String>(ALL_STRS); Assert.assertEquals(expected.size(), matched.size()); Collections.sort(expected); Collections.sort(matched); Assert.assertArrayEquals(expected.toArray(), matched.toArray()); }
public static List<String> filterByRegular(List<String> allStrs, String regular) { List<String> matchedValues = new ArrayList<String>(); String newReqular = regular.replace(".*", "*").replace("*", ".*"); Pattern p = Pattern.compile(newReqular); for (String partition : allStrs) { if (p.matcher(partition).matches()) { if (!matchedValues.contains(partition)) { matchedValues.add(partition); } } } return matchedValues; }
FilterUtil { public static List<String> filterByRegular(List<String> allStrs, String regular) { List<String> matchedValues = new ArrayList<String>(); String newReqular = regular.replace(".*", "*").replace("*", ".*"); Pattern p = Pattern.compile(newReqular); for (String partition : allStrs) { if (p.matcher(partition).matches()) { if (!matchedValues.contains(partition)) { matchedValues.add(partition); } } } return matchedValues; } }
FilterUtil { public static List<String> filterByRegular(List<String> allStrs, String regular) { List<String> matchedValues = new ArrayList<String>(); String newReqular = regular.replace(".*", "*").replace("*", ".*"); Pattern p = Pattern.compile(newReqular); for (String partition : allStrs) { if (p.matcher(partition).matches()) { if (!matchedValues.contains(partition)) { matchedValues.add(partition); } } } return matchedValues; }  }
FilterUtil { public static List<String> filterByRegular(List<String> allStrs, String regular) { List<String> matchedValues = new ArrayList<String>(); String newReqular = regular.replace(".*", "*").replace("*", ".*"); Pattern p = Pattern.compile(newReqular); for (String partition : allStrs) { if (p.matcher(partition).matches()) { if (!matchedValues.contains(partition)) { matchedValues.add(partition); } } } return matchedValues; }  static List<String> filterByRegular(List<String> allStrs,
                                               String regular); static List<String> filterByRegulars(List<String> allStrs,
                                                List<String> regulars); }
FilterUtil { public static List<String> filterByRegular(List<String> allStrs, String regular) { List<String> matchedValues = new ArrayList<String>(); String newReqular = regular.replace(".*", "*").replace("*", ".*"); Pattern p = Pattern.compile(newReqular); for (String partition : allStrs) { if (p.matcher(partition).matches()) { if (!matchedValues.contains(partition)) { matchedValues.add(partition); } } } return matchedValues; }  static List<String> filterByRegular(List<String> allStrs,
                                               String regular); static List<String> filterByRegulars(List<String> allStrs,
                                                List<String> regulars);  }