Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

In this page you can find the example usage for java.util Map keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:adalid.util.i18n.Merger.java

public static void merge(String project) {
    logger.info(project);/*from w  ww  .  j a v a2 s  .c o m*/
    Mapper mapper = Mapper.map(project);
    //      mapper.info();
    String name, locale, tag, filename;
    List<File> list;
    File baseBundle;
    Properties baseProperties, localeProperties, mergedProperties;
    Map<String, List<File>> map = mapper.getMap();
    Set<String> keySet = map.keySet();
    for (String key : keySet) {
        logger.info(key);
        list = map.get(key);
        baseBundle = null;
        for (File bundle : list) {
            name = bundle.getName();
            locale = locale(name);
            if (locale == null) {
                baseBundle = bundle;
            }
        }
        if (baseBundle == null) {
            continue;
        }
        baseProperties = PropertiesHandler.loadProperties(baseBundle, true);
        tag = baseProperties.getProperty(LOCALE_LANGUAGE_TAG);
        if (tag == null) {
            continue;
        }
        baseProperties.remove(LOCALE_LANGUAGE_TAG);
        logger.debug("\t" + baseBundle.getName() + " " + baseProperties.size());
        for (File bundle : list) {
            name = bundle.getName();
            locale = locale(name);
            if (locale != null) {
                localeProperties = PropertiesHandler.loadProperties(bundle, true);
                logger.debug("\t" + bundle.getName() + " " + localeProperties.size());
                filename = TEST_DIR + locale + FILE_SEPARATOR + key + "_" + locale + ".properties";
                if (locale.equals(tag)) {
                    mergedProperties = baseProperties;
                } else {
                    mergedProperties = merge(bundle, baseProperties, localeProperties);
                }
                PropertiesHandler.storeProperties(mergedProperties, filename);
            }
        }
    }
}

From source file:Main.java

/**
 * Returns the ordered keys of the given map
 * //w w w .java 2 s  .  co  m
 * @param map
 *            the map
 * @return the ordered keys
 */
public final static List<String> getOrderedKeys(final Map<String, Object> map) {
    List<String> keys = new LinkedList<String>();
    if (!map.isEmpty()) {
        keys.addAll(map.keySet());
        Collections.sort(keys, new Comparator<String>() {
            /**
             * {@inheritDoc}
             */
            public int compare(String o1, String o2) {
                if (o1 == o2) {
                    return 0;
                }
                int n1 = -1;
                int n2 = -1;
                try {
                    n1 = Integer.parseInt(o1.substring(1));
                } catch (NumberFormatException e) {
                    // IGNORE
                }
                try {
                    n2 = Integer.parseInt(o2.substring(1));
                } catch (NumberFormatException e) {
                    // IGNORE
                }
                /*
                 * n1 is a number
                 */
                if (n1 != -1) {
                    /*
                     * n2 is a number
                     */
                    if (n2 != -1) {
                        return n1 - n2;
                    }
                    /*
                     * n2 is a string literal
                     */
                    return -1;
                }
                /*
                 * n1 is a literal and n2 is a number
                 */
                if (n2 != -1) {
                    return -1;
                }
                /*
                 * both are literals
                 */
                return o1.compareTo(o2);
            }
        });
    }
    return keys;
}

From source file:com.streamreduce.util.JSONUtils.java

/**
 * Copies and sanitizes any Map so that it is suitable for conversion to JSON.  This method only converts any
 * (nested) values that are of type ObjectId to its .toString() value.
 *
 * @param map Any Map./* w w  w .  ja  v  a  2  s  .c om*/
 * @return A mutable Map&lt;Object,Object&gt; copied from the passed in Map
 * with sanitized values specific to Nodeable for converting to JSON.
 */
public static <T> Map<T, Object> sanitizeMapForJson(Map<T, Object> map) {
    Map<T, Object> returnMap = Maps.newHashMap(map);
    for (T key : returnMap.keySet()) {
        Object o = returnMap.get(key);
        if (o instanceof Map) {
            returnMap.put(key, sanitizeMapForJson((Map<Object, Object>) o));
        }
        if (o instanceof ObjectId) {
            returnMap.put(key, o.toString());
        }
    }
    return returnMap;
}

From source file:com.tilab.ca.sse.core.util.SSEUtils.java

public static Map sortIntegersMap(Map passedMap) {
    LOG.debug("[sortHashMapIntegers] - BEGIN");
    List mapKeys = new ArrayList(passedMap.keySet());
    List mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);//from w ww .  java2  s. c  o  m
    Collections.reverse(mapValues);
    Collections.sort(mapKeys);
    Map sortedMap = new LinkedHashMap();
    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Object val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();
        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();
            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put((Integer) key, (Integer) val);
                break;
            }
        }
    }
    LOG.debug("[sortHashMapIntegers] - END");
    return sortedMap;
}

From source file:de.uniko.west.winter.core.serializing.JSONResultProcessor.java

public static Map<String, Set<Object>> processResultsMultiVarFilter(String results, Set<String> varFilter) {

    try {/*from   w w w .jav a2 s. c  o  m*/
        JSONObject jsonResultObject = new JSONObject(results);
        Map<String, Set<Object>> resultsMap = convertJson2Map(jsonResultObject);
        for (String key : resultsMap.keySet()) {
            if (!varFilter.contains(key)) {
                resultsMap.remove(key);
            }
        }
        return resultsMap;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:gov.nij.bundles.intermediaries.ers.osgi.EntityResolutionConversionUtils.java

/**
 * Convert a collection of SERF attributes to an equivalent collection of SERF-independent attribute wrappers
 * @param attributes the attributes/*from  w  w  w .j  av a2  s. co  m*/
 * @return the equivalent wrappers
 */
public static Map<String, AttributeWrapper> convertAttributes(Map<String, Attribute> attributes) {
    Map<String, AttributeWrapper> ret = new HashMap<String, AttributeWrapper>();
    for (String key : attributes.keySet()) {
        Attribute a = attributes.get(key);
        ret.put(key, convertAttribute(a));
    }
    return ret;
}

From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java

public static void testCookies() throws Exception {
    URL url = new URL("http://www.repubblica.it");
    URLConnection conn = url.openConnection();
    //conn.setRequestProperty("Cookie", "name1=value1; name2=value2");
    conn.connect();/*from  ww  w  .j a v a2s. c  o m*/
    Map<String, List<String>> map = conn.getHeaderFields();
    map.keySet().forEach((s) -> {
        LOG.debug(s + "\t" + map.get(s));
    });

}

From source file:Main.java

public static String getElementTagWithAttributes(String elementName, Map<String, String> attributes) {

    if (notEmptyStr(elementName) && attributes != null) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(TAG_START).append(elementName);

        for (String key : attributes.keySet()) {
            buffer.append(" ").append(key).append("=").append("\"").append(attributes.get(key)).append("\"");
        }//from  ww w .  j  av  a  2s .co m
        return buffer.append("/").append(TAG_END).toString();
    }
    return null;
}

From source file:com.tlabs.eve.api.EveRequest.java

public static final String md5(EveRequest<? extends EveResponse> request) {
    String key = request.getClass().getSimpleName() + request.getPage();

    Map<String, String> params = request.getParameters();
    for (String p : params.keySet()) {
        key = appendKey(key, p + "=" + params.get(p));
    }//from   w w  w . j av a 2  s  .c  o m
    try {
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(key.getBytes());
        return new String(digest.digest());
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:ke.co.tawi.babblesms.server.utils.StringUtil.java

/**
 * Converts a String {@link Map} into a String, for example for logging purposes
 * /*from w w w.ja  va2 s .  c o m*/
 * @param map
 * @return a String representation of a Map.
 */
public static String mapToString(Map<String, String> map) {
    StringBuilder stringBuilder = new StringBuilder();

    for (String key : map.keySet()) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append("&");
        }
        String value = map.get(key);

        stringBuilder.append(StringUtils.trimToEmpty(key));
        stringBuilder.append("=");
        stringBuilder.append(StringUtils.trimToEmpty(value));
    }

    return stringBuilder.toString();
}