List of usage examples for java.util Map size
int size();
From source file:Main.java
public static boolean isNotEmpty(Map<?, ?> map) { if (map != null && !map.isEmpty() && map.size() > 0) { return true; } else {/*from ww w . j a va 2s . com*/ return false; } }
From source file:Main.java
public static boolean isEmpty(Map<?, ?> map) { if (null == map || map.isEmpty() || map.size() <= 0) return true; return false; }
From source file:Main.java
public static <K, V> Map<K, V> put(Map<K, V> map, K key, V value) { final int size = map.size(); if (size == 0) { return ImmutableMap.of(key, value); } else if (map instanceof ImmutableMap) { map = Maps.newHashMap(map);// w ww . j a v a 2 s. com } map.put(key, value); return map; }
From source file:Main.java
public static final int size() { Map<Object, Object> cache = LOCAL_CACHE.get(); return cache == null ? 0 : cache.size(); }
From source file:Main.java
public static int size(final Map map) { return null != map ? map.size() : 0; }
From source file:Main.java
/** * join map/*from w ww . j a va 2s . c o m*/ * * @param map * @return */ public static String toJson(Map<String, String> map) { if (map == null || map.size() == 0) { return null; } StringBuilder paras = new StringBuilder(); paras.append("{"); Iterator<Map.Entry<String, String>> ite = map.entrySet().iterator(); while (ite.hasNext()) { Map.Entry<String, String> entry = (Map.Entry<String, String>) ite.next(); paras.append("\"").append(entry.getKey()).append("\":\"").append(entry.getValue()).append("\""); if (ite.hasNext()) { paras.append(","); } } paras.append("}"); return paras.toString(); }
From source file:Main.java
static public String assemblyUrlByCommon(String url, Map<String, String> params) { if (params == null && params.size() == 0) { return url; } else {//from w w w .j a va2s. c o m StringBuilder sb = new StringBuilder(url); sb.append("?"); Set<String> keys = params.keySet(); int i = 0; for (String key : keys) { String value = params.get(key); sb.append(key).append("=").append(value); if (i != keys.size() - 1) { sb.append("&"); } i++; } return sb.toString(); } }
From source file:Main.java
public static <T1, T2, T3> Map<T1, T3> merge(Map<T1, T2> map1, Map<T2, T3> map2) { Map<T1, T3> map3 = new HashMap<T1, T3>(map1.size()); merge(map1, map2, map3);//from w w w.j a v a 2 s . c o m return map3; }
From source file:Main.java
public static <K> Map<K, Long> convertMapValueToLong(Map<K, String> map) { Map<K, Long> covertedResult = new HashMap<K, Long>(map.size()); Set<Entry<K, String>> entrySet = map.entrySet(); for (Entry<K, String> entry : entrySet) { covertedResult.put(entry.getKey(), Long.valueOf(entry.getValue().trim())); }/*from w w w . j a va2s . co m*/ return covertedResult; }
From source file:Main.java
/** * Given a map, determine the proper initial size for a new Map to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original map/*from w w w . j a v a 2 s. c om*/ * * @return The proper size. */ public static int determineProperSizing(Map original) { return determineProperSizing(original.size()); }