org.constretto.model.CPrimitive Maven / Gradle / Ivy
package org.constretto.model;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Kaare Nilsen
*/
public class CPrimitive extends CValue {
private final Pattern variablePattern = Pattern.compile("#\\{(.*?)}");
private String value;
public CPrimitive(String value) {
this.value = value;
}
public String value() {
return value;
}
@Override
public Set referencedKeys() {
Set referencedKeys = new HashSet();
Matcher matcher = variablePattern.matcher(value);
while (matcher.find()) {
String group = matcher.group(1);
referencedKeys.add(group);
}
return referencedKeys;
}
@Override
public void replace(String key, String resolvedValue) {
value = value.replaceAll("#\\{" + key + "\\}", resolvedValue);
}
@Override
public String toString() {
return value;
}
}