List of usage examples for java.util Map size
int size();
From source file:adam.app.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.java
protected static PropertyValue[] toPropertyValues(Map/*<String,Object>*/ properties) { PropertyValue[] propertyValues = new PropertyValue[properties.size()]; int i = 0;//from ww w. ja v a 2s. c om for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); Object value = entry.getValue(); if (value instanceof Map) { // recursively convert nested Map to PropertyValue[] Map subProperties = (Map) value; value = toPropertyValues(subProperties); } propertyValues[i++] = property((String) entry.getKey(), value); } return propertyValues; }
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
/** * Url?/*from w ww. ja va 2s. com*/ */ private static String parse(String url, Map<String, String> params) { if (params == null && params.size() == 0) { return url; } StringBuilder builder = new StringBuilder(url); builder.append(SYMBOL_MARK); Iterator<String> it = params.keySet().iterator(); while (it.hasNext()) { String key = it.next(); try { builder.append(key).append(SYMBOL_EQUAL).append( URLEncoder.encode(params.get(key) == null ? EMPTY_STRING : params.get(key), CHARSET_UTF8)) .append(SYMBOL_CONNECTOR); } catch (UnsupportedEncodingException e) { logger.error("Parse Url error", e); throw new RuntimeException(e); } } String parse = builder.toString(); return parse.substring(0, parse.length() - 1); }
From source file:Main.java
/** * @param mathExpectation math expectation for full list * @return dispersion on full array//from w w w .j a va 2 s .co m */ private static double dispersionForFull(double mathExpectation, Map<String, Long> pressingLength) { double sum = 0.0; for (String key : pressingLength.keySet()) { double x = pressingLength.get(key) - mathExpectation; sum += x * x; } return sqrt(sum / (pressingLength.size() - 1)); }
From source file:com.autentia.intra.util.SpringUtils.java
/** * Configure this class/* w w w . j a v a 2 s. c o m*/ * * @param appCtx */ public synchronized static void configure(ApplicationContext ctx) { // Do not let configure more than once if (appCtx != null) { throw new IllegalStateException("Spring's application context cannot be set more than once"); } // Store application context appCtx = ctx; // Find AclService Map map = appCtx.getBeansOfType(AclService.class); if (map.size() != 1) { throw new IllegalStateException( "Found incorrect number of AclService instances in application context - you must have only have one!"); } aclService = (AclService) map.values().iterator().next(); // Find SidRetrievalStrategy map = appCtx.getBeansOfType(SidRetrievalStrategy.class); if (map.size() == 0) { sidRetrievalStrategy = new SidRetrievalStrategyImpl(); } else if (map.size() == 1) { sidRetrievalStrategy = (SidRetrievalStrategy) map.values().iterator().next(); } else { throw new IllegalStateException( "Found incorrect number of SidRetrievalStrategy instances in application context - you must have only have one!"); } // Find ObjectIdentityRetrievalStrategy map = appCtx.getBeansOfType(ObjectIdentityRetrievalStrategy.class); if (map.size() == 0) { objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl(); } else if (map.size() == 1) { objectIdentityRetrievalStrategy = (ObjectIdentityRetrievalStrategy) map.values().iterator().next(); } else { throw new IllegalStateException( "Found incorrect number of ObjectIdentityRetrievalStrategy instances in application context - you must have only have one!"); } }
From source file:com.hangum.tadpole.mongodb.core.utils.MongoDBTableColumn.java
/** * TableView? ? ?. // ww w.java2 s .c om * * @param dbObject * @param mapColumns * @return */ public static Map<Integer, String> getTabelColumnView(DBObject dbObject, Map<Integer, String> mapColumns) { if (dbObject == null) return mapColumns; int i = mapColumns.size(); for (String name : dbObject.keySet()) { if (!mapColumns.containsValue(name)) { mapColumns.put(i, name); i++; } } return mapColumns; }
From source file:ddf.security.permission.Permissions.java
public static List<String> getPermissionsAsStrings(Map<String, Set<String>> attributes) { if (attributes == null) { return Collections.emptyList(); }//w w w.j a v a2 s. c om List<String> stringAttributes = new ArrayList<>(attributes.size()); StringBuilder sb = new StringBuilder(); for (Map.Entry<String, Set<String>> entry : attributes.entrySet()) { sb.append(entry.getKey()); sb.append("="); sb.append(StringUtils.join(entry.getValue(), ",")); stringAttributes.add(sb.toString()); sb.setLength(0); } return stringAttributes; }
From source file:Main.java
/** * Compares the two specified maps for equality. Returns * <tt>true</tt> if the two maps represent the same mappings. More formally, two maps <tt>m1</tt> and * <tt>m2</tt> represent the same mappings if * <tt>m1.keySet().equals(m2.keySet())</tt> and for every key <tt>k</tt> * in <tt>m1.keySet()</tt>, <tt> (m1.get(k)==null ? m2.get(k)==null : * m1.get(k).equals(m2.get(k))) </tt>. * <p/>//from w w w .j a v a 2 s . com * This implementation first checks if the <tt>m1</tt> and <tt>m2</tt> are the same object; * if so it returns <tt>true</tt>. Then, it checks if the two maps have the same sizw; if * not, it returns <tt>false</tt>. If so, it iterates over <tt>m1</tt>'s * <tt>entrySet</tt> collection, and checks that map <tt>m1</tt> * contains each mapping that map <tt>m2</tt> contains. If map <tt>m1</tt> * fails to contain such a mapping, <tt>false</tt> is returned. If the * iteration completes, <tt>true</tt> is returned. * * @return <tt>true</tt> if the specified object is equal to this map. */ public static boolean equals(Map m1, Map m2) { if (m2 == m1) return true; if (m1 == null) return false; if (m2 == null) return false; if (m2.size() != m1.size()) return false; try { for (Iterator it = m1.entrySet().iterator(); it.hasNext();) { Map.Entry e = (Map.Entry) it.next(); Object key = e.getKey(); Object value = e.getValue(); if (value == null) { if (!(m2.get(key) == null && m2.containsKey(key))) return false; } else { if (!value.equals(m2.get(key))) return false; } } } catch (ClassCastException unused) { return false; } catch (NullPointerException unused) { return false; } return true; }
From source file:Main.java
public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) { if (map1 == null && map2 == null) { return true; }/*from ww w.j a v a2s . c o m*/ if (map1 == null || map2 == null) { return false; } if (map1.size() != map2.size()) { return false; } for (Map.Entry<?, ?> entry : map1.entrySet()) { Object key = entry.getKey(); Object value1 = entry.getValue(); Object value2 = map2.get(key); if (!objectEquals(value1, value2)) { return false; } } return true; }
From source file:Main.java
public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; }/* w ww . ja v a 2 s . c om*/ List<String> list = new java.util.ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; }
From source file:com.boyuanitsm.pay.alipay.util.AlipayCore.java
/** * ???//from www .j a v a 2 s. c om * @param sArray ??? * @return ??????? */ public static Map<String, String> paraFilter(Map<String, String> sArray) { Map<String, String> result = new HashMap<String, String>(); if (sArray == null || sArray.size() <= 0) { return result; } for (String key : sArray.keySet()) { String value = sArray.get(key); if (value == null || value.equals("") || key.equalsIgnoreCase("sign") || key.equalsIgnoreCase("sign_type")) { continue; } result.put(key, value); } return result; }