@Test public void testInterpolateParameters() { String testValue = "path=/${PATH1}/${PATH2}/${}"; ParamHandler paramHandler = new ParamHandler(); assertEquals(testValue, GenericExternalProcess.interpolateParameters(testValue, paramHandler.getMap())); paramHandler.add("PATH1", "path1"); paramHandler.add("PATH2", "$2"); assertEquals("path=/path1/$2/${}", GenericExternalProcess.interpolateParameters(testValue, paramHandler.getMap())); }
static String interpolateParameters(String s, Map<String, String> parameters) { if (s == null || s.length() < 4 || parameters.isEmpty()) { return s; } Matcher m = REPLACE_PARAM_PATTERN.matcher(s); StringBuffer sb = null; while(m.find()) { if (m.groupCount() == 1) { String param = m.group(1); String replacement = parameters.get(param); if (replacement != null) { sb = sb != null ? sb : new StringBuffer(); m.appendReplacement(sb, Matcher.quoteReplacement(replacement)); } } } if (sb == null) { return s; } m.appendTail(sb); return sb.toString(); }
GenericExternalProcess extends ExternalProcess { static String interpolateParameters(String s, Map<String, String> parameters) { if (s == null || s.length() < 4 || parameters.isEmpty()) { return s; } Matcher m = REPLACE_PARAM_PATTERN.matcher(s); StringBuffer sb = null; while(m.find()) { if (m.groupCount() == 1) { String param = m.group(1); String replacement = parameters.get(param); if (replacement != null) { sb = sb != null ? sb : new StringBuffer(); m.appendReplacement(sb, Matcher.quoteReplacement(replacement)); } } } if (sb == null) { return s; } m.appendTail(sb); return sb.toString(); } }
GenericExternalProcess extends ExternalProcess { static String interpolateParameters(String s, Map<String, String> parameters) { if (s == null || s.length() < 4 || parameters.isEmpty()) { return s; } Matcher m = REPLACE_PARAM_PATTERN.matcher(s); StringBuffer sb = null; while(m.find()) { if (m.groupCount() == 1) { String param = m.group(1); String replacement = parameters.get(param); if (replacement != null) { sb = sb != null ? sb : new StringBuffer(); m.appendReplacement(sb, Matcher.quoteReplacement(replacement)); } } } if (sb == null) { return s; } m.appendTail(sb); return sb.toString(); } GenericExternalProcess(Configuration conf); }
GenericExternalProcess extends ExternalProcess { static String interpolateParameters(String s, Map<String, String> parameters) { if (s == null || s.length() < 4 || parameters.isEmpty()) { return s; } Matcher m = REPLACE_PARAM_PATTERN.matcher(s); StringBuffer sb = null; while(m.find()) { if (m.groupCount() == 1) { String param = m.group(1); String replacement = parameters.get(param); if (replacement != null) { sb = sb != null ? sb : new StringBuffer(); m.appendReplacement(sb, Matcher.quoteReplacement(replacement)); } } } if (sb == null) { return s; } m.appendTail(sb); return sb.toString(); } GenericExternalProcess(Configuration conf); GenericExternalProcess addInputFile(File file); File getInputFile(); GenericExternalProcess addOutputFile(File file); File getOutputFile(); ParamHandler getParameters(); Map<String, String> getResultParameters(); ProcessResult getResult(); @Override void run(); boolean isSkippedProcess(); }
GenericExternalProcess extends ExternalProcess { static String interpolateParameters(String s, Map<String, String> parameters) { if (s == null || s.length() < 4 || parameters.isEmpty()) { return s; } Matcher m = REPLACE_PARAM_PATTERN.matcher(s); StringBuffer sb = null; while(m.find()) { if (m.groupCount() == 1) { String param = m.group(1); String replacement = parameters.get(param); if (replacement != null) { sb = sb != null ? sb : new StringBuffer(); m.appendReplacement(sb, Matcher.quoteReplacement(replacement)); } } } if (sb == null) { return s; } m.appendTail(sb); return sb.toString(); } GenericExternalProcess(Configuration conf); GenericExternalProcess addInputFile(File file); File getInputFile(); GenericExternalProcess addOutputFile(File file); File getOutputFile(); ParamHandler getParameters(); Map<String, String> getResultParameters(); ProcessResult getResult(); @Override void run(); boolean isSkippedProcess(); static final String DST_PARENT; static final String DST_PATH; static final String SRC_EXT; static final String SRC_NAME; static final String SRC_NAME_EXT; static final String SRC_PATH; static final String SRC_PARENT; }