Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:OneParameterization.java

/**
 * Performs a single run of the specified algorithm using the parameters.
 * // w w w  . ja va  2s. c o m
 * @param algorithmName the algorithm name
 * @param properties the parameters stored in a properties object
 * @throws IOException if an I/O error occurred
 */
protected void process(String algorithmName, Properties properties) throws IOException {
    // instrument the problem to record timing information
    TimingProblem timingProblem = new TimingProblem(problem);

    Algorithm algorithm = AlgorithmFactory.getInstance().getAlgorithm(algorithmName, properties, timingProblem);

    // find the maximum NFE to run
    if (!properties.containsKey("maxEvaluations")) {
        throw new FrameworkException("maxEvaluations not defined");
    }

    int maxEvaluations = (int) Double.parseDouble(properties.getProperty("maxEvaluations"));

    // run the algorithm
    long startTime = System.nanoTime();
    while (!algorithm.isTerminated() && (algorithm.getNumberOfEvaluations() < maxEvaluations)) {
        algorithm.step();
    }
    long endTime = System.nanoTime();

    // extract the result and free any resources
    NondominatedPopulation result = algorithm.getResult();
    algorithm.terminate();

    // apply epsilon-dominance if required
    if (properties.containsKey("epsilon")) {
        TypedProperties typedProperties = new TypedProperties(properties);
        double[] epsilon = typedProperties.getDoubleArray("epsilon", null);

        result = EpsilonHelper.convert(result, epsilon);
    }

    // record instrumented data
    Properties timingData = new Properties();
    timingData.setProperty("EvaluationTime", Double.toString(timingProblem.getTime()));
    timingData.setProperty("TotalTime", Double.toString((endTime - startTime) / 1e9));

    // write result to output
    output.append(new ResultEntry(result, timingData));
}

From source file:org.javassonne.ui.controllers.GameController.java

/**
 * Called when an END_GAME notification is received. This notification used
 * to be called EXIT_GAME, but it is now possible to end a game without
 * quitting the app, so we've broken EXIT_GAME into END_GAME and QUIT. The
 * game controller should clean up any resources related to the game to make
 * sure they are destroyed.// w  ww .jav a  2s. c o m
 * 
 * @param n
 *            The notification object sent from the NotificationManager.
 */
public void endGame(Notification n) {
    // reset game-related state variables. The board controller and hud
    // controller also receive this notification, and they will remove their
    // views from the screen.
    boardController_ = null;
    hudController_ = null;

    Properties config = (Properties) n.argument();
    if (config == null || !config.containsKey("hideMainMenu"))
        // show the main menu again, but this time with gameInProgress =
        // false
        toggleMainMenu(null);
}

From source file:org.apache.synapse.transport.mail.MailTransportSender.java

/**
 * Initialize the Mail sender and be ready to send messages
 * @param cfgCtx the axis2 configuration context
 * @param transportOut the transport-out description
 * @throws org.apache.axis2.AxisFault on error
 *///from ww w.  j  a va  2  s .c o m
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    setTransportName(MailConstants.TRANSPORT_NAME);
    super.init(cfgCtx, transportOut);

    // initialize SMTP session
    Properties props = new Properties();
    List<Parameter> params = transportOut.getParameters();
    for (Parameter p : params) {
        props.put(p.getName(), p.getValue());
    }

    if (props.containsKey(MailConstants.MAIL_SMTP_FROM)) {
        try {
            smtpFromAddress = new InternetAddress((String) props.get(MailConstants.MAIL_SMTP_FROM));
        } catch (AddressException e) {
            handleException("Invalid default 'From' address : " + props.get(MailConstants.MAIL_SMTP_FROM), e);
        }
    }

    if (props.containsKey(MailConstants.MAIL_SMTP_BCC)) {
        try {
            smtpBccAddresses = InternetAddress.parse((String) props.get(MailConstants.MAIL_SMTP_BCC));
        } catch (AddressException e) {
            handleException("Invalid default 'Bcc' address : " + props.get(MailConstants.MAIL_SMTP_BCC), e);
        }
    }

    if (props.containsKey(MailConstants.TRANSPORT_MAIL_FORMAT)) {
        defaultMailFormat = (String) props.get(MailConstants.TRANSPORT_MAIL_FORMAT);
    }

    smtpUsername = (String) props.get(MailConstants.MAIL_SMTP_USERNAME);
    smtpPassword = (String) props.get(MailConstants.MAIL_SMTP_PASSWORD);

    if (smtpUsername != null && smtpPassword != null) {
        session = Session.getInstance(props, new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(smtpUsername, smtpPassword);
            }
        });
    } else {
        session = Session.getInstance(props, null);
    }

    // add handlers for main MIME types
    MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
    mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("application/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("application/soap+xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
    mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
    mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
    CommandMap.setDefaultCommandMap(mc);

    session.setDebug(log.isTraceEnabled());
}

From source file:gobblin.scheduler.JobScheduler.java

/**
 * Run a job.//from  w  w w. ja  v  a  2s  . c  om
 *
 * <p>
 *   This method runs the job immediately without going through the Quartz scheduler.
 *   This is particularly useful for testing.
 * </p>
 *
 * <p>
 *   This method does what {@link #runJob(Properties, JobListener)} does, and additionally it allows
 *   the caller to pass in a {@link JobLauncher} instance used to launch the job to run.
 * </p>
 *
 * @param jobProps Job configuration properties
 * @param jobListener {@link JobListener} used for callback, can be <em>null</em> if no callback is needed.
 * @param jobLauncher a {@link JobLauncher} object used to launch the job to run
 * @throws JobException when there is anything wrong with running the job
 */
public void runJob(Properties jobProps, JobListener jobListener, JobLauncher jobLauncher) throws JobException {
    Preconditions.checkArgument(jobProps.containsKey(ConfigurationKeys.JOB_NAME_KEY),
            "A job must have a job name specified by job.name");
    String jobName = jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY);

    // Check if the job has been disabled
    boolean disabled = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_DISABLED_KEY, "false"));
    if (disabled) {
        LOG.info("Skipping disabled job " + jobName);
        return;
    }

    // Launch the job
    try (Closer closer = Closer.create()) {
        closer.register(jobLauncher).launchJob(jobListener);
        boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
        if (runOnce && this.scheduledJobs.containsKey(jobName)) {
            this.scheduler.getScheduler().deleteJob(this.scheduledJobs.remove(jobName));
        }
    } catch (Throwable t) {
        throw new JobException("Failed to launch and run job " + jobName, t);
    }
}

From source file:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java

@Test
public void testCreateProperties() {
    Properties properties = CollectionUtils.createProperties(Collections.singletonMap("one", "two"));

    assertNotNull(properties);/*w  w  w . java 2s. c om*/
    assertFalse(properties.isEmpty());
    assertTrue(properties.containsKey("one"));
    assertEquals("two", properties.getProperty("one"));
}

From source file:com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration.java

void setBasicInformation(MidpointConfiguration masterConfig) throws TaskManagerConfigurationException {
    Configuration c = masterConfig.getConfiguration(TASK_MANAGER_CONFIG_SECTION);

    stopOnInitializationFailure = c.getBoolean(STOP_ON_INITIALIZATION_FAILURE_CONFIG_ENTRY,
            STOP_ON_INITIALIZATION_FAILURE_DEFAULT);

    threads = c.getInt(THREADS_CONFIG_ENTRY, THREADS_DEFAULT);
    clustered = c.getBoolean(CLUSTERED_CONFIG_ENTRY, CLUSTERED_DEFAULT);
    jdbcJobStore = c.getBoolean(JDBC_JOB_STORE_CONFIG_ENTRY, clustered);

    nodeId = System.getProperty(MIDPOINT_NODE_ID_PROPERTY);
    if (StringUtils.isEmpty(nodeId) && !clustered) {
        nodeId = NODE_ID_DEFAULT;/*www  .  ja  v a 2 s .com*/
    }

    jmxHostName = System.getProperty(MIDPOINT_JMX_HOST_NAME_PROPERTY);

    String portString = System.getProperty(JMX_PORT_PROPERTY);
    if (StringUtils.isEmpty(portString)) {
        jmxPort = JMX_PORT_DEFAULT;
    } else {
        try {
            jmxPort = Integer.parseInt(portString);
        } catch (NumberFormatException nfe) {
            throw new TaskManagerConfigurationException(
                    "Cannot get JMX management port - invalid integer value of " + portString, nfe);
        }
    }

    jmxConnectTimeout = c.getInt(JMX_CONNECT_TIMEOUT_CONFIG_ENTRY, JMX_CONNECT_TIMEOUT_DEFAULT);

    if (c.containsKey(TEST_MODE_CONFIG_ENTRY)) {
        midPointTestMode = c.getBoolean(TEST_MODE_CONFIG_ENTRY);
        LOGGER.trace(TEST_MODE_CONFIG_ENTRY + " present, its value = " + midPointTestMode);
    } else {
        LOGGER.trace(TEST_MODE_CONFIG_ENTRY + " NOT present");
        Properties sp = System.getProperties();
        if (sp.containsKey(SUREFIRE_PRESENCE_PROPERTY)) {
            LOGGER.info("Determined to run in a test environment, setting midPointTestMode to 'true'.");
            midPointTestMode = true;
        } else {
            midPointTestMode = false;
        }
    }
    LOGGER.trace("midPointTestMode = " + midPointTestMode);

    String useTI = c.getString(USE_THREAD_INTERRUPT_CONFIG_ENTRY, USE_THREAD_INTERRUPT_DEFAULT);
    try {
        useThreadInterrupt = UseThreadInterrupt.fromValue(useTI);
    } catch (IllegalArgumentException e) {
        throw new TaskManagerConfigurationException(
                "Illegal value for " + USE_THREAD_INTERRUPT_CONFIG_ENTRY + ": " + useTI, e);
    }

    quartzNodeRegistrationCycleTime = c.getInt(QUARTZ_NODE_REGISTRATION_INTERVAL_CONFIG_ENTRY,
            QUARTZ_NODE_REGISTRATION_CYCLE_TIME_DEFAULT);
    nodeRegistrationCycleTime = c.getInt(NODE_REGISTRATION_INTERVAL_CONFIG_ENTRY,
            NODE_REGISTRATION_CYCLE_TIME_DEFAULT);
    nodeTimeout = c.getInt(NODE_TIMEOUT_CONFIG_ENTRY, NODE_TIMEOUT_DEFAULT);

    jmxUsername = c.getString(JMX_USERNAME_CONFIG_ENTRY, JMX_USERNAME_DEFAULT);
    jmxPassword = c.getString(JMX_PASSWORD_CONFIG_ENTRY, JMX_PASSWORD_DEFAULT);

    waitingTasksCheckInterval = c.getInt(WAITING_TASKS_CHECK_INTERVAL_CONFIG_ENTRY,
            WAITING_TASKS_CHECK_INTERVAL_DEFAULT);
    stalledTasksCheckInterval = c.getInt(STALLED_TASKS_CHECK_INTERVAL_CONFIG_ENTRY,
            STALLED_TASKS_CHECK_INTERVAL_DEFAULT);
    stalledTasksThreshold = c.getInt(STALLED_TASKS_THRESHOLD_CONFIG_ENTRY, STALLED_TASKS_THRESHOLD_DEFAULT);
    stalledTasksRepeatedNotificationInterval = c.getInt(
            STALLED_TASKS_REPEATED_NOTIFICATION_INTERVAL_CONFIG_ENTRY,
            STALLED_TASKS_REPEATED_NOTIFICATION_INTERVAL_DEFAULT);
    runNowKeepsOriginalSchedule = c.getBoolean(RUN_NOW_KEEPS_ORIGINAL_SCHEDULE_CONFIG_ENTRY,
            RUN_NOW_KEEPS_ORIGINAL_SCHEDULE_DEFAULT);
}

From source file:io.warp10.standalone.StandaloneDeleteHandler.java

public StandaloneDeleteHandler(KeyStore keystore, StandaloneDirectoryClient directoryClient,
        StoreClient storeClient) {//from   www . java  2  s  .c  o m
    this.keyStore = keystore;
    this.storeClient = storeClient;
    this.directoryClient = directoryClient;

    this.classKey = this.keyStore.getKey(KeyStore.SIPHASH_CLASS);
    this.classKeyLongs = SipHashInline.getKey(this.classKey);

    this.labelsKey = this.keyStore.getKey(KeyStore.SIPHASH_LABELS);
    this.labelsKeyLongs = SipHashInline.getKey(this.labelsKey);

    Properties props = WarpConfig.getProperties();

    if (props.containsKey(Configuration.DATALOG_DIR)) {
        File dir = new File(props.getProperty(Configuration.DATALOG_DIR));

        if (!dir.exists()) {
            throw new RuntimeException("Data logging target '" + dir + "' does not exist.");
        } else if (!dir.isDirectory()) {
            throw new RuntimeException("Data logging target '" + dir + "' is not a directory.");
        } else {
            loggingDir = dir;
        }

        String id = props.getProperty(Configuration.DATALOG_ID);

        if (null == id) {
            throw new RuntimeException("Property '" + Configuration.DATALOG_ID
                    + "' MUST be set to a unique value for this instance.");
        } else {
            datalogId = new String(OrderPreservingBase64.encode(id.getBytes(Charsets.UTF_8)),
                    Charsets.US_ASCII);
        }
    } else {
        loggingDir = null;
        datalogId = null;
    }

    if (props.containsKey(Configuration.DATALOG_PSK)) {
        this.datalogPSK = this.keyStore.decodeKey(props.getProperty(Configuration.DATALOG_PSK));
    } else {
        this.datalogPSK = null;
    }

    this.logforwarded = "true".equals(props.getProperty(Configuration.DATALOG_LOGFORWARDED));
}

From source file:org.apache.ctakes.ytex.kernel.KernelUtilImpl.java

@Override
public void generateFolds(InstanceData instanceLabel, Properties props) {
    int folds = Integer.parseInt(props.getProperty("folds"));
    int runs = Integer.parseInt(props.getProperty("runs", "1"));
    int minPerClass = Integer.parseInt(props.getProperty("minPerClass", "0"));
    Integer randomNumberSeed = props.containsKey("rand") ? Integer.parseInt(props.getProperty("rand")) : null;
    instanceLabel.setLabelToInstanceMap(foldGenerator.generateRuns(instanceLabel.getLabelToInstanceMap(), folds,
            minPerClass, randomNumberSeed, runs));
}

From source file:hudson.org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask.java

/**
 * replace all known author's id's with their maven specified names
 *//*from   w w w  .  j ava  2s.  c  om*/
private void replaceAuthorIdWithName(final Properties userList, final CVSEntry[] entrySet) {
    for (int i = 0; i < entrySet.length; i++) {

        final CVSEntry entry = entrySet[i];
        if (userList.containsKey(entry.getAuthor())) {
            entry.setAuthor(userList.getProperty(entry.getAuthor()));
        }
    }
}

From source file:com.evolveum.polygon.connector.drupal.TestClient.java

@BeforeClass
public static void setUp() throws Exception {
    String fileName = "test.properties";

    final Properties properties = new Properties();
    InputStream inputStream = TestClient.class.getClassLoader().getResourceAsStream(fileName);
    if (inputStream == null) {
        throw new IOException("Sorry, unable to find " + fileName);
    }/*from   ww  w  . ja v  a 2 s  .  c  om*/
    properties.load(inputStream);

    conf = new DrupalConfiguration();
    conf.setUsername(properties.getProperty("username"));
    conf.setPassword(new GuardedString(properties.getProperty("password").toCharArray()));
    conf.setServiceAddress(properties.getProperty("serviceAddress"));
    conf.setAuthMethod(properties.getProperty("authMethod"));
    conf.setTrustAllCertificates(Boolean.parseBoolean(properties.getProperty("trustAllCertificates")));

    conf.setUserDeleteDisabled(Boolean.parseBoolean(properties.getProperty("userDeleteDisabled")));

    conf.setPageSize(Integer.parseInt(properties.getProperty("pageSize")));

    if (properties.containsKey("userFields")) {
        String[] userFields = properties.getProperty("userFields").split(";");
        conf.setUserFields(userFields);
    }

    if (properties.containsKey("taxonomies")) {
        String[] taxonomies = properties.getProperty("taxonomies").split(";");
        conf.setTaxonomies(taxonomies);
    }

    if (properties.containsKey("createTaxonomyWhenNameNotExists")) {
        String[] createTaxonomyWhenNameNotExists = properties.getProperty("createTaxonomyWhenNameNotExists")
                .split(";");
        conf.setCreateTaxonomyWhenNameNotExists(createTaxonomyWhenNameNotExists);
    }

    if (properties.containsKey("createNodeWhenTitleNotExists")) {
        String[] createNodeWhenTitleNotExists = properties.getProperty("createNodeWhenTitleNotExists")
                .split(";");
        conf.setCreateNodeWhenTitleNotExists(createNodeWhenTitleNotExists);
    }

    if (properties.containsKey("userFields")) {
        String[] userFields = properties.getProperty("userFields").split(";");
        conf.setUserFields(userFields);
    }

    if (properties.containsKey("requiredFields")) {
        String[] requiredFields = properties.getProperty("requiredFields").split(";");
        conf.setRequiredFields(requiredFields);
    }

    if (properties.containsKey("dontReadUserDetailsWhenFindAllUsers")) {
        conf.setDontReadUserDetailsWhenFindAllUsers(
                Boolean.parseBoolean(properties.getProperty("dontReadUserDetailsWhenFindAllUsers")));
    }

    conn = new DrupalConnector();
    conn.init(conf);
}