All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.constretto.model.CPrimitive Maven / Gradle / Ivy

There is a newer version: 3.0.0-BETA4
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy