Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

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

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:de.fhg.iais.asc.commons.AscConfiguration.java

/**
 * Read in the properties information to the context
 * //from  w w w  . j av a 2 s.c  om
 * @param globalpropertiesFilepath the global properties
 * @param providerspecificpropertiesFilepath the provider specific properties
 */
public final void readOutPropertiesFromFile(String globalpropertiesFilepath,
        String providerspecificpropertiesFilepath) {
    if (globalpropertiesFilepath != null) {
        Properties globalproperties = readOnePropertyFile(globalpropertiesFilepath);
        for (Entry<Object, Object> e : globalproperties.entrySet()) {
            this.propertiesMap.put(e.getKey().toString(), e.getValue());
        }
    }

    // local will override global
    if (providerspecificpropertiesFilepath != null) {
        Properties providerspecificproperties = readOnePropertyFile(providerspecificpropertiesFilepath);
        for (Entry<Object, Object> e : providerspecificproperties.entrySet()) {
            this.propertiesMap.put(e.getKey().toString(), e.getValue());
        }
    }
}

From source file:org.apache.ignite.internal.client.impl.ClientPropertiesConfigurationSelfTest.java

/**
 * Test client configuration loaded from the properties.
 *
 * @throws Exception In case of exception.
 */// ww w.  j  a v  a  2 s . c o m
public void testCreation() throws Exception {
    // Validate default configuration.
    GridClientConfiguration cfg = new GridClientConfiguration();

    cfg.setServers(Arrays.asList("localhost:11211"));

    validateConfig(0, cfg);

    // Validate default properties-based configuration.
    cfg = new GridClientConfiguration();

    cfg.setServers(Arrays.asList("localhost:11211"));

    validateConfig(0, cfg);

    // Validate loaded configuration.
    Properties props = loadProperties(1, GRID_CLIENT_CONFIG);
    validateConfig(0, new GridClientConfiguration(props));

    // Validate loaded configuration with changed key prefixes.
    Properties props2 = new Properties();

    for (Map.Entry<Object, Object> e : props.entrySet())
        props2.put("new." + e.getKey(), e.getValue());

    validateConfig(0, new GridClientConfiguration("new.ignite.client", props2));
    validateConfig(0, new GridClientConfiguration("new.ignite.client.", props2));

    // Validate loaded test configuration.
    File tmp = uncommentProperties(GRID_CLIENT_CONFIG);

    props = loadProperties(25, tmp.toURI().toURL());
    validateConfig(2, new GridClientConfiguration(props));

    // Validate loaded test configuration with changed key prefixes.
    props2 = new Properties();

    for (Map.Entry<Object, Object> e : props.entrySet())
        props2.put("new." + e.getKey(), e.getValue());

    validateConfig(2, new GridClientConfiguration("new.ignite.client", props2));
    validateConfig(2, new GridClientConfiguration("new.ignite.client.", props2));

    // Validate loaded test configuration with empty key prefixes.
    props2 = new Properties();

    for (Map.Entry<Object, Object> e : props.entrySet())
        props2.put(e.getKey().toString().replace("ignite.client.", ""), e.getValue());

    validateConfig(2, new GridClientConfiguration("", props2));
    validateConfig(2, new GridClientConfiguration(".", props2));
}

From source file:org.apache.drill.test.ClusterFixture.java

private Properties configProperties(Properties configProps) {
    Properties effectiveProps = new Properties();
    for (Entry<Object, Object> entry : configProps.entrySet()) {
        effectiveProps.put(entry.getKey(), entry.getValue().toString());
    }//from  w  ww.  j  a va 2  s.  c o m
    if (zkHelper != null) {
        effectiveProps.put(ExecConstants.ZK_CONNECTION,
                zkHelper.getConfig().getString(ExecConstants.ZK_CONNECTION));
    }
    return effectiveProps;
}

From source file:energy.usef.core.config.AbstractConfig.java

/***
 * Reads the configuration properties which consist of application specific properties which overrule default properties.
 *
 * @throws IOException/*from  w  w w  .  j  a  v  a2 s.  c  om*/
 */
public void readProperties() throws IOException {
    properties.clear();
    String filename = getConfigurationFolder() + CONFIG_LOCAL_FILE_NAME;
    Properties defaults = readDefaultProperties();
    if (isFileExists(filename)) {
        properties = readPropertiesFromFile(filename);

        // merge default properties if the property does not exist.
        for (Entry<Object, Object> entry : defaults.entrySet()) {
            String key = (String) entry.getKey();
            if (properties.getProperty(key) == null) {
                LOGGER.debug("Default property is added: {}", key);
                properties.put(key, entry.getValue());
            }
        }

    } else {
        LOGGER.warn("Could not find properties file: {}. Using the default properties.", filename);
        properties = defaults;
    }

    List<String> propertiesList = properties.entrySet().stream()
            .map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList());
    Collections.sort(propertiesList);

    LOGGER.info("\nProperties:\n" + StringUtils.join(propertiesList.toArray(), "\n"));
}

From source file:org.ala.spatial.web.services.SitesBySpeciesWSControllerTabulated.java

@RequestMapping(value = { "sxs/delete", "sxs/sxs/delete" }, method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView sxsDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    String url = req.getParameter("u");

    try {//  www .j  a v a2  s. c om
        String pth = AlaspatialProperties.getAnalysisWorkingDir() + File.separator + "sxs" + File.separator;

        initListProperties();
        Properties p = new Properties();
        p.load(new FileReader(pth + "list.properties"));

        for (Entry<Object, Object> entry : p.entrySet()) {
            if (((String) entry.getValue()).equals(url)) {
                FileWriter fw = new FileWriter(pth + ((String) entry.getKey()));
                fw.write("-1");
                fw.flush();
                fw.close();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return new ModelAndView("redirect:" + AlaspatialProperties.getAlaspatialUrl() + "/sxs");
}

From source file:org.openbaton.nfvo.system.SystemStartup.java

@Override
public void run(String... args) throws Exception {
    log.info("Initializing OpenBaton");

    log.debug(Arrays.asList(args).toString());

    propFileLocation = propFileLocation.replace("file:", "");
    log.debug("Property file: " + propFileLocation);

    InputStream is = new FileInputStream(propFileLocation);
    Properties properties = new Properties();
    properties.load(is);//from   w ww.ja  v  a  2s.com

    log.debug("Config Values are: " + properties.values());

    Configuration c = new Configuration();

    c.setName("system");
    c.setConfigurationParameters(new HashSet<ConfigurationParameter>());

    /**
     * Adding properties from file
     */
    for (Entry<Object, Object> entry : properties.entrySet()) {
        ConfigurationParameter cp = new ConfigurationParameter();
        cp.setConfKey((String) entry.getKey());
        cp.setValue((String) entry.getValue());
        c.getConfigurationParameters().add(cp);
    }

    /**
     * Adding system properties
     */
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
        ConfigurationParameter cp = new ConfigurationParameter();
        log.trace("Display name: " + netint.getDisplayName());
        log.trace("Name: " + netint.getName());
        cp.setConfKey("ip-" + netint.getName().replaceAll("\\s", ""));
        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            if (inetAddress.getHostAddress().contains(".")) {
                log.trace("InetAddress: " + inetAddress.getHostAddress());
                cp.setValue(inetAddress.getHostAddress());
            }
        }
        log.trace("");
        c.getConfigurationParameters().add(cp);
    }

    configurationRepository.save(c);

    if (installPlugin) {
        startPlugins(pluginDir);
    }
}

From source file:fr.landel.utils.commons.StringUtils.java

/**
 * Injects all arguments in the specified char sequence. The arguments are
 * injected by replacement of keys between braces. To exclude keys, just
 * double braces (like {{key}} will return {key}). If some keys aren't
 * found, they are ignored./* www  .j av a 2  s. c o  m*/
 * 
 * <p>
 * precondition: {@code charSequence} cannot be {@code null}
 * </p>
 * 
 * <pre>
 * Properties properties = new Properties();
 * properties.setProperty("where", "beach");
 * properties.setProperty("when", "afternoon");
 * 
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "", properties);
 * // =&gt; ""
 * 
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to the ${where} this ${when}", properties);
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to ${where}${{where}}${where}", properties);
 * // =&gt; "I'll go to beach${where}beach"
 * </pre>
 * 
 * @param include
 *            the characters that surround the property key to replace
 * @param exclude
 *            the characters that surround the property key to exclude of
 *            replacement
 * @param charSequence
 *            the input char sequence
 * @param properties
 *            the properties to inject
 * @return the result with replacements
 */
public static String injectKeys(final Pair<String, String> include, final Pair<String, String> exclude,
        final CharSequence charSequence, final Properties properties) {
    if (charSequence == null) {
        throw new IllegalArgumentException("The input char sequence cannot be null");
    } else if (isEmpty(charSequence) || properties == null || properties.isEmpty()) {
        return charSequence.toString();
    }

    return injectKeys(include, exclude, charSequence,
            properties.entrySet().toArray(CastUtils.cast(new Map.Entry[properties.size()])));
}

From source file:org.apache.falcon.oozie.OozieOrchestrationWorkflowBuilder.java

protected CONFIGURATION getConfig(Properties props) {
    CONFIGURATION conf = new CONFIGURATION();
    for (Map.Entry<Object, Object> prop : props.entrySet()) {
        CONFIGURATION.Property confProp = new CONFIGURATION.Property();
        confProp.setName((String) prop.getKey());
        confProp.setValue((String) prop.getValue());
        conf.getProperty().add(confProp);
    }/*  w  ww  . j a  v a 2s .  co m*/
    return conf;
}

From source file:net.lightbody.bmp.proxy.jetty.http.HashUserRealm.java

/** Load realm users from properties file.
 * The property file maps usernames to password specs followed by
 * an optional comma separated list of role names.
 *
 * @param config Filename or url of user properties file.
 * @exception IOException //from w  w w  .j  a  v  a  2s. c o m
 */
public void load(String config) throws IOException {
    _config = config;
    if (log.isDebugEnabled())
        log.debug("Load " + this + " from " + config);
    Properties properties = new Properties();
    Resource resource = Resource.newResource(config);
    properties.load(resource.getInputStream());

    Iterator iter = properties.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();

        String username = entry.getKey().toString().trim();
        String credentials = entry.getValue().toString().trim();
        String roles = null;
        int c = credentials.indexOf(',');
        if (c > 0) {
            roles = credentials.substring(c + 1).trim();
            credentials = credentials.substring(0, c).trim();
        }

        if (username != null && username.length() > 0 && credentials != null && credentials.length() > 0) {
            put(username, credentials);
            if (roles != null && roles.length() > 0) {
                StringTokenizer tok = new StringTokenizer(roles, ", ");
                while (tok.hasMoreTokens())
                    addUserToRole(username, tok.nextToken());
            }
        }
    }
}

From source file:org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor.java

/**
 * @param globalConfig The global configuration.
 * @param props Property values/*  ww w  .  j av a 2 s.  c  om*/
 * @return The Stellar configuration.
 */
private Map<String, Object> getStellarConfig(Map<String, Object> globalConfig, Properties props) {
    Map<String, Object> stellarConfig = new HashMap<>();
    stellarConfig.putAll(globalConfig);
    if (props != null) {
        for (Map.Entry<Object, Object> kv : props.entrySet()) {
            stellarConfig.put(kv.getKey().toString(), kv.getValue());
        }
    }
    return stellarConfig;
}