List of usage examples for java.util Map size
int size();
From source file:de.betterform.xml.xforms.CustomElementFactory.java
/** * Loads the configuration for custom elements. * /*from www. j a v a2s .co m*/ * @return A Map where the keys are in the format namespace-uri:element-name * and the value is the reference to the class that implements the * custom element, or an empty map if the configuration could not be * loaded for some reason. */ private static Map getCustomElementsConfig() { try { Map elementClassNames = Config.getInstance().getCustomElements(); Map elementClassRefs = new HashMap(elementClassNames.size()); Iterator itr = elementClassNames.entrySet().iterator(); //converts class names into the class references while (itr.hasNext()) { Map.Entry entry = (Entry) itr.next(); String key = (String) entry.getKey(); String className = (String) entry.getValue(); Class classRef = Class.forName(className, true, CustomElementFactory.class.getClassLoader()); elementClassRefs.put(key, classRef); } //return the configuration return elementClassRefs; } catch (XFormsConfigException xfce) { LOGGER.error("could not load custom-elements config: " + xfce.getMessage()); } catch (ClassNotFoundException cnfe) { LOGGER.error("class configured for custom-element not found: " + cnfe.getMessage()); } //returns an empty map (no custom elements) return Collections.EMPTY_MAP; }
From source file:com.insightml.utils.Collections.java
public static <K, V> Map<K, V> subMap(final Map<K, V> sorted, final int n) { if (Check.num(n, 1, 9999999) >= sorted.size()) { return sorted; }/* w ww .j ava 2 s. c om*/ final Map<K, V> map = new LinkedHashMap<>(); int i = 0; for (final Entry<K, V> entry : sorted.entrySet()) { map.put(entry.getKey(), entry.getValue()); if (++i >= n) { break; } } return map; }
From source file:Main.java
/** * Returns <tt>true</tt> iff the given {@link Collection}s contain * exactly the same elements with exactly the same cardinalities. * <p/>/*from w ww . j ava2s.c om*/ * That is, iff the cardinality of <i>e</i> in <i>a</i> is * equal to the cardinality of <i>e</i> in <i>b</i>, * for each element <i>e</i> in <i>a</i> or <i>b</i>. * * @param a the first collection, must not be null * @param b the second collection, must not be null * @return <code>true</code> iff the collections15 contain the same elements with the same cardinalities. */ public static <E> boolean isEqualCollection(final Collection<? extends E> a, final Collection<? extends E> b) { if (a.size() != b.size()) { return false; } else { Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); if (mapa.size() != mapb.size()) { return false; } else { Iterator it = mapa.keySet().iterator(); while (it.hasNext()) { Object obj = it.next(); if (getFreq(obj, mapa) != getFreq(obj, mapb)) { return false; } } return true; } } }
From source file:org.shareok.data.webserv.WebUtil.java
public static ModelAndView getServerList(ModelAndView model, RepoServerService serverService) throws JsonProcessingException { Map<String, String> serverList = serverService.getServerNameIdList(); if (null != serverList && serverList.size() > 0) { ObjectMapper mapper = new ObjectMapper(); Collection<String> ids = serverList.values(); List<RepoServer> serverObjList = serverService.getServerObjList(ids); String serverListJson = mapper.writeValueAsString(serverList); model.addObject("serverList", serverListJson); model.addObject("serverObjList", mapper.writeValueAsString(serverObjList)); } else {//w w w . jav a 2 s. co m // model.addObject("emptyServerList", "There are NO servers set up."); } return model; }
From source file:lucee.commons.net.http.HTTPEngine.java
private static Header[] toHeaders(Map<String, String> headers) { if (CollectionUtil.isEmpty(headers)) return null; Header[] rtn = new Header[headers.size()]; Iterator<Entry<String, String>> it = headers.entrySet().iterator(); Entry<String, String> e; int index = 0; while (it.hasNext()) { e = it.next();// w w w . ja v a2s. c om rtn[index++] = new HeaderImpl(e.getKey(), e.getValue()); } return rtn; }
From source file:com.dell.asm.asmcore.asmmanager.util.razor.RazorUtil.java
/** * Parse the return value of the razor node GET api, e.g. * http://RAZOR_HOST/api/collections/nodes/node2 * * @param mapper ObjectMapper to parse JSON * @param nodeJson Json node data/*from w ww.j a v a 2s.co m*/ * @return Device object */ public static RazorDevice parseNodeJson(ObjectMapper mapper, String nodeJson) throws IOException { Map node = mapper.readValue(nodeJson, Map.class); Map hwInfo = (Map) node.get(NODE_HW_INFO_KEY); String uuid = (String) hwInfo.get(NODE_HW_INFO_UUID_KEY); RazorDevice ret = new RazorDevice(); ret.setId((String) node.get("name")); ret.setUuid(uuid); Map policy = (Map) node.get(NODE_POLICY); if (policy == null || policy.isEmpty()) { ret.setStatus(RazorDeviceStatus.UNPROVISIONED); } else { //System.out.println("Policy..."); for (Object key : policy.keySet()) { String policyName = (String) key; Object policyValueObject = policy.get(policyName); String policyValueString = policyValueObject.toString(); ret.getPolicy().put(policyName, policyValueString); //System.out.println(policyName + ":" + policyValueString); } //System.out.println(""); ret.setStatus(RazorDeviceStatus.PROVISIONED); } List tagslist = (List) node.get("tags"); if (tagslist != null && tagslist.size() > 0) { for (Object aTagslist : tagslist) { Map tags = (Map) aTagslist; if (tags != null && tags.size() > 0) { //System.out.println("Tag..."); for (Object key : tags.keySet()) { String tagName = (String) key; Object tagValueObject = tags.get(tagName); String tagValueString = tagValueObject.toString(); ret.getTags().put(tagName, tagValueString); //System.out.println(tagName + ":" + tagValueString); } //System.out.println(""); } } } Map facts = (Map) node.get(NODE_FACTS_KEY); if (facts == null) { LOGGER.warn("No facts found for node uuid " + ret.getId()); } else { for (Object key : facts.keySet()) { String factName = (String) key; Object factValueObject = facts.get(factName); // Fact values are generally strings, but can be other raw types like integers, // e.g. for physicalprocessorcount String factValue = factValueObject.toString(); ret.getFacts().put(factName, factValue); switch (factName) { case FACT_IPADDRESS_KEY: ret.setIpAddress(factValue); break; case FACT_MACADDRESS_KEY: ret.setMacAddress(factValue); break; case FACT_MANUFACTURER_KEY: ret.setManufacturer(factValue); break; } } } return ret; }
From source file:de.hofuniversity.iisys.neo4j.websock.util.JsonConverter.java
@SuppressWarnings("unchecked") private static JSONObject convertFromMap(final Map<String, ?> map) throws JSONException { final JSONObject json = new JSONObject(map.size()); Object o = null;/*from w w w .j ava 2 s . c o m*/ for (Entry<String, ?> mapE : map.entrySet()) { o = mapE.getValue(); if (o instanceof Map) { if (o instanceof JSONMap) { o = ((JSONMap) o).getJson(); } else { o = convertFromMap((Map<String, ?>) o); } } else if (o instanceof List) { if (o instanceof JSONList) { o = ((JSONList) o).getJson(); } else { o = convertFromList((List<?>) o); } } json.put(mapE.getKey(), o); } return json; }
From source file:io.apiman.cli.util.DeclarativeUtil.java
/** * Parses the {@link Declaration} from the {@code fileContents}, using the specified {@code properties}. * * @param mapper the Mapper to use//from www. j a va 2s .co m * @param unresolved the contents of the file * @param properties the property placeholders * @return the Declaration * @throws IOException */ private static Declaration loadDeclaration(ObjectMapper mapper, String unresolved, Map<String, String> properties) throws IOException { final String resolved = BeanUtil.resolvePlaceholders(unresolved, properties); LOGGER.trace("Declaration file after resolving {} placeholders: {}", properties.size(), resolved); return mapper.readValue(resolved, Declaration.class); }
From source file:com.glaf.activiti.util.ExecutionUtils.java
@SuppressWarnings("unchecked") public static void executeSqlUpdate(DelegateExecution execution, Expression sql) { CommandContext commandContext = Context.getCommandContext(); ExecutionEntity executionEntity = commandContext.getExecutionEntityManager() .findExecutionById(execution.getId()); String processDefinitionId = executionEntity.getProcessDefinitionId(); ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); String processName = processDefinitionEntity.getKey(); Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> variables = execution.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (params.get(variableName) == null) { Object value = execution.getVariable(variableName); params.put(variableName, value); }/*from w w w. jav a2s .c o m*/ } } params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey()); params.put("processInstanceId", execution.getProcessInstanceId()); params.put("processDefinitionId", processDefinitionEntity.getId()); params.put("processName", processName); params.put("now", new java.util.Date()); if (sql != null) { String sqlx = sql.getExpressionText(); if (sqlx.indexOf("#{tableName}") != -1) { String tableName = (String) execution.getVariable("tableName"); if (StringUtils.isNotEmpty(tableName)) { sqlx = StringTools.replace(sqlx, "#{tableName}", tableName); } } else if (sqlx.indexOf("${tableName}") != -1) { String tableName = (String) execution.getVariable("tableName"); if (StringUtils.isNotEmpty(tableName)) { sqlx = StringTools.replace(sqlx, "${tableName}", tableName); } } sqlx = StringTools.replaceIgnoreCase(sqlx, "${", "#{"); List<Object> values = new java.util.ArrayList<Object>(); SqlExecutor sqlExecutor = JdbcUtils.rebuildSQL(sqlx, params); sqlx = sqlExecutor.getSql(); if (sqlExecutor.getParameter() != null) { if (sqlExecutor.getParameter() instanceof List) { List<Object> list = (List<Object>) sqlExecutor.getParameter(); values.addAll(list); } } logger.debug(sqlx); logger.debug(values); Connection con = null; try { con = commandContext.getDbSqlSession().getSqlSession().getConnection(); PreparedStatement psmt = con.prepareStatement(sqlx); JdbcUtils.fillStatement(psmt, values); psmt.executeUpdate(); psmt.close(); psmt = null; } catch (SQLException ex) { throw new RuntimeException(ex); } } }
From source file:IdentityMap.java
public static Map invert(Map map) { Map result = instantiate(map.size()); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry) iter.next(); result.put(me.getValue(), me.getKey()); }/* w w w. ja va 2s. c om*/ return result; }