List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:de.christianseipl.utilities.maputils.MapPrinting.java
public static <K, V> void printMapCollection(String _header, Map<K, ? extends Collection<V>> _map) { System.out.println(_header);/*from w ww. j a v a2 s .co m*/ for (Entry<K, ? extends Collection<V>> entry : _map.entrySet()) { System.out.printf("%20s\t", entry.getKey().toString()); Object[] elements = entry.getValue().toArray(); System.out.printf("[ "); for (int i = 0; i < elements.length - 1; i++) { System.out.printf("%s, ", elements[i].toString()); } if (elements.length > 0) { System.out.printf("%s ", elements[elements.length - 1].toString()); } System.out.printf("]"); System.out.println(); } System.out.println(); System.out.println(); }
From source file:hu.ppke.itk.nlpg.purepos.common.Util.java
public static <K, L> Pair<K, Double> findMax2(Map<K, Pair<L, Double>> map) { Pair<K, Double> ret = null; for (Map.Entry<K, Pair<L, Double>> e : map.entrySet()) { if (ret == null || e.getValue().getValue() > ret.getValue()) { ret = Pair.of(e.getKey(), e.getValue().getValue()); }// ww w .java 2 s . com } return ret; }
From source file:Main.java
/** * Converts a map into a delimited string value. * A "{@literal =}" separates the keys and values and a "{@literal &}" separates the key pairs. * @param stringMap map to convert/*from w ww . j av a 2 s .c o m*/ * @return string representation of map */ public static String convertMapToString(final Map<String, String> stringMap) { final StringBuilder sb = new StringBuilder(); final char keySeparator = '='; final char pairSeparator = '&'; for (final Map.Entry<String, String> pair : stringMap.entrySet()) { sb.append(pair.getKey()); sb.append(keySeparator); sb.append(pair.getValue()); sb.append(pairSeparator); } return sb.toString().substring(0, sb.length() - 1); }
From source file:Main.java
/** * Print an empty XML tag./*from w w w .j a v a 2s.c o m*/ * * @param tag * tag name * @param attributes * list of attributes * @return opening tag */ public static StringBuilder emptyTag(final String tag, final Map<String, String> attributes) { final StringBuilder s = new StringBuilder(ELEMENT_EMPTY_OPEN).append(tag); for (final Map.Entry<String, String> attribute : attributes.entrySet()) { s.append(ATTRIBUTE_DELIMITER); s.append(attribute.getKey()); s.append(ATTRIBUTE_EQUALS); s.append(ATTRIBUTE_VALUE_ESCAPE_START); s.append(attribute.getValue()); s.append(ATTRIBUTE_VALUE_ESCAPE_END); } s.append(ELEMENT_EMPTY_CLOSE); return s; }
From source file:org.eel.kitchen.jsonschema.ref.JsonPointerTest.java
private static Object[] mungeArguments(final JsonNode node) { final Message.Builder msg = Domain.REF_RESOLVING.newMessage().setKeyword("$ref") .setMessage("illegal JSON Pointer"); final Map<String, JsonNode> map = JacksonUtils.nodeToMap(node.get("info")); for (final Map.Entry<String, JsonNode> entry : map.entrySet()) msg.addInfo(entry.getKey(), entry.getValue()); return new Object[] { node.get("input").textValue(), msg.build() }; }
From source file:net.sf.zekr.engine.search.tanzil.RegexUtils.java
License:asdf
static final String applyRules(String str, Map<String, String> rule) { for (Entry<String, String> entry : rule.entrySet()) { str = pregReplace(str, entry.getKey().toString(), entry.getValue().toString()); }//from w ww.java 2s.co m return str; }
From source file:Main.java
/** * Sort a map by supplied comparator logic. * * @return new instance of {@link LinkedHashMap} contained sorted entries of supplied map. * @author Maxim Veksler/*from w w w .ja v a2 s .com*/ */ public static <K, V> LinkedHashMap<K, V> sortMap(final Map<K, V> map, final Comparator<Map.Entry<K, V>> comparator) { // Convert the map into a list of key,value pairs. List<Map.Entry<K, V>> mapEntries = new LinkedList<Map.Entry<K, V>>(map.entrySet()); // Sort the converted list according to supplied comparator. Collections.sort(mapEntries, comparator); // Build a new ordered map, containing the same entries as the old map. LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(map.size() + (map.size() / 20)); for (Map.Entry<K, V> entry : mapEntries) { // We iterate on the mapEntries list which is sorted by the comparator putting new entries into // the targeted result which is a sorted map. result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
public static Map handleURLEncodedResponse(HttpResponse response) { Map<String, Charset> map = Charset.availableCharsets(); Map<String, String> oauthResponse = new HashMap<String, String>(); Set<Map.Entry<String, Charset>> set = map.entrySet(); Charset charset = null;/* ww w .j a v a 2 s. c o m*/ HttpEntity entity = response.getEntity(); System.out.println(); System.out.println("********** URL Encoded Response Received **********"); for (Map.Entry<String, Charset> entry : set) { System.out.println(String.format(" %s = %s", entry.getKey(), entry.getValue())); if (entry.getKey().equalsIgnoreCase(HTTP.UTF_8)) { charset = entry.getValue(); } } try { List<NameValuePair> list = URLEncodedUtils.parse(entity); for (NameValuePair pair : list) { System.out.println(String.format(" %s = %s", pair.getName(), pair.getValue())); oauthResponse.put(pair.getName(), pair.getValue()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new RuntimeException("Could not parse URLEncoded Response"); } return oauthResponse; }
From source file:Main.java
public static <T> List<T> mapToList(Map<String, T> map, String... excludeKey) { Map<String, T> tmpMap = new LinkedHashMap<String, T>(map); for (String exclude : excludeKey) { tmpMap.remove(exclude);/*from ww w . j ava 2 s. c o m*/ } List<T> list = new ArrayList<>(); for (Map.Entry<String, T> entry : tmpMap.entrySet()) { list.add(entry.getValue()); } return list; }
From source file:io.logspace.hq.core.solr.event.SolrNativeQueryService.java
private static SolrParams createSolrParams(Map<String, String[]> parameters) { ModifiableSolrParams result = new ModifiableSolrParams(); for (Entry<String, String[]> eachEntry : parameters.entrySet()) { result.add(eachEntry.getKey(), eachEntry.getValue()); }// www.java 2 s . c om return result; }