@Test public void makePredicateCheckCount() throws Exception { List<QueryPart> query = new ArrayList<>(); query.add(new QueryPart("Vorname", "*Sheldon")); query.add(new QueryPart("Vorname", "Sheldon*")); query.add(new QueryPart("Vorname", "*Sheldon*")); query.add(new QueryPart("Vorname", "*Sheldon**")); query.add(new QueryPart("Vorname", "**Sheldon*")); query.add(new QueryPart("Vorname", "**Sheldon**")); Predicate<Dataset> pred = DatasetPredicate.makePredicate(query); Map<String, String> testMap = new HashMap<>(); testMap.put("Vorname", "Sheldon"); Map<String, String> testMap1 = new HashMap<>(); testMap1.put("Vorname", "Sheldon*"); List<Dataset> datasetList = new ArrayList<>(); Dataset ds = new SimpleDataset("Test", testMap); Dataset ds1 = new SimpleDataset("Test", testMap1); datasetList.add(ds); datasetList.add(ds1); int count = 0; for (Dataset dataset : datasetList) { boolean result = pred.test(dataset); if (result) count++; } assertEquals(1, count, "Given datasets have a wrong match count with given QueryParts:"); }
public static Predicate<Dataset> makePredicate(List<QueryPart> query) { return query.stream().map(part -> { @SuppressWarnings("squid:S1488") Predicate<Dataset> pred = (Dataset ds) -> { try { return Pattern.matches(part.getSearchString().replaceAll("\\*", ""), ds.get(part.getColumnName())); } catch (ColumnNotFoundException ex) { return false; } }; return pred; }).reduce(matchAll, Predicate::and); }
DatasetPredicate { public static Predicate<Dataset> makePredicate(List<QueryPart> query) { return query.stream().map(part -> { @SuppressWarnings("squid:S1488") Predicate<Dataset> pred = (Dataset ds) -> { try { return Pattern.matches(part.getSearchString().replaceAll("\\*", ""), ds.get(part.getColumnName())); } catch (ColumnNotFoundException ex) { return false; } }; return pred; }).reduce(matchAll, Predicate::and); } }
DatasetPredicate { public static Predicate<Dataset> makePredicate(List<QueryPart> query) { return query.stream().map(part -> { @SuppressWarnings("squid:S1488") Predicate<Dataset> pred = (Dataset ds) -> { try { return Pattern.matches(part.getSearchString().replaceAll("\\*", ""), ds.get(part.getColumnName())); } catch (ColumnNotFoundException ex) { return false; } }; return pred; }).reduce(matchAll, Predicate::and); } private  DatasetPredicate(); }
DatasetPredicate { public static Predicate<Dataset> makePredicate(List<QueryPart> query) { return query.stream().map(part -> { @SuppressWarnings("squid:S1488") Predicate<Dataset> pred = (Dataset ds) -> { try { return Pattern.matches(part.getSearchString().replaceAll("\\*", ""), ds.get(part.getColumnName())); } catch (ColumnNotFoundException ex) { return false; } }; return pred; }).reduce(matchAll, Predicate::and); } private  DatasetPredicate(); static Predicate<Dataset> makePredicate(List<QueryPart> query); }
DatasetPredicate { public static Predicate<Dataset> makePredicate(List<QueryPart> query) { return query.stream().map(part -> { @SuppressWarnings("squid:S1488") Predicate<Dataset> pred = (Dataset ds) -> { try { return Pattern.matches(part.getSearchString().replaceAll("\\*", ""), ds.get(part.getColumnName())); } catch (ColumnNotFoundException ex) { return false; } }; return pred; }).reduce(matchAll, Predicate::and); } private  DatasetPredicate(); static Predicate<Dataset> makePredicate(List<QueryPart> query); static final Predicate<Dataset> matchAll; }