Example usage for org.apache.commons.configuration2 PropertiesConfiguration containsKey

List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration containsKey

Introduction

In this page you can find the example usage for org.apache.commons.configuration2 PropertiesConfiguration containsKey.

Prototype

@Override
public final boolean containsKey(final String key) 

Source Link

Document

This implementation handles synchronization and delegates to containsKeyInternal() .

Usage

From source file:com.smartmarmot.dbforbix.config.Config.java

/**
 * Reads the configuration from a properties file
 * /*from  ww  w.  ja va2 s. co m*/
 * @throws IOException
 */
public void readFileConfig() throws IOException, NullPointerException {
    LOG.debug("Parsing config file: " + configFile);
    calculateFileConfigHash();
    try (FileReader reader = new FileReader(configFile)) {
        PropertiesConfiguration pcfg = new PropertiesConfiguration();
        pcfg.read(reader);
        if (pcfg.containsKey(SET_PERSISTENCETYPE))
            persistenceType = pcfg.getString(SET_PERSISTENCETYPE);
        if (pcfg.containsKey(SET_PERSISTENCEDIR))
            persistenceDir = pcfg.getString(SET_PERSISTENCEDIR);
        if (pcfg.containsKey(SET_UPDATECONFIG))
            setUpdateConfigTimeout(pcfg.getInt(SET_UPDATECONFIG));
        if (pcfg.containsKey(SET_POOL_MAXACTIVE))
            maxActive = pcfg.getInt(SET_POOL_MAXACTIVE);
        if (pcfg.containsKey(SET_POOL_MAXIDLE))
            maxIdle = pcfg.getInt(SET_POOL_MAXIDLE);
        if (pcfg.containsKey(SET_LOGIN_TIMEOUT))
            loginTimeout = Integer.parseInt(pcfg.getString(SET_LOGIN_TIMEOUT));
        Iterator<?> it;
        it = pcfg.getKeys(GLOBAL_ZBXSRV);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigZSRV(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }
        it = pcfg.getKeys(GLOBAL_DB);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigDB(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }

    } catch (ConfigurationException e) {
        throw new IOException("Error in configuration: " + e.getLocalizedMessage(), e);
    }
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static void addMissingProperties(PropertiesConfiguration reference, PropertiesConfiguration target) {
    Lists.newArrayList(reference.getKeys()).stream().filter(propertyKey -> !target.containsKey(propertyKey))
            .forEach(missingKey -> target.setProperty(missingKey, reference.getProperty(missingKey)));
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static void removeObsoleteProperties(PropertiesConfiguration reference,
        PropertiesConfiguration target) {
    Lists.newArrayList(target.getKeys()).stream().filter(propertyKey -> !reference.containsKey(propertyKey))
            .forEach(target::clearProperty);
}