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

querqy.rewrite.commonrules.model.InstructionsProperties Maven / Gradle / Ivy

There is a newer version: 3.18.1
Show newest version
package querqy.rewrite.commonrules.model;

import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class InstructionsProperties {

    private final Map propertyMap;
    private final DocumentContext documentContext;

    public InstructionsProperties(final Map propertyMap, final Configuration jsonPathConfig) {
        this.propertyMap = propertyMap;
        documentContext = JsonPath.using(jsonPathConfig).parse(propertyMap);
    }

    public InstructionsProperties(final Map propertyMap) {
        this(propertyMap, Configuration.defaultConfiguration());
    }


    public Optional getProperty(final String name) {
        return Optional.ofNullable(propertyMap.get(name));
    }

    public boolean matches(final String jsonPath) {
        final List read = documentContext.read(jsonPath);
        return read.size() > 0;
    }
}