List of usage examples for java.util Map get
V get(Object key);
From source file:net.fizzl.redditengine.data.ListMapValue.java
public static List<String> fromInputStream(String json, String name) { List<Map<String, String>> listmap = fromString(json); List<String> retval = new ArrayList<String>(); for (Map<String, String> map : listmap) { String value = (String) map.get(name); retval.add(value);//from w w w . j a v a 2s.c om } return retval; }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <K, V extends Collection<T>, T> void addToMap(Map<K, V> data, K key, T value, Class<? extends Collection> clz) { V values = data.get(key); if (values == null) { try {/*w w w. j ava 2 s .c o m*/ values = (V) clz.newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException("Failed to create collection class", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Failed to create collection class", e); } data.put(key, values); } values.add(value); }
From source file:Main.java
/** * @see list argument list/*from w w w.jav a 2 s . c om*/ * @return the most occurring element in list; when more elements occur equally * often, the earliest occurring element is returned. **/ public static <T> T mostOccurringElement(Collection<T> list) { Map<T, Integer> map = new HashMap<>(); for (T t : list) { Integer val = map.get(t); map.put(t, val == null ? 1 : val + 1); } Map.Entry<T, Integer> max = null; for (Map.Entry<T, Integer> e : map.entrySet()) { if (max == null || e.getValue() > max.getValue()) { max = e; } } return max == null ? null : max.getKey(); }
From source file:Main.java
public static void decrementLongMap(Map<String, Long> map, String key) { if (!map.containsKey(key)) return;/*from w ww . j a va2 s .c om*/ map.put(key, map.get(key) - 1); }
From source file:io.apiman.common.config.options.AbstractOptions.java
protected static String getVar(Map<String, String> optionsMap, String varName) { if (optionsMap.get(varName) == null || optionsMap.get(varName).isEmpty()) { return null; }/* www.ja va2s.c o m*/ return optionsMap.get(varName); }
From source file:Main.java
public static List findAll(Map map, List keys) { List list = new ArrayList(); for (Object key : keys) { Object value = map.get(key); if (value != null) { list.add(value);//w ww . j a v a 2 s. c o m } } return list; }
From source file:cc.linkedme.commons.useragent.OS.java
public static OS fromMap(Map<String, String> m) { return new OS(m.get("family"), m.get("major"), m.get("minor"), m.get("patch"), m.get("patch_minor")); }
From source file:com.griddynamics.genesis.notification.utils.ConfigReaderUtils.java
public static String getRequiredParameter(java.util.Map<String, String> config, String parameterName) { String value = config.get(parameterName); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException(String.format("'%s' cannot be empty", parameterName)); }/*from w w w . ja va 2 s . c o m*/ return value; }
From source file:Main.java
/** Merge two map counters. */ public static <K> void mergeMapCounters(Map<K, Integer> counter1, Map<K, Integer> counter2) { for (K key : counter2.keySet()) { increaseMapCounter(counter1, key, counter2.get(key)); }/*from www . j a va2s . c om*/ }
From source file:com.alibaba.flink.utils.MetricsMonitor.java
public static String monitorJob() { StringBuilder sb = new StringBuilder(); String url = String.format("http://%s:%d/jobs/%s", ip, port, jobId); Map json = httpResponse(url); String jobName = (String) json.get("name"); String uptime = Utils.prettyUptime(Utils.getInt(json.get("duration"), 0)); sb.append("job: ").append(jobName).append(" uptime: ").append(uptime).append("\n"); List<Map> vertices = (List<Map>) json.get("vertices"); for (Map v : vertices) { String name = (String) v.get("name"); int duration = (int) v.get("duration"); Map metrics = (Map) v.get("metrics"); long recv = Utils.parseLong(metrics.get("read-records")); long send = Utils.parseLong(metrics.get("write-records")); double recvTps = (recv * 1000.0) / duration; double sendTps = (send * 1000.0) / duration; sb.append(String.format("[<%s> recv_tps: %.2f, send_tps: %.2f]\n", name, recvTps, sendTps)); }//from w w w . j a v a 2 s . c om sb.append("---------------------------------------------\n"); return sb.toString(); }