List of usage examples for java.util Map size
int size();
From source file:Main.java
private static void setHeader(HttpUriRequest request, Map<String, String> headers) { if (headers == null || headers.size() == 0) { throw new NullPointerException("headers not be null"); }/* ww w . j a v a 2s .c o m*/ for (Entry<String, String> entry : headers.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } }
From source file:Main.java
public static <K, V> boolean isEmpty(Map<K, V> sourceMap) { return (sourceMap == null || sourceMap.size() == 0); }
From source file:Main.java
public static String jointUrl(String url, Map<String, String> params) { if (params != null && params.size() > 0) { Uri uri = Uri.parse(url);//from w w w .j a va 2 s .c o m Uri.Builder b = uri.buildUpon(); for (Map.Entry<String, String> entry : params.entrySet()) { b.appendQueryParameter(entry.getKey(), entry.getValue()); } return b.build().toString(); } return url; }
From source file:Main.java
static <K, V> Map<K, V> getMap(Map<K, V> orig) { if (orig == null || orig.size() == 0) { return Collections.emptyMap(); } else if (orig.size() == 1) { final Map.Entry<K, V> entry = orig.entrySet().iterator().next(); return Collections.singletonMap(entry.getKey(), entry.getValue()); } else {// w ww . j av a2 s . co m return Collections.unmodifiableMap(new TreeMap<>(orig)); } }
From source file:Main.java
public static boolean isNotEmpty(Map<? extends Object, ? extends Object> map) { return map != null && map.size() > 0; }
From source file:Main.java
/** * Returns the same map <code>theMap</code> if it has elements, * otherwise it returns a new <code>HashMap</code>. * Can be used in combination with {@link CollectionUtil#emptyMapIfNull(List)} to * use a singleton empty map as initial value. * <p>//from www . j a v a 2 s . com * <strong>Pre:</strong> <code>theMap != null</code> * </p> * <p> * <strong>Post:</strong> <code>result</code> is writable. * @param <TK> Element type of the keys * @param <TV> Element type of the values * @param theList A <code>List</code> * @return The same <code>Map</code> if <code>theMap.size() > 0</code> or a new <code>HashMap</code> */ public static <TK, TV> Map<TK, TV> initAsHashMap(final Map<TK, TV> theMap) { if (theMap.size() == 0) return new HashMap<TK, TV>(); else return theMap; }
From source file:Main.java
public static boolean emptyMap(Map hash) { boolean result = true; if ((hash != null) && (hash.size() > 0)) { result = false;/*from ww w . ja v a2 s . c o m*/ } return result; }
From source file:Main.java
/** * <p>//from www. ja v a2s. c om * A method to check whether the <tt>map</tt> is empty or not. *</p> * * * @param mapToCheck * a <tt>Map</tt> which needs to be checked * * @return * a boolean value (true/false) indicating the status */ public static boolean isEmptyMap(Map<? extends Object, ? extends Object> mapToCheck) { return (mapToCheck.size() <= 0); }
From source file:Main.java
public static boolean isNotEmpty(Map<?, ?> map) { return (map != null) && (map.size() > 0); }
From source file:Main.java
/** * Return <code>true</code> if the supplied Map is not <code>null</code> * and contain only one element. Otherwise, return <code>false</code>.<br> * * @param map the Map to be checked/*from w w w . jav a 2 s . c o m*/ * @return whether the given Map is Single */ public static boolean isSingle(Map<?, ?> map) { return (map != null && map.size() == 1); }