List of usage examples for java.util Map size
int size();
From source file:com.excilys.ebi.spring.dbunit.utils.ApplicationContextUtils.java
public static <T> T getOptionalUniqueBeanOfType(ApplicationContext applicationContext, Class<T> type) { Map<String, T> configs = applicationContext.getBeansOfType(type); isTrue(configs.size() <= 1, "found more than one bean in the applicationContext"); return configs.size() == 1 ? configs.values().iterator().next() : null; }
From source file:Main.java
public static int sizeOf(Map<?, ?> map) { if (map == null) { return 0; }/*from ww w . ja v a 2 s . c o m*/ return map.size(); }
From source file:Main.java
public final static <K, V> String join(Map<K, V> map, String separator, String separator1) { if (map == null || map.size() == 0) { return ""; }/*from ww w . java 2s .c o m*/ StringBuilder sb = new StringBuilder(); for (Map.Entry<K, V> entry : map.entrySet()) { sb.append(String.valueOf(entry.getKey())).append(separator1).append(String.valueOf(entry.getValue())) .append(separator); } return sb.toString().substring(0, sb.toString().length() - separator.length()); }
From source file:Main.java
/** * //w w w. j a v a 2 s . c om * @param pressingLength length of pause between clicks * @param mathExpectation mathExpectation values list * @return dispersion values list */ public static List<Double> dispersion(Map<String, Long> pressingLength, List<Double> mathExpectation) { int N = pressingLength.size() - 1; //dispersion int i = 0; ArrayList<Double> dispersion = new ArrayList<Double>(); for (String key : pressingLength.keySet()) { double x; double s = 0.0; for (String k : pressingLength.keySet()) { if (!k.equals(key)) { x = pressingLength.get(k) - mathExpectation.get(i); s += x * x; } } dispersion.add(sqrt(s / (N - 1))); i++; } return dispersion; }
From source file:Main.java
public static String map2String(Map<String, String> map) { StringBuilder result = new StringBuilder(); if (map == null || map.size() == 0) return ""; for (String key : map.keySet()) { result.append(key).append("=").append(map.get(key)).append("&"); }/*w w w. j a v a 2s . com*/ return result.substring(0, result.length() - 1); }
From source file:com.quartercode.eventbridge.test.ExtraAssert.java
public static void assertMapEquals(String message, Map<?, ?> map, Pair<?, ?>... entries) { assertTrue(message, map.size() == entries.length); Map<?, ?> mapClone = new HashMap<>(map); for (Pair<?, ?> expectedEntry : entries) { Object actualValue = mapClone.get(expectedEntry.getKey()); assertTrue(message, Objects.equals(expectedEntry.getValue(), actualValue)); mapClone.remove(expectedEntry.getKey()); }//from w ww . java 2s . co m }
From source file:Main.java
public static void printDetails(Map<String, String> map) { String usage = map.get("CSS"); System.out.println("Map: " + map); System.out.println("Map Size: " + map.size()); System.out.println("Map is empty: " + map.isEmpty()); System.out.println("Map contains CSS key: " + map.containsKey("CSS")); System.out.println("Usage: " + usage); System.out.println("removed: " + map.remove("CSS")); }
From source file:Main.java
/** * returns a new HashMap containing a shallow clone of the * original map./*from w w w .j a v a2 s .c o m*/ * @param origMap * @return */ public static <K, V> HashMap<K, V> clone(Map<K, V> origMap) { HashMap<K, V> newMap = new HashMap<K, V>(); if (origMap != null && origMap.size() > 0) { newMap.putAll(origMap); } return newMap; }
From source file:com.shouyingbao.pbs.core.framework.spring.context.utils.SpringContextUtil.java
/** * ?Class?//from w ww. j a v a 2 s. c om * @param type * @return */ public static <T> T getBeanOfType(Class<T> type) { Map<String, T> beans = getBeansOfType(type); if (beans.size() == 0) { throw new NoSuchBeanDefinitionException(type, "Unsatisfied dependency of type [" + type + "]: expected at least 1 matching bean"); } if (beans.size() > 1) { throw new NoSuchBeanDefinitionException(type, "expected single matching bean but found " + beans.size() + ": " + beans.keySet()); } return beans.values().iterator().next(); }
From source file:Main.java
/** * Utility method that return a String representation of a map. The elements * will be represented as "key = value"/*from w w w . ja v a2 s . c o m*/ * * @param map * The map to transform to a string * @return A csv string */ public static final String mapToString(Map map, String tabs) { if ((map == null) || (map.size() == 0)) { return ""; } StringBuffer sb = new StringBuffer(); Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { Object key = iter.next(); sb.append(tabs); sb.append(key); Object value = map.get(key); sb.append(" = '").append(value.toString()).append("'\n"); } return sb.toString(); }