DAPDownloader { static List<String> filterVariables(List<String> variableNames, String constraintExpression) { final List<String> filteredVariables = new ArrayList<String>(); final List<String> constrainedVariableNames = getVariableNames(constraintExpression); if (constrainedVariableNames == null || constrainedVariableNames.isEmpty()) { return variableNames; } for (String variableName : variableNames) { if (constrainedVariableNames.contains(variableName)) { filteredVariables.add(variableName); } } if (filteredVariables.isEmpty()) { return variableNames; } return filteredVariables; } DAPDownloader(Map<String, Boolean> dapUris, List<String> fileURIs, DownloadContext downloadContext,
                         DownloadProgressBarPM pm); void saveProducts(File targetDir);  }
@Test public void testFilterVariables() throws Exception { final URL resource = getClass().getResource("test.nc"); final NetcdfFile netcdfFile = NetcdfFileOpener.open(resource.toString()); final List<Variable> variables = netcdfFile.getVariables(); final List<String> variableNames = new ArrayList<String>(); for (Variable variable : variables) { variableNames.add(variable.getFullName()); } String constraintExpression = null; List<String> filteredVariables = DAPDownloader.filterVariables(variableNames, constraintExpression); assertEquals(2, filteredVariables.size()); assertEquals("sst", filteredVariables.get(0)); assertEquals("wind", filteredVariables.get(1)); constraintExpression = "sst[0:1:10][0:1:10]"; filteredVariables = DAPDownloader.filterVariables(variableNames, constraintExpression); assertEquals(1, filteredVariables.size()); assertEquals("sst", filteredVariables.get(0)); constraintExpression = "bogusVariable[0:1:10][0:1:10]"; filteredVariables = DAPDownloader.filterVariables(variableNames, constraintExpression); assertEquals(2, filteredVariables.size()); assertEquals("sst", filteredVariables.get(0)); assertEquals("wind", filteredVariables.get(1)); constraintExpression = "sst[0:1:10][0:1:10],wind[0:1:10][0:1:10]"; filteredVariables = DAPDownloader.filterVariables(variableNames, constraintExpression); assertEquals(2, filteredVariables.size()); assertEquals("sst", filteredVariables.get(0)); assertEquals("wind", filteredVariables.get(1)); constraintExpression = "sst[0:1:10][0:1:10],wind[0:1:10][0:1:10],sst"; filteredVariables = DAPDownloader.filterVariables(variableNames, constraintExpression); assertEquals(2, filteredVariables.size()); assertEquals("sst", filteredVariables.get(0)); assertEquals("wind", filteredVariables.get(1)); }