List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static List<Set<Entry<String, Object>>> sortMapByKey(Map<String, ? extends Object> map) { if (map == null) { return null; }/*from w ww . ja va 2s . c om*/ List<Set<Entry<String, Object>>> returnlist = new LinkedList(map.entrySet()); Collections.sort(returnlist, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getKey()).compareTo(((Map.Entry) (o2)).getKey()); } }); return returnlist; }
From source file:Main.java
/** * Returns a copy of the Map of Maps parameter. *///from w w w . j a v a 2s . com public static <KEY_1, KEY_2, VALUE> Map<KEY_1, Map<KEY_2, VALUE>> copyOf( Map<KEY_1, ? extends Map<KEY_2, VALUE>> map) { Map<KEY_1, Map<KEY_2, VALUE>> result = new HashMap<>(); for (Map.Entry<KEY_1, ? extends Map<KEY_2, VALUE>> entry : map.entrySet()) { result.put(entry.getKey(), new HashMap<>(entry.getValue())); } return result; }
From source file:io.syndesis.inspector.JsonSchemaInspector.java
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Entry<String, JsonSchema> entry : properties.entrySet()) { final JsonSchema subschema = entry.getValue(); String path;//from www.j a v a2 s.c o m final String key = entry.getKey(); if (context == null) { path = key; } else { path = context + "." + key; } if (subschema.isValueTypeSchema()) { paths.add(path); } else if (subschema.isObjectSchema()) { fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties()); } } }
From source file:Main.java
public static String encodeParameters(Map<String, String> params) throws UnsupportedEncodingException { StringBuilder body = new StringBuilder(); Iterator<Entry<String, String>> it = params.entrySet().iterator(); boolean firstElement = true; while (it.hasNext()) { Map.Entry<String, String> pair = it.next(); if (firstElement) { firstElement = false;//w w w .ja v a2 s. co m } else { body.append("&"); } body.append(URLEncoder.encode(pair.getKey(), CHARSET) + "=" + ((pair.getValue() == null) ? "null" : URLEncoder.encode(pair.getValue(), CHARSET))); } return body.toString(); }
From source file:Main.java
/** * map sort/*from w w w . j a va2 s . co m*/ * @param map * @param compator * @return */ public static <K, V> Map<K, V> sortMap(Map<K, V> map, Comparator<Entry<K, V>> compator) { Map<K, V> result = new LinkedHashMap<K, V>(); List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>(map.entrySet()); Collections.sort(entries, compator); for (Entry<K, V> entry : entries) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java
protected static JsonObject mapToJson(Map<String, String> map) { JsonObject root = new JsonObject(); for (Entry<String, String> entry : map.entrySet()) { String[] split = StringUtils.split(entry.getKey(), '.'); ArrayDeque<String> dq = new ArrayDeque<>(Arrays.asList(split)); createOrDescend(root, dq, entry.getValue()); }/* ww w .j a va 2 s . co m*/ return root; }
From source file:Main.java
/** Partitions a Map into a Collection of Maps, each of max size n. */ public static <K, V> ImmutableList<ImmutableMap<K, V>> partitionMap(Map<K, V> map, int size) { ImmutableList.Builder<ImmutableMap<K, V>> shards = new ImmutableList.Builder<>(); for (Iterable<Map.Entry<K, V>> entriesShard : partition(map.entrySet(), size)) { shards.add(ImmutableMap.copyOf(entriesShard)); }// ww w .j ava 2 s .co m return shards.build(); }
From source file:com.github.horrorho.liquiddonkey.util.Bytes.java
public static <T> String hex(Map<ByteString, T> map, Function<T, String> function) { return map == null ? "null" : map.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> function.apply(entry.getValue()))) .toString();/*from w w w . j a v a 2 s . c o m*/ }
From source file:com.github.mushkevych.genfabeto.Ganfabeto.java
public static Object createBean(String className, Map<String, Object> params) { try {// www .ja va 2 s .co m Object bean = createObject(className); for (Map.Entry<String, Object> entry : params.entrySet()) { ReflectionTestUtils.setField(bean, entry.getKey(), entry.getValue()); } return bean; } catch (ClassNotFoundException e) { String eMessage = String.format("Unable to find a class %s", className); log.error(eMessage, e); throw new BeanCreationException(eMessage, e); } catch (IllegalAccessException e) { String eMessage = String.format("Unable to access a class %s", className); log.error(eMessage, e); throw new BeanCreationException(eMessage, e); } catch (InstantiationException e) { String eMessage = String.format("Unable to instantiate a class %s", className); log.error(eMessage, e); throw new BeanCreationException(eMessage, e); } }
From source file:com.blackboard.WebdavBulkDeleterClient.java
@SuppressWarnings("static-access") private static Options addAllOptions(Options options, Map<String, String> optionsAvailable) { Iterator<Entry<String, String>> it = optionsAvailable.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = it.next(); String name = pairs.getKey(); String description = pairs.getValue(); options.addOption(OptionBuilder.withLongOpt(name).withDescription(description).hasArg() .withArgName(name).create()); }/*from w w w . j a v a 2s . com*/ return (options); }