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:com.nesscomputing.mojo.numbers.PropertyCache.java

@VisibleForTesting
ValueProvider findCurrentValue(final Properties props, final AbstractDefinition<?> definition) {
    final String propName = definition.getPropertyName();
    final boolean hasProperty = props.containsKey(propName);

    final boolean createProperty = IWFCEnum.checkState(definition.getOnMissingProperty(), hasProperty,
            propName);//from w ww . j  a  va 2  s .  co  m

    if (hasProperty) {
        return new ValueProvider.PropertyProvider(props, propName);
    } else if (createProperty) {
        props.setProperty(propName, definition.getInitialValue());
        return new ValueProvider.PropertyProvider(props, propName);
    } else {
        return ValueProvider.NULL_PROVIDER;
    }
}

From source file:com.predic8.membrane.balancer.client.LBNotificationClient.java

private String getArgument(CommandLine cl, int clArgPos, char option, String prop, String def, String errMsg)
        throws Exception {
    if (clArgPos != -1 && cl.getArgs().length > clArgPos) {
        return cl.getArgs()[clArgPos];
    }/*from w  w w. ja  va 2  s.  co m*/

    if (option != '-' && cl.hasOption(option)) {
        return cl.getOptionValue(option);
    }

    if (prop != null && new File(propertiesFile).exists()) {
        Properties props = new Properties();
        InputStream is = new FileInputStream(propertiesFile);
        try {
            props.load(is);
        } finally {
            is.close();
        }
        if (props.containsKey(prop)) {
            return props.getProperty(prop);
        }
    }

    if (def != null) {
        return def;
    }

    throw new MissingArgumentException(errMsg);
}

From source file:com.rtl.http.Upload.java

/**
 * ??//from  ww w.  ja  va2s.  co  m
 */
public void readInfo(String propFile) {
    Properties p = new Properties();
    try {
        InputStream in = new FileInputStream(propFile);
        p.load(in);
        in.close();
        if (p.containsKey("url")) {
            url = p.getProperty("url");
        }
        if (p.containsKey("licenseKey")) {
            licenseKey = p.getProperty("licenseKey");
        }
        if (p.containsKey("logDir")) {
            logDir = p.getProperty("logDir");
        }
        // if(p.containsKey("dataType")){
        // dataType = p.getProperty("dataType");
        // System.out.println("dataType="+dataType);
        // }
        // if(p.containsKey("dataVersion")){
        // dataVersion = p.getProperty("dataVersion");
        // System.out.println("dataVersion="+dataVersion);
        // }
        // if(p.containsKey("datafile")){
        // datafile = p.getProperty("datafile");
        // System.out.println("datafile="+datafile);
        // }
        // if(p.containsKey("filePath")){
        // filePath = p.getProperty("filePath");
        // System.out.println("filePath="+filePath);
        // }
    } catch (IOException ex) {
        // System.out.println(ex.getMessage());
        logger.error(ex.getMessage());
    }
}

From source file:org.sonar.plugins.web.markup.validation.RemoteValidationService.java

protected String getProperty(File file, String property) {
    File propertiesFile = new File(file.getPath() + ".txt");

    if (propertiesFile.exists()) {
        Properties properties = new Properties();

        InputStream in = null;//from  w ww.j a  v  a  2s  .  c o  m
        try {
            in = new FileInputStream(propertiesFile);
            properties.load(in);
            if (properties.containsKey(property)) {
                return properties.getProperty(property);
            }
        } catch (IOException e) {
            return null;
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return null;
}

From source file:com.netflix.lipstick.listeners.LipstickPPNL.java

/**
 * Initialize the clients from properties in the pig context.
 *///from  w ww . j  ava  2s  . c  om
protected void initClients() {
    // Make sure client list is empty before initializing.
    // For example, this prevents initailizing multiple times when
    // executing multiple runs in a grunt shell session.
    Properties props = ps.getPigContext().getProperties();
    if (clients.isEmpty() && props.containsKey(LIPSTICK_URL_PROP)) {
        // Initialize the client
        clients.add(new BasicP2LClient(props.getProperty(LIPSTICK_URL_PROP)));
    }
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.VehicleTrackingManagementServiceImpl.java

@PostConstruct
public void setup() {

    if (_configPath == null || !_configPath.exists())
        return;//from  ww  w.j  a va 2  s. c o m

    try {
        Properties p = new Properties();
        FileReader in = new FileReader(_configPath);
        p.load(in);
        in.close();

        if (p.containsKey("noProgressTimeout"))
            _vehicleStalledTimeThreshold = Integer.parseInt(p.getProperty("noProgressTimeout"));

        if (p.containsKey("offRouteDistance"))
            _vehicleOffRouteDistanceThreshold = Double.parseDouble("offRouteDistance");

    } catch (IOException ex) {
        _log.warn("error loading configuration properties from " + _configPath, ex);
    }
}

From source file:gobblin.azkaban.AzkabanJobLauncher.java

public AzkabanJobLauncher(String jobId, Properties props) throws Exception {
    super(jobId, LOG);

    Properties properties = new Properties();
    properties.putAll(props);/*ww w. ja  v a 2s  . c o  m*/
    Configuration conf = new Configuration();

    String fsUri = conf.get(HADOOP_FS_DEFAULT_NAME);
    if (!Strings.isNullOrEmpty(fsUri)) {
        if (!properties.containsKey(ConfigurationKeys.FS_URI_KEY)) {
            properties.setProperty(ConfigurationKeys.FS_URI_KEY, fsUri);
        }
        if (!properties.containsKey(ConfigurationKeys.STATE_STORE_FS_URI_KEY)) {
            properties.setProperty(ConfigurationKeys.STATE_STORE_FS_URI_KEY, fsUri);
        }
    }

    // Set the job tracking URL to point to the Azkaban job execution link URL
    properties.setProperty(ConfigurationKeys.JOB_TRACKING_URL_KEY,
            Strings.nullToEmpty(conf.get(AZKABAN_LINK_JOBEXEC_URL)));

    // Necessary for compatibility with Azkaban's hadoopJava job type
    // http://azkaban.github.io/azkaban/docs/2.5/#hadoopjava-type
    if (System.getenv(HADOOP_TOKEN_FILE_LOCATION) != null) {
        properties.setProperty(MAPREDUCE_JOB_CREDENTIALS_BINARY, System.getenv(HADOOP_TOKEN_FILE_LOCATION));
    }

    JobMetrics.addCustomTagsToProperties(properties, getAzkabanTags());

    // If the job launcher type is not specified in the job configuration,
    // override the default to use the MAPREDUCE launcher.
    if (!properties.containsKey(ConfigurationKeys.JOB_LAUNCHER_TYPE_KEY)) {
        properties.setProperty(ConfigurationKeys.JOB_LAUNCHER_TYPE_KEY,
                JobLauncherFactory.JobLauncherType.MAPREDUCE.toString());
    }

    // Create a JobLauncher instance depending on the configuration. The same properties object is
    // used for both system and job configuration properties because Azkaban puts configuration
    // properties in the .job file and in the .properties file into the same Properties object.
    this.jobLauncher = this.closer.register(JobLauncherFactory.newJobLauncher(properties, properties));
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.tools.AerovisConverter.java

/**
 * Converts and writes the contents of the result file to the Aerovis
 * format.//from  w  w  w  .  j a v  a2s  .  c  o m
 * 
 * @param problem the problem
 * @param reduced {@code true} if the decision variables are suppressed;
 *        {@code false} if they are written to the output file
 * @param reader the result file reader
 * @param writer the writer where the output is written
 */
private void convert(Problem problem, boolean reduced, ResultFileReader reader, PrintWriter writer) {
    int numberOfVariables = problem.getNumberOfVariables();
    int numberOfObjectives = problem.getNumberOfObjectives();

    if (reduced) {
        numberOfVariables = 0;
    }

    while (reader.hasNext()) {
        ResultEntry entry = reader.next();
        Population population = entry.getPopulation();
        Properties properties = entry.getProperties();

        if (population.isEmpty()) {
            continue;
        }

        if (properties.containsKey("NFE")) {
            writer.print(properties.getProperty("NFE"));
        } else {
            writer.print("0");
        }

        writer.print(" ");

        if (properties.containsKey("ElapsedTime")) {
            writer.println(properties.getProperty("ElapsedTime"));
        } else {
            writer.println("0");
        }

        writer.println("#");

        for (Solution solution : population) {
            for (int i = 0; i < numberOfVariables; i++) {
                if (i > 0) {
                    writer.print(" ");
                }

                writer.print(solution.getVariable(i));
            }

            for (int i = 0; i < numberOfObjectives; i++) {
                if ((i > 0) || (numberOfVariables > 0)) {
                    writer.print(" ");
                }

                writer.print(solution.getObjective(i));
            }

            writer.println();
        }
        writer.println("#");
    }
}

From source file:org.apache.gobblin.metrics.kafka.KafkaAvroSchemaRegistry.java

/**
 * @param properties properties should contain property "kafka.schema.registry.url", and optionally
 * "kafka.schema.registry.max.cache.size" (default = 1000) and
 * "kafka.schema.registry.cache.expire.after.write.min" (default = 10).
 */// ww  w .  ja v a  2 s  .co  m
public KafkaAvroSchemaRegistry(Properties props) {
    super(props);
    Preconditions.checkArgument(props.containsKey(KAFKA_SCHEMA_REGISTRY_URL),
            String.format("Property %s not provided.", KAFKA_SCHEMA_REGISTRY_URL));

    this.url = props.getProperty(KAFKA_SCHEMA_REGISTRY_URL);
    this.namespaceOverride = KafkaAvroReporterUtil.extractOverrideNamespace(props);

    int objPoolSize = Integer
            .parseInt(props.getProperty(ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_THREADS,
                    "" + ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_DEFAULT_THREAD_COUNT));
    LOG.info("Create HttpClient pool with size " + objPoolSize);

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(objPoolSize);
    config.setMaxIdle(objPoolSize);

    HttpClientFactory factory = new HttpClientFactory();

    if (this.props.containsKey(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_SO_TIMEOUT)) {
        String soTimeout = this.props
                .getProperty(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_SO_TIMEOUT);
        factory.setSoTimeout(Integer.parseInt(soTimeout));
    }

    if (this.props.containsKey(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_CONN_TIMEOUT)) {
        String connTimeout = this.props
                .getProperty(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_CONN_TIMEOUT);
        factory.setConnTimeout(Integer.parseInt(connTimeout));
    }

    this.httpClientPool = new GenericObjectPool<>(factory, config);
}

From source file:com.google.api.ads.dfp.lib.AuthToken.java

/**
 * Retrieves an authentication token using the user's credentials.
 *
 * @return a {@code String} authentication token.
 * @throws AuthTokenException if the status from the Client Login server is
 *     anything but {@code HttpStatus.SC_OK = 200}
 *//*from w  w  w .  ja v  a  2 s  .co m*/
public String getAuthToken() throws AuthTokenException {
    try {
        PostMethod postMethod = new PostMethod(CLIENT_LOGIN_URL);

        int statusCode = postToClientLogin(postMethod);
        Properties responseProperties = generatePropertiesFromResponse(postMethod.getResponseBodyAsStream());

        if (statusCode == HttpStatus.SC_OK) {
            if (responseProperties.containsKey(AUTH_TOKEN_KEY)) {
                return responseProperties.getProperty(AUTH_TOKEN_KEY).toString();
            } else {
                throw new IllegalStateException("Unable to get auth token from Client Login server");
            }
        } else {
            CaptchaInformation captchaInfo = null;
            String errorCode = null;

            if (responseProperties.containsKey(ERROR_KEY)) {
                errorCode = responseProperties.getProperty(ERROR_KEY);
                if (errorCode != null && errorCode.equals(CAPTCHA_REQUIRED_ERROR)) {
                    captchaInfo = extractCaptchaInfoFromProperties(responseProperties);
                }

                if (responseProperties.containsKey(INFO_KEY)) {
                    errorCode += ": " + responseProperties.getProperty(INFO_KEY);
                }
            }

            throw new AuthTokenException(statusCode, postMethod.getResponseBodyAsString(), errorCode,
                    captchaInfo, null);
        }
    } catch (IOException e) {
        throw new AuthTokenException(null, null, null, null, e);
    }
}