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:com.haulmont.cuba.core.entity.LocaleHelper.java

public static Map<String, String> getLocalizedValuesMap(String localeBundle) {
    if (StringUtils.isNotEmpty(localeBundle)) {
        Properties localeProperties = loadProperties(localeBundle);
        if (localeProperties != null) {
            Map<String, String> map = new HashMap<>();
            for (Map.Entry<Object, Object> entry : localeProperties.entrySet()) {
                map.put((String) entry.getKey(), (String) entry.getValue());
            }//from   w  ww. ja v  a2s.  co  m
            return map;
        }
    }
    return Collections.emptyMap();
}

From source file:org.apache.falcon.metadata.MetadataMappingService.java

public static Configuration getConfiguration() {
    Configuration graphConfig = new BaseConfiguration();

    Properties configProperties = StartupProperties.get();
    for (Map.Entry entry : configProperties.entrySet()) {
        String name = (String) entry.getKey();
        if (name.startsWith(FALCON_PREFIX)) {
            String value = (String) entry.getValue();
            name = name.substring(FALCON_PREFIX.length());
            graphConfig.setProperty(name, value);
        }/*  w  w  w. j  av a 2 s .c om*/
    }

    return graphConfig;
}

From source file:org.apache.maven.wagon.shared.http.ConfigurationUtils.java

public static void copyConfig(HttpMethodConfiguration config, RequestConfig.Builder builder) {
    if (config.getConnectionTimeout() > 0) {
        builder.setConnectTimeout(config.getConnectionTimeout());
    }/*  w  w  w .  j a  v a  2s  .co m*/
    if (config.getReadTimeout() > 0) {
        builder.setSocketTimeout(config.getReadTimeout());
    }
    Properties params = config.getParams();
    if (params != null) {

        Pattern coercePattern = Pattern.compile(COERCE_PATTERN);
        for (Map.Entry entry : params.entrySet()) {
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
            Matcher matcher = coercePattern.matcher(value);
            if (matcher.matches()) {
                value = matcher.group(2);
            }

            if (key.equals(SO_TIMEOUT)) {
                builder.setSocketTimeout(Integer.parseInt(value));
            } else if (key.equals(STALE_CONNECTION_CHECK)) {
                builder.setStaleConnectionCheckEnabled(Boolean.valueOf(value));
            } else if (key.equals(CONNECTION_TIMEOUT)) {
                builder.setConnectTimeout(Integer.parseInt(value));
            } else if (key.equals(USE_EXPECT_CONTINUE)) {
                builder.setExpectContinueEnabled(Boolean.valueOf(value));
            } else if (key.equals(DEFAULT_PROXY)) {
                builder.setProxy(new HttpHost(value));
            } else if (key.equals(LOCAL_ADDRESS)) {
                try {
                    builder.setLocalAddress(InetAddress.getByName(value));
                } catch (UnknownHostException ignore) {
                    // ignore
                }
            } else if (key.equals(PROXY_AUTH_PREF)) {
                builder.setProxyPreferredAuthSchemes(Arrays.asList(value.split(",")));
            } else if (key.equals(TARGET_AUTH_PREF)) {
                builder.setTargetPreferredAuthSchemes(Arrays.asList(value.split(",")));
            } else if (key.equals(HANDLE_AUTHENTICATION)) {
                builder.setAuthenticationEnabled(Boolean.valueOf(value));
            } else if (key.equals(ALLOW_CIRCULAR_REDIRECTS)) {
                builder.setCircularRedirectsAllowed(Boolean.valueOf(value));
            } else if (key.equals(CONN_MANAGER_TIMEOUT)) {
                builder.setConnectionRequestTimeout(Integer.parseInt(value));
            } else if (key.equals(COOKIE_POLICY)) {
                builder.setCookieSpec(value);
            } else if (key.equals(MAX_REDIRECTS)) {
                builder.setMaxRedirects(Integer.parseInt(value));
            } else if (key.equals(HANDLE_REDIRECTS)) {
                builder.setRedirectsEnabled(Boolean.valueOf(value));
            } else if (key.equals(REJECT_RELATIVE_REDIRECT)) {
                builder.setRelativeRedirectsAllowed(!Boolean.valueOf(value));
            }
        }
    }
}

From source file:org.apache.maven.wagon.providers.http.ConfigurationUtils.java

public static Header[] asRequestHeaders(HttpMethodConfiguration config) {
    Properties headers = config.getHeaders();
    if (headers == null) {
        return new Header[0];
    }/*www  .j  a v  a2s  .c o m*/

    Header[] result = new Header[headers.size()];

    int index = 0;
    for (Map.Entry entry : headers.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        Header header = new BasicHeader(key, value);
        result[index++] = header;
    }

    return result;
}

From source file:org.apache.hadoop.hive.llap.cli.service.LlapServiceDriver.java

private static void populateConfWithLlapProperties(Configuration conf, Properties properties) {
    for (Entry<Object, Object> props : properties.entrySet()) {
        String key = (String) props.getKey();
        if (HiveConf.getLlapDaemonConfVars().contains(key)) {
            conf.set(key, (String) props.getValue());
        } else {/* w w  w  .  j  a v  a  2s  . co  m*/
            if (key.startsWith(HiveConf.PREFIX_LLAP) || key.startsWith(HiveConf.PREFIX_HIVE_LLAP)) {
                LOG.warn("Adding key [{}] even though it is not in the set of known llap-server keys", key);
                conf.set(key, (String) props.getValue());
            } else {
                LOG.warn("Ignoring unknown llap server parameter: [{}]", key);
            }
        }
    }
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

public static void loadFromProperties(Properties props) throws Exception {
    asr.setSurfaceFamily(props.getProperty("surface_equation"));

    Set<Map.Entry<Object, Object>> entries = props.entrySet();
    String parameter_prefix = "surface_parameter_";
    for (Map.Entry<Object, Object> entry : entries) {
        String name = (String) entry.getKey();
        if (name.startsWith(parameter_prefix)) {
            String parameterName = name.substring(parameter_prefix.length());
            asr.setParameterValue(parameterName, Float.parseFloat((String) entry.getValue()));
        }//from w ww .  ja  v  a 2  s .  co m
    }

    asr.getCamera().loadProperties(props, "camera_", "");
    asr.getFrontMaterial().loadProperties(props, "front_material_", "");
    asr.getBackMaterial().loadProperties(props, "back_material_", "");
    for (int i = 0; i < asr.MAX_LIGHTS; i++) {
        asr.getLightSource(i).setStatus(LightSource.Status.OFF);
        asr.getLightSource(i).loadProperties(props, "light_", "_" + i);
    }
    asr.setBackgroundColor(BasicIO.fromColor3fString(props.getProperty("background_color")));
    setScale(Float.parseFloat(props.getProperty("scale_factor")));
    basic_rotation = BasicIO.fromMatrix4dString(props.getProperty("rotation_matrix"));
}

From source file:com.symantec.cpe.config.ConfigHelper.java

/**
 * Load config from file: implement the function loadConfig, blind to users.
 *//*from w w  w .  ja  va2  s . c o m*/
private static Config loadConfigFromFile(String propertiesFileName) throws IOException {

    Config conf = new Config();

    try {
        // Load configs from properties file
        LOG.debug("Loading properties from " + propertiesFileName);
        InputStream fileInputStream = new FileInputStream(propertiesFileName);
        Properties properties = new Properties();
        try {
            properties.load(fileInputStream);
        } finally {
            fileInputStream.close();
        }

        for (@SuppressWarnings("rawtypes")
        Map.Entry me : properties.entrySet()) {
            try {
                // Check every property and covert to appropriate data type before
                // adding it to storm config. If no data type defined keep it as string
                if (keyTypeMap.containsKey(me.getKey().toString())) {
                    if (Number.class.equals(keyTypeMap.get(me.getKey().toString()))) {
                        conf.put((String) me.getKey(), Long.valueOf(((String) me.getValue()).trim()));
                    } else if (Map.class.equals(keyTypeMap.get(me.getKey().toString()))) {
                        if (me.getValue() != null) {
                            Map<String, Object> map = new HashMap<String, Object>();
                            String kvPairs[] = StringUtils.split(me.getValue().toString(),
                                    properties.getProperty("map.kv.pair.separator", ","));
                            for (String kvPair : kvPairs) {
                                String kv[] = StringUtils.split(kvPair,
                                        properties.getProperty("map.kv.separator", "="));
                                map.put((String) kv[0], kv[1].trim());
                            }
                            conf.put((String) me.getKey(), map);
                        }
                    } else if (Boolean.class.equals(keyTypeMap.get((String) me.getKey()))) {
                        conf.put((String) me.getKey(), Boolean.valueOf(((String) me.getValue()).trim()));
                    }
                } else {
                    conf.put(me.getKey().toString(), me.getValue());
                }
            } catch (NumberFormatException nfe) {
                LOG.error("Failed while loading properties from file " + propertiesFileName + ". The value '"
                        + me.getValue() + "' for property " + me.getKey() + " is expected to be numeric", nfe);
                throw nfe;
            }
        }
    } catch (IOException ioe) {
        LOG.error("Failed while loading properties from file " + propertiesFileName, ioe);
        throw ioe;
    }
    return conf;
}

From source file:org.opennms.ng.dao.support.ResourceTypeUtils.java

private static void loadStringAttributes(File rrdDirectory, String relativePath,
        Set<OnmsAttribute> attributes) {
    Properties properties = getStringProperties(rrdDirectory, relativePath);
    if (properties != null) {
        for (Entry<Object, Object> entry : properties.entrySet()) {
            attributes.add(new StringPropertyAttribute(entry.getKey().toString(), entry.getValue().toString()));
        }/*  ww  w  . j  a va2  s. c o  m*/
    }
}

From source file:com.jivesoftware.os.routing.bird.deployable.config.extractor.ConfigExtractor.java

private static Map<String, String> extractAndPublish(Set<Class<? extends Config>> serviceConfig,
        File defaultServiceConfigFile, String context, String instanceKey, String instanceVersion,
        HttpRequestHelper buildRequestHelper, String setPath) throws IOException {

    ConfigExtractor serviceConfigExtractor = new ConfigExtractor(new PropertyPrefix(), serviceConfig);
    serviceConfigExtractor.writeDefaultsToFile(defaultServiceConfigFile);

    Properties defaultProperties = createKeySortedProperties();
    defaultProperties.load(new FileInputStream(defaultServiceConfigFile));
    Map<String, String> config = new HashMap<>();
    for (Map.Entry<Object, Object> entry : defaultProperties.entrySet()) {
        config.put(entry.getKey().toString(), entry.getValue().toString());
    }//w  w w  . j a v  a  2  s . com

    DeployableConfig setDefaults = new DeployableConfig(context, instanceKey, instanceVersion, config);
    DeployableConfig setConfig = buildRequestHelper.executeRequest(setDefaults, setPath, DeployableConfig.class,
            null);
    if (setConfig == null) {
        System.out.println("Failed to publish default config for " + instanceKey);
    }
    return config;
}

From source file:fr.cls.atoll.motu.library.misc.utils.PropertiesUtilities.java

/**
 * Remove from <code>props</code> every properties for which key is not prefixed by the given
 * <code>prefix</code>.// w w w .  j a  v  a  2  s. c o m
 * 
 * @param props Properties to filter.
 * @param prefix Prefix used to filter
 * @param target properties destination
 * @return <code>props</code> eventually altered.
 */
public static Properties filterPropertiesByPrefix(Properties props, String prefix, Properties target) {
    if (props == null) {
        return null;
    }
    boolean modify = (props == target);
    for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        if (key.startsWith(prefix)) {
            if (!modify) {
                target.put(entry.getKey(), entry.getValue());
            }
        } else {
            if (modify) {
                iter.remove();
            }
        }
    }
    return props;
}