List of usage examples for java.util Map size
int size();
From source file:com.brienwheeler.lib.spring.beans.AutowireUtils.java
public static <T> Collection<T> getAutowireBeans(ApplicationContext applicationContext, Class<T> clazz, Log log) {/*from w ww . j a v a2s.c o m*/ ValidationUtils.assertNotNull(applicationContext, "applicationContext cannot be null"); ValidationUtils.assertNotNull(clazz, "clazz cannot be null"); ValidationUtils.assertNotNull(log, "log cannot be null"); Map<String, T> beans = applicationContext.getBeansOfType(clazz); if (beans.size() > 0) { log.info("autowiring " + beans.size() + " " + clazz.getSimpleName()); } return beans.values(); }
From source file:Main.java
/** * Write a HashMap to a Parcel, class of key and value are both String * /*www.j a v a 2s . c om*/ * @param map * @param out * @param flags */ public static void writeHashMapStringAndString(Map<String, String> map, Parcel out, int flags) { if (map != null) { out.writeInt(map.size()); for (Entry<String, String> entry : map.entrySet()) { out.writeString(entry.getKey()); out.writeString(entry.getValue()); } } else { out.writeInt(-1); } }
From source file:Main.java
public final static <GOutput> List<GOutput> toOrderedList(final Map<Integer, GOutput> responseMap) { final List<GOutput> localResponses = new ArrayList<GOutput>(responseMap.size()); for (int i = 0; i < responseMap.size(); i++) { final GOutput rr = responseMap.get(Integer.valueOf(i)); assert rr != null; localResponses.add(rr);// w w w .j a va 2s .co m } return localResponses; }
From source file:Main.java
/** * Clones the lhs map and add all things from the * rhs map./*from ww w . j a v a 2 s. co m*/ * * @param lhs the first map * @param rhs the second map * @return the merged map */ public static Map merge(Map lhs, Map rhs) { Map result = null; if ((lhs == null) || (lhs.size() == 0)) { result = copy(rhs); } else if ((rhs == null) || (rhs.size() == 0)) { result = copy(lhs); } else { result = copy(lhs); result.putAll(rhs); } return result; }
From source file:Main.java
public static String[] map2keyValueStrings(Map<String, String> map, char delimiter) { String[] sa = new String[map.size()]; int i = 0;//from w w w . ja va 2s. c o m for (Map.Entry<String, String> e : map.entrySet()) { sa[i++] = e.getKey() + delimiter + e.getValue(); } return sa; }
From source file:Main.java
/** * Add parameters stored in the Map to the uri string. * Map can contain Object values which will be converted to the string, * or Object arrays, which will be treated as multivalue attributes. * //from w w w .ja v a 2 s.co m * @param uri The uri to add parameters into * @param parameters The map containing parameters to be added * @return The uri with added parameters */ public static String parameterize(String uri, Map parameters) { if (parameters.size() == 0) { return uri; } StringBuffer buffer = new StringBuffer(uri); if (uri.indexOf('?') == -1) { buffer.append('?'); } else { buffer.append('&'); } for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); if (entry.getValue().getClass().isArray()) { Object[] value = (Object[]) entry.getValue(); for (int j = 0; j < value.length; j++) { if (j > 0) { buffer.append('&'); } buffer.append(entry.getKey()); buffer.append('='); buffer.append(value[j]); } } else { buffer.append(entry.getKey()); buffer.append('='); buffer.append(entry.getValue()); } if (i.hasNext()) { buffer.append('&'); } } return buffer.toString(); }
From source file:Main.java
/** * Copy each map entry to a new map but check that each key and value isn't null. Throw * a {@code NullPointerException} if it's the case. * * @param entries entries to copy// ww w. j a va 2 s . c o m * @param <K> type of key * @param <V> type of value * @return cloned map * @throws NullPointerException if a key or value is null */ public static <K, V> Map<K, V> copyMapButFailOnNull(Map<? extends K, ? extends V> entries) { Map<K, V> entriesToRemap = new HashMap<>(entries.size()); entries.forEach((k, v) -> { // If a key/value is null, throw NPE, nothing gets mutated if (k == null || v == null) { throw new NullPointerException(); } entriesToRemap.put(k, v); }); return entriesToRemap; }
From source file:Main.java
public static <K, V> List<K> keyToList(Map<K, V> map, int count) { if (isNotNull(map)) { if (map.size() <= count) { return new ArrayList<K>(map.keySet()); } else {//from w w w . j a v a2 s .co m List<K> list = new ArrayList<K>(map.keySet()); return list.subList(0, count); } } return null; }
From source file:Main.java
/** * Write a HashMap to a Parcel, class of key and value can parcelable both * //w ww .j a va 2 s.co m * @param map * @param out * @param flags */ public static <K extends Parcelable, V extends Parcelable> void writeHashMap(Map<K, V> map, Parcel out, int flags) { if (map != null) { out.writeInt(map.size()); for (Entry<K, V> entry : map.entrySet()) { out.writeParcelable(entry.getKey(), flags); out.writeParcelable(entry.getValue(), flags); } } else { out.writeInt(-1); } }
From source file:io.cloudslang.lang.entities.utils.MapUtils.java
public static Map<String, Value> convertMapNonSensitiveValues(Map<String, ? extends Serializable> source) { Map<String, Value> target = new HashMap<>(source.size()); for (Map.Entry<String, ? extends Serializable> entry : source.entrySet()) { target.put(entry.getKey(), ValueFactory.create(entry.getValue())); }/*from ww w .j av a 2 s.c om*/ return target; }