DatasetNameFilter implements FilterComponent { @Override public boolean accept(OpendapLeaf leaf) { String text = expressionTextField.getText(); if (StringUtils.isNullOrEmpty(text)) { return true; } text = text.replace("*", ".*").toLowerCase(); Pattern pattern = Pattern.compile(text); final Matcher matcher = pattern.matcher(leaf.getName().toLowerCase()); return matcher.matches(); } DatasetNameFilter(JCheckBox filterCheckBox); @Override JComponent getUI(); @Override boolean accept(OpendapLeaf leaf); @Override void addFilterChangeListener(FilterChangeListener listener);  }
@Test public void testAccept() throws Exception { DatasetNameFilter datasetNameFilter = new DatasetNameFilter(new JCheckBox()); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafName", new InvDataset(null, "") { }))); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafName", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("x"); assertFalse(datasetNameFilter.accept(new OpendapLeaf("leafName", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("leafName"); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafName", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("*afNa*"); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafName", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("*afNa+"); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafNaaaa", new InvDataset(null, "") { }))); assertFalse(datasetNameFilter.accept(new OpendapLeaf("leafN", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("*afNa?"); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafN", new InvDataset(null, "") { }))); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafNa", new InvDataset(null, "") { }))); assertFalse(datasetNameFilter.accept(new OpendapLeaf("leafNam", new InvDataset(null, "") { }))); datasetNameFilter.expressionTextField.setText("*afna*"); assertTrue(datasetNameFilter.accept(new OpendapLeaf("leafNam", new InvDataset(null, "") { }))); }