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

org.n3r.eql.config.EqlPropertiesConfig Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
package org.n3r.eql.config;

import lombok.val;
import org.n3r.eql.util.P;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class EqlPropertiesConfig implements EqlConfig {
    private final Properties properties;

    public EqlPropertiesConfig(String properties) {
        this(P.toProperties(properties));
    }

    public EqlPropertiesConfig(File file) {
        this(P.toProperties(file));
    }

    public EqlPropertiesConfig(InputStream is) {
        this(P.toProperties(is));
    }

    public EqlPropertiesConfig(Properties properties) {
        this.properties = checkNotEmptyProperties(properties);
    }

    private Properties checkNotEmptyProperties(Properties properties) {
        if (properties == null || properties.isEmpty())
            throw new IllegalArgumentException("eql properties is null or empty");

        return properties;
    }

    @Override
    public String getStr(String key) {
        return properties.getProperty(key);
    }

    @Override
    public Map params() {
        val map = new HashMap(properties.size());
        for (final String name : properties.stringPropertyNames())
            map.put(name, properties.getProperty(name));
        return map;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        val that = (EqlPropertiesConfig) o;

        return properties.equals(that.properties);
    }

    @Override
    public int hashCode() {
        return properties.hashCode();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy