DAPDownloader { static int[] getOrigin(String variableName, String constraintExpression, int dimensionCount) { int[] origin = new int[dimensionCount]; Arrays.fill(origin, 0); if (StringUtils.isNullOrEmpty(constraintExpression)) { return origin; } final String[] variableConstraints = constraintExpression.split(","); for (String variableConstraint : variableConstraints) { if (variableConstraint.contains(variableName)) { if (!variableConstraint.contains("[")) { return origin; } variableConstraint = variableConstraint.replace("]", ""); String[] rangeConstraints = variableConstraint.split("\\["); if (rangeConstraints.length - 1 > dimensionCount) { throw new IllegalArgumentException( MessageFormat.format("Illegal expression: ''{0}'' for variable ''{1}''.", constraintExpression, variableName)); } for (int i = 1; i < rangeConstraints.length; i++) { String rangeConstraint = rangeConstraints[i]; String[] rangeComponents = rangeConstraint.split(":"); origin[i - 1] = Integer.parseInt(rangeComponents[0]); } } } return origin; } DAPDownloader(Map<String, Boolean> dapUris, List<String> fileURIs, DownloadContext downloadContext,
                         DownloadProgressBarPM pm); void saveProducts(File targetDir);  }
@Test public void testGetOrigin() throws Exception { int[] origin = DAPDownloader.getOrigin("sst", "sst[0:1:10][0:1:10],wind[0:1:10][0:1:10]", 3); assertArrayEquals(new int[]{0, 0, 0}, origin); origin = DAPDownloader.getOrigin("wind", "sst[0:1:10][0:1:10],wind[0:1:10][0:1:10]", 2); assertArrayEquals(new int[]{0, 0}, origin); origin = DAPDownloader.getOrigin("sst", "sst[5:1:10][10:1:10],wind[1:1:10][0:1:10]", 3); assertArrayEquals(new int[]{5, 10, 0}, origin); origin = DAPDownloader.getOrigin("sst", "", 3); assertArrayEquals(new int[]{0, 0, 0}, origin); }