Example usage for org.apache.commons.configuration Configuration containsKey

List of usage examples for org.apache.commons.configuration Configuration containsKey

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration containsKey.

Prototype

boolean containsKey(String key);

Source Link

Document

Check if the configuration contains the specified key.

Usage

From source file:com.linkedin.pinot.routing.builder.LargeClusterRoutingTableBuilder.java

@Override
public void init(Configuration configuration) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("offlineTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("offlineTargetServerCountPerQuery");
        try {//from   w  ww. j  av a  2 s .  co m
            TARGET_SERVER_COUNT_PER_QUERY = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using offline target server count of {}", TARGET_SERVER_COUNT_PER_QUERY);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the offline target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, TARGET_SERVER_COUNT_PER_QUERY, e);
        }
    } else {
        LOGGER.info("Using default value for offline target server count of {}", TARGET_SERVER_COUNT_PER_QUERY);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.mga.AbstractMGAAlgorithm.java

/**
 * Configures the algorithm.//from w w w.j  ava2s  . c o  m
 */
@Override
public void configure(Configuration conf) {
    try {
        super.configure(conf);

        if (conf.containsKey("Elitism")) {
            this.setElitism(conf.getInt("Elitism"));
        } else {
            this.setElitism(1);
            (new ConfWarning("AbstractMGAAlgorithm.Elitism", 1)).warn();
        }

        if (conf.containsKey("NominalConvergence.Class")) {
            this.setNominalConvergence(
                    (StopTest) Class.forName(conf.getString("NominalConvergence.Class")).newInstance());
        } else {
            (new ConfWarning("AbstractMGAAlgorithm.NominalConvergence", "MicroGenerationsConvergence")).warn();
            this.setNominalConvergence(new MicroGenerationsConvergence(3));
        }

        this.getNominalConvergence().configure(conf.subset("NominalConvergence"));
    } catch (Exception ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }
}

From source file:com.linkedin.pinot.broker.routing.builder.LargeClusterRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("offlineTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("offlineTargetServerCountPerQuery");
        try {/*from ww  w. j a v  a 2s .  co  m*/
            _targetNumServersPerQuery = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using offline target server count of {}", _targetNumServersPerQuery);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the offline target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, _targetNumServersPerQuery, e);
        }
    } else {
        LOGGER.info("Using default value for offline target server count of {}", _targetNumServersPerQuery);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.mga.MMGAAlgorithm.java

/**
 * Configures the algorithm./*from  w  w  w  . j  a v  a  2 s  . c  o m*/
 */
@Override
public void configure(Configuration conf) {
    try {
        super.configure(conf);

        if (conf.containsKey("ParetoFrontReplaceOperator.Class")) {
            setParetoFrontReplaceOperator((ParetoFrontReplaceOperator) Class
                    .forName(conf.getString("ParetoFrontReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.ParetoFrontReplaceOperator", "ParetoFrontReplaceOperator")).warn();
            setParetoFrontReplaceOperator(new ParetoFrontReplaceOperator());
        }

        getParetoFrontReplaceOperator().configure(conf.subset("ParetoFrontReplaceOperator"));

        if (conf.containsKey("PopulationMemorySize")) {
            setPopulationMemorySize(conf.getInt("PopulationMemorySize"));
        } else {
            int memSize = getParetoFrontReplaceOperator().getMaximumParetoFrontSize() / 3;

            (new ConfWarning("MMGAAlgorithm.PopulationMemorySize", memSize)).warn();
            setPopulationMemorySize(memSize);
        }

        if (conf.containsKey("PopulationMemoryReplaceOperator.Class")) {
            setPopulationMemoryReplaceOperator((PopulationMemoryReplaceOperator) Class
                    .forName(conf.getString("PopulationMemoryReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.PopulationMemoryReplaceOperator",
                    "PopulationMemoryReplaceOperator")).warn();
            setPopulationMemoryReplaceOperator(new PopulationMemoryReplaceOperator());
        }

        getPopulationMemoryReplaceOperator().setPopMemSize(getPopulationMemorySize());
        getPopulationMemoryReplaceOperator().configure(conf.subset("PopulationMemoryReplaceOperator"));

    } catch (Exception ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.operator.replace.mmga.PopulationMemoryReplaceOperator.java

@Override
public void configure(Configuration conf) {
    /* Defaults */
    int hypDiv = 25;
    int repCycle = 4;
    double repPart = 0.666;

    if (conf.containsKey("HypercubeDivisions")) {
        hypDiv = conf.getInt("HypercubeDivisions");
    } else {//from ww w.j  a v a 2  s .  c  o m
        (new ConfWarning("PopulationMemoryReplaceOperator.Hypercube" + "Divisions", hypDiv)).warn();
    }

    if (conf.containsKey("ReplacementCycle")) {
        repCycle = conf.getInt("ReplacementCycle");
    } else {
        (new ConfWarning("PopulationMemoryReplaceOperator.Replacement" + "Cycle", repCycle)).warn();
    }

    if (conf.containsKey("ReplaceablePart")) {
        repPart = conf.getDouble("ReplaceablePart");
    } else {
        (new ConfWarning("PopulationMemoryReplaceOperator.Replaceable" + "Part", repPart)).warn();
    }

    setHypercubeDivisions(hypDiv);
    setReplacementCycle(repCycle);
    setReplaceablePartSize((int) ((double) popMemSize * repPart));
}

From source file:com.vvote.verifier.component.votePacking.VotePackingConfig.java

/**
 * Constructor for a VotePackingConfig object from a String
 * /* ww  w .java  2 s.  com*/
 * @param configLocation
 *            The filename or filepath of the config in string format
 * @throws ConfigException
 */
public VotePackingConfig(String configLocation) throws ConfigException {
    logger.debug("Reading in Vote Packing specific configuration data");

    if (configLocation == null) {
        logger.error("Cannot successfully create a VotePackingConfig");
        throw new ConfigException("Cannot successfully create a VotePackingConfig");
    }

    if (configLocation.length() == 0) {
        logger.error("Cannot successfully create a VotePackingConfig");
        throw new ConfigException("Cannot successfully create a VotePackingConfig");
    }

    try {
        Configuration config = new PropertiesConfiguration(configLocation);

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.CURVE)) {
            this.curve = config.getString(ConfigFileConstants.VotePackingConfig.CURVE);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the curve used");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the curve used");
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.PADDING_FILE)) {
            this.paddingFile = config.getString(ConfigFileConstants.VotePackingConfig.PADDING_FILE);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the padding file");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the padding file");
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH)) {
            this.laLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH);
        } else {
            this.laLineLength = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING)) {
            this.laPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING);
        } else {
            this.laPacking = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH)) {
            this.lcBTLLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH);
        } else {
            this.lcBTLLineLength = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING)) {
            this.lcBTLPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING);
        } else {
            this.lcBTLPacking = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES)) {
            this.candidateTablesFolder = config
                    .getString(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the candidates table");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the candidates table");
        }

        this.useDirect = new HashMap<RaceType, Boolean>();
        this.useDirect.put(RaceType.LA, false);
        this.useDirect.put(RaceType.LC_ATL, false);
        this.useDirect.put(RaceType.LC_BTL, false);

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.USE_DIRECT)) {
            String[] directlyUsed = config.getStringArray(ConfigFileConstants.VotePackingConfig.USE_DIRECT);

            for (String race : directlyUsed) {
                RaceType raceType = RaceType.fromString(race);

                if (raceType != null) {
                    this.useDirect.remove(raceType);
                    this.useDirect.put(raceType, true);
                } else {
                    logger.error(
                            "Cannot successfully create a VotePackingConfig - misformed use direct race type");
                    throw new ConfigException(
                            "Cannot successfully create a VotePackingConfig - misformed use direct race type");
                }
            }
        }

    } catch (ConfigurationException e) {
        logger.error("Cannot successfully create a VotePackingConfig", e);
        throw new ConfigException("Cannot successfully create a VotePackingConfig", e);
    }
}

From source file:com.linkedin.pinot.broker.routing.builder.KafkaLowLevelConsumerRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("realtimeTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("realtimeTargetServerCountPerQuery");
        try {/*from  w  w  w.  j a va2 s.com*/
            _targetNumServersPerQuery = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using realtime target server count of {}", _targetNumServersPerQuery);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the realtime target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, _targetNumServersPerQuery, e);
        }
    } else {
        LOGGER.info("Using default value for realtime target server count of {}", _targetNumServersPerQuery);
    }
}

From source file:com.linkedin.pinot.broker.routing.builder.DefaultOfflineRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    _largeClusterRoutingTableBuilder = new LargeClusterRoutingTableBuilder();
    _smallClusterRoutingTableBuilder = new BalancedRandomRoutingTableBuilder();
    if (configuration.containsKey("minServerCountForLargeCluster")) {
        final String minServerCountForLargeCluster = configuration.getString("minServerCountForLargeCluster");
        try {//from w  w  w  .  j a  v  a2  s  . c o m
            _minServerCountForLargeCluster = Integer.parseInt(minServerCountForLargeCluster);
            LOGGER.info("Using large cluster min server count of {}", _minServerCountForLargeCluster);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the large cluster min server count from configuration value {}, keeping default value {}",
                    minServerCountForLargeCluster, _minServerCountForLargeCluster, e);
        }
    } else {
        LOGGER.info("Using default value for large cluster min server count of {}",
                _minServerCountForLargeCluster);
    }

    if (configuration.containsKey("minReplicaCountForLargeCluster")) {
        final String minReplicaCountForLargeCluster = configuration.getString("minReplicaCountForLargeCluster");
        try {
            _minReplicaCountForLargeCluster = Integer.parseInt(minReplicaCountForLargeCluster);
            LOGGER.info("Using large cluster min replica count of {}", _minReplicaCountForLargeCluster);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the large cluster min replica count from configuration value {}, keeping default value {}",
                    minReplicaCountForLargeCluster, _minReplicaCountForLargeCluster, e);
        }
    } else {
        LOGGER.info("Using default value for large cluster min replica count of {}",
                _minReplicaCountForLargeCluster);
    }

    _largeClusterRoutingTableBuilder.init(configuration, tableConfig, propertyStore);
    _smallClusterRoutingTableBuilder.init(configuration, tableConfig, propertyStore);
}

From source file:com.cisco.oss.foundation.directory.config.ServiceDirectoryConfigTest.java

@Test
public void testGetProperty() {
    Configuration config = ServiceDirectory.getServiceDirectoryConfig();

    assertFalse(config.getBoolean("ddd"));
    assertTrue(config.getDouble("notexists", 89.1) == 89.1);
    try {//from  w  w  w . ja  va  2s .  c o  m
        config.getDouble("notexists");
    } catch (Exception e) {
        assertTrue(e instanceof NoSuchElementException);
    }

    assertFalse(config.containsKey("not_property"));
}

From source file:com.datastax.openflights.OpenflightsBulkLoaderVertexProgram.java

private BulkLoader createBulkLoader() {
    final BulkLoader loader;
    final Configuration config = configuration.subset(BULK_LOADER_VERTEX_PROGRAM_CFG_PREFIX);
    if (config.containsKey("class")) {
        final String className = config.getString("class");
        try {/*from w  w w .  j a va  2s  .c o m*/
            final Class<?> bulkLoaderClass = Class.forName(className);
            loader = (BulkLoader) bulkLoaderClass.getConstructor().newInstance();
        } catch (ClassNotFoundException e) {
            LOGGER.error("Unable to find custom bulk loader class: {}", className);
            throw new IllegalStateException(e);
        } catch (Exception e) {
            LOGGER.error("Unable to create an instance of the given bulk loader class: {}", className);
            throw new IllegalStateException(e);
        }
    } else {
        loader = new IncrementalBulkLoader();
    }
    loader.configure(configuration);
    return loader;
}