List of usage examples for java.util Map size
int size();
From source file:Main.java
public static <V> void appendMaps(Map<Integer, V> A, Map<Integer, V> B) { int index = A.size(); for (int i : B.keySet()) { A.put(index, B.get(i));//from w w w . java 2 s .c o m index++; } }
From source file:Main.java
final static public boolean isEmpty(Map map) { return map == null || map.size() == 0; }
From source file:Main.java
public static <K, V> Map<K, V> clone(Map<K, V> map1) { Map<K, V> map2 = new HashMap<K, V>(map1.size()); for (Map.Entry<K, V> e : map1.entrySet()) { map2.put(e.getKey(), e.getValue()); }/* www .ja v a 2 s . c om*/ return map2; }
From source file:Main.java
public static boolean isNonEmpty(Map map) { return (map != null && map.size() > 0); }
From source file:Main.java
static int[] getSwitchKeys(Map buckets) { int[] keys = new int[buckets.size()]; int index = 0; for (Iterator it = buckets.keySet().iterator(); it.hasNext();) { keys[index++] = ((Integer) it.next()).intValue(); }//from w w w .java 2 s . co m Arrays.sort(keys); return keys; }
From source file:Main.java
public static boolean isNotEmpty(Map<?, ?> map) { if (null != map && map.size() > 0) return true; return false; }
From source file:Main.java
/** * is null or its size is 0/* w ww . ja v a 2s . c o m*/ * * <pre> * isEmpty(null) = true; * isEmpty({}) = true; * isEmpty({1, 2}) = false; * </pre> * * @param sourceMap * @return if map is null or its size is 0, return true, else return false. */ public static <K, V> boolean isEmpty(Map<K, V> sourceMap) { return (sourceMap == null || sourceMap.size() == 0); }
From source file:Main.java
private static void addProperty(HttpURLConnection connection, Map<String, String> headers) { if (headers == null || headers.size() == 0) { return;/*from w w w . j av a2 s . c om*/ } for (Map.Entry<String, String> entry : headers.entrySet()) { connection.addRequestProperty(entry.getKey(), entry.getValue()); } }
From source file:Main.java
public static void trimMap(Map map, int numberOfElements) { if (map.size() < numberOfElements) { return;//from ww w .ja v a2 s . c o m } numberOfElements = map.size() - numberOfElements; Iterator it = map.entrySet().iterator(); int counter = 0; while (it.hasNext()) { if (counter <= numberOfElements) { it.next(); counter++; } it.remove(); } }
From source file:Main.java
public static <K, V> int size(final Map<K, V> map) { return map == null ? 0 : map.size(); }