List of usage examples for java.util LinkedHashMap size
int size();
From source file:com.alibaba.wasp.meta.TestFMetaStore.java
public static void compare(LinkedHashMap<String, Field> left, LinkedHashMap<String, Field> right) { if (compareNull(left, right)) { assertTrue(false);/*from w w w . j a v a2 s. c o m*/ return; } if (left != null && right != null) { assertTrue(left.size() == right.size()); Iterator<Entry<String, Field>> leftIter = left.entrySet().iterator(); Iterator<Entry<String, Field>> rightIter = right.entrySet().iterator(); while (leftIter.hasNext()) { Field leftField = leftIter.next().getValue(); Field rightField = rightIter.next().getValue(); compare(rightField, leftField); } } }
From source file:gov.llnl.lc.smt.command.node.SmtNode.java
public static String getNodeSummary(OpenSmMonitorService oms, IB_Guid g) { String formatString = "%12s: %s"; StringBuffer buff = new StringBuffer(); if ((oms != null) && (g != null)) { OSM_Fabric fabric = oms.getFabric(); if (fabric != null) { OSM_Node n = fabric.getOSM_Node(g); boolean mgr = fabric.isManagementNode(n); String mString = mgr/*from w w w . ja va 2 s . co m*/ ? Console.getTextColorString(ConsoleColor.red) + " (Subnet Manager)" + Console.getTextNormalString() : ""; if (n != null) { int num_ports = n.sbnNode.num_ports; boolean isSwitch = OSM_Fabric.isSwitch(g, fabric); LinkedHashMap<String, IB_Link> links = fabric.getIB_Links(g); int num_links = links.size(); int num_down = num_ports - num_links; int lid = fabric.getLidFromGuid(g); buff.append( String.format(formatString, "Node name", n.pfmNode.node_name + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "description", n.sbnNode.description + mString + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "guid", g.toColonString() + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "lid", lid + " (" + IB_Address.toLidHexString(lid) + ")" + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "type", OSM_NodeType.get(n).getFullName() + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "active", n.pfmNode.active + SmtConstants.NEW_LINE)); if (isSwitch) buff.append(String.format(formatString, "esp0", n.pfmNode.esp0 + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "total ports", n.sbnNode.num_ports + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "active ports", num_links + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "down ports", num_down + SmtConstants.NEW_LINE)); if (isSwitch) { LinkedHashMap<String, IB_Vertex> vertexMap = IB_Vertex.createVertexMap(fabric); IB_Vertex v = IB_Vertex.getVertex(IB_Vertex.getVertexKey(g), vertexMap); int ul = v.getUpLinkNumbers().size(); int dl = v.getDownLinkNumbers().size(); buff.append(String.format(formatString, "up links", ul + SmtConstants.NEW_LINE)); buff.append(String.format(formatString, "down links", dl + SmtConstants.NEW_LINE)); } } } } return buff.toString(); }
From source file:com.vmware.bdd.cli.commands.CommandsUtils.java
public static void printInTableFormat(LinkedHashMap<String, List<String>> columnNamesWithKeys, List<Map> entities, String spacesBeforeStart) throws Exception { if (MapUtils.isNotEmpty(columnNamesWithKeys)) { int columnNum = columnNamesWithKeys.size(); if (CollectionUtils.isNotEmpty(entities)) { String[][] table = new String[entities.size() + 1][columnNum]; //build table header: column names String[] tableHeader = table[0]; int rowIndex = 1; int columnIndex = 0; for (Map<String, String> entity : entities) { for (Entry<String, List<String>> columnNameEntry : columnNamesWithKeys.entrySet()) { if (tableHeader[columnIndex] == null) { tableHeader[columnIndex] = columnNameEntry.getKey(); }//from www . j a va2 s.co m StringBuilder value = new StringBuilder(); for (String key : columnNameEntry.getValue()) { if (value.length() > 0) { value.append(','); } Object valueObj = entity.get(key); if (valueObj == null) { value.append(' '); } else { if (valueObj instanceof Double) { value.append(String.valueOf( round(((Double) valueObj).doubleValue(), 2, BigDecimal.ROUND_FLOOR))); } else { value.append(valueObj); } } } if (isJansiAvailable()) { table[rowIndex][columnIndex] = transferEncoding(value.toString()); } else { table[rowIndex][columnIndex] = value.toString(); } columnIndex++; } rowIndex++; } printTable(table, spacesBeforeStart); } } }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
public static LinkedHashMap<String, ChartData> getSortedAndLimitedChartDataMap( LinkedHashMap<String, ChartData> map, Integer limit, String limitLabel) { //test if we need to trim if (limit <= 0 || limit >= map.size()) { return map; }/* w ww.j a va 2 s. c om*/ //sort by value Map<String, ChartData> sortedMap = ControllerUtils.getSortedByChartDataMap(map); //limit and combine results Map<String, ChartData> sortedLimitedMap = ControllerUtils.getLimitedChartDataMap(sortedMap, limit, limitLabel); //put the original sort order back (minus the values combined) LinkedHashMap<String, ChartData> originalSortResultMap = new LinkedHashMap<String, ChartData>(limit); LinkedHashMap<String, ChartData> passedValuesMap = new LinkedHashMap<String, ChartData>(map.size()); int i = 0; for (String key : map.keySet()) { if (i < limit) { if (sortedLimitedMap.containsKey(key)) { ChartData value = sortedLimitedMap.get(key); //if value is not null/zero, add it and increment if (value != null && value.getCount() != null && !Double.isNaN(value.getCount()) && value.getCount() > 0) { originalSortResultMap.put(key, value); i++; } else { //put it in a list of passed up values for inclusion at the end passedValuesMap.put(key, value); } } } } //if we still have room after adding all sorted non zero values... fill the rest with passed values if (i < limit) { for (String key : passedValuesMap.keySet()) { if (i < limit) { originalSortResultMap.put(key, passedValuesMap.get(key)); i++; } } } //add combined field if it is not null (indicates it was used even if the value is 0) ChartData cVal = sortedLimitedMap.get(limitLabel); if (cVal != null && cVal.getCount() != null && !Double.isNaN(cVal.getCount())) { originalSortResultMap.put(limitLabel, cVal); } return originalSortResultMap; }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
/** * Returns a new map that is sorted and then limited to the top {@code limit} values. It then places the map back * in the original sort order minus anything that has been cut. */// w w w . j a v a2 s . co m public static LinkedHashMap<String, Double> getSortedAndLimitedMap(LinkedHashMap<String, Double> map, Integer limit, String limitLabel) { //test if we need to trim if (limit <= 0 || limit >= map.size()) { return map; } //sort by value Map<String, Double> sortedMap = ControllerUtils.getSortedByValueMap(map); //limit and combine results Map<String, Double> sortedLimitedMap = ControllerUtils.getLimitedMap(sortedMap, limit, limitLabel); //put the original sort order back (minus the values combined) LinkedHashMap<String, Double> originalSortResultMap = new LinkedHashMap<String, Double>(limit); LinkedHashMap<String, Double> passedValuesMap = new LinkedHashMap<String, Double>(map.size()); int i = 0; for (String key : map.keySet()) { if (i < limit) { if (sortedLimitedMap.containsKey(key)) { Double value = sortedLimitedMap.get(key); //if value is not null/zero, add it and increment if (value != null && !Double.isNaN(value) && value > 0) { originalSortResultMap.put(key, value); i++; } else { //put it in a list of passed up values for inclusion at the end passedValuesMap.put(key, value); } } } } //if we still have room after adding all sorted non zero values... fill the rest with passed values if (i < limit) { for (String key : passedValuesMap.keySet()) { if (i < limit) { originalSortResultMap.put(key, passedValuesMap.get(key)); i++; } } } //add combined field if it is not null (indicates it was used even if the value is 0) Double cVal = sortedLimitedMap.get(limitLabel); if (cVal != null && !Double.isNaN(cVal)) { originalSortResultMap.put(limitLabel, cVal); } return originalSortResultMap; }
From source file:com.vmware.bdd.cli.commands.CommandsUtils.java
/** * Show a table(include table column names and table contents) by left * justifying. More specifically, the {@code columnNamesWithGetMethodNames} * argument is a map struct, the key is table column name and value is method * name list which it will be invoked by reflection. The {@code entities} * argument is traversed entity array.It is source of table data. In * addition,the method name must be each of the {@code entities} argument 's * member. The {@code spacesBeforeStart} argument is whitespace in the front * of the row.//from w w w .j av a 2s . c o m * <p> * * @param columnNamesWithGetMethodNames * the container of table column name and invoked method name. * @param entities * the traversed entity array. * @param spacesBeforeStart * the whitespace in the front of the row. * @throws Exception */ public static void printInTableFormat(LinkedHashMap<String, List<String>> columnNamesWithGetMethodNames, Object[] entities, String spacesBeforeStart) throws Exception { if (entities != null && entities.length > 0) { // get number of columns int columnNum = columnNamesWithGetMethodNames.size(); String[][] table = new String[entities.length + 1][columnNum]; //build table header: column names String[] tableHeader = new String[columnNum]; Set<String> columnNames = columnNamesWithGetMethodNames.keySet(); columnNames.toArray(tableHeader); //put table column names into the first row table[0] = tableHeader; //build table contents Collection<List<String>> getMethodNamesCollect = columnNamesWithGetMethodNames.values(); int i = 1; for (Object entity : entities) { int j = 0; for (List<String> getMethodNames : getMethodNamesCollect) { Object tempValue = null; int k = 0; for (String methodName : getMethodNames) { if (tempValue == null) tempValue = entity; Object value = tempValue.getClass().getMethod(methodName).invoke(tempValue); if (k == getMethodNames.size() - 1) { table[i][j] = value == null ? "" : ((value instanceof Double) ? String.valueOf( round(((Double) value).doubleValue(), 2, BigDecimal.ROUND_FLOOR)) : value.toString()); if (isJansiAvailable() && !isBlank(table[i][j])) { table[i][j] = transferEncoding(table[i][j]); } j++; } else { tempValue = value; k++; } } } i++; } printTable(table, spacesBeforeStart); } }
From source file:gov.llnl.lc.smt.command.route.SmtRoute.java
public static String getPortSummaryString(RT_Node node, RT_Table table, OSM_Fabric fabric) { // report number of ports with routes, and then each port summary StringBuffer buff = new StringBuffer(); LinkedHashMap<String, RT_Port> PortRouteMap = RT_Node.sortPortRouteTable(node.getPortRouteMap(), true); buff.append(//from w w w. j a va2 s . c o m "(" + PortRouteMap.size() + ") Ports with routes [total routes=" + node.getNumRoutes() + "]\n"); if (PortRouteMap != null) { for (Map.Entry<String, RT_Port> entry : PortRouteMap.entrySet()) { RT_Port rp = entry.getValue(); int portNum = rp.getPortNumber(); IB_Guid g = node.getGuid(); buff.append(getPortRouteLine(fabric, table, g, portNum)); } } return buff.toString(); }
From source file:gov.llnl.lc.smt.command.node.SmtNode.java
public static String getDownPortSummary(OSM_FabricDelta fabricDelta, OSM_Node n, LinkedHashMap<String, IB_Link> links) { OSM_FabricDeltaAnalyzer fda = new OSM_FabricDeltaAnalyzer(fabricDelta); OSM_Fabric fabric = fabricDelta.getFabric2(); StringBuffer buff = new StringBuffer(); int num_ports = n.sbnNode.num_ports; int num_links = links.size(); int num_down = num_ports - num_links; if (num_down > 0) { buff.append("(" + num_down + ") Down ports" + SmtConstants.NEW_LINE); // loop through the nodes port numbers, and print out the downed ports for (int pn = 0; pn < n.sbnNode.num_ports; pn++) { String pKey = OSM_Fabric.getOSM_PortKey(n.getNodeGuid().getGuid(), (short) (pn + 1)); OSM_Port p = fabric.getOSM_Port(pKey); String errStr = fda.getPortErrorState(n.getNodeGuid(), pn + 1); IB_Link l = null;//from www .j av a 2s . c om boolean down = true; // is this one of the active links? If not, count it as down for (Map.Entry<String, IB_Link> entry : links.entrySet()) { l = entry.getValue(); if (l.contains(p)) { // not one of the down ones down = false; break; } } if (down) buff.append(SmtNode.getDownPortLine(p, l, errStr) + SmtConstants.NEW_LINE); } } return buff.toString(); }
From source file:com.servioticy.datamodel.serviceobject.SOStream.java
@JsonSetter("channels") public void setNotNullOrEmptyChannels(LinkedHashMap<String, SOChannel> channels) throws JsonMappingException { if (channels == null || channels.size() < 1) { throw new JsonMappingException("At least one channel is required"); }//from w w w . ja v a 2 s .c o m setChannels(channels); }
From source file:gov.llnl.lc.smt.command.node.SmtNode.java
public static String getActivePortSummary(OSM_FabricDelta fabricDelta, OSM_Node n, LinkedHashMap<String, IB_Link> links) { OSM_FabricDeltaAnalyzer fda = new OSM_FabricDeltaAnalyzer(fabricDelta); OSM_Fabric fabric = fabricDelta.getFabric2(); StringBuffer buff = new StringBuffer(); LinkedHashMap<String, IB_Vertex> vertexMap = IB_Vertex.createVertexMap(fabric); IB_Vertex v = IB_Vertex.getVertex(IB_Vertex.getVertexKey(n.getNodeGuid()), vertexMap); int num_links = links.size(); buff.append("(" + num_links + ") Active ports" + SmtConstants.NEW_LINE); // loop through the nodes port numbers, and print out the active ports for (int pn = 0; pn < n.sbnNode.num_ports; pn++) { String pKey = OSM_Fabric.getOSM_PortKey(n.getNodeGuid().getGuid(), (short) (pn + 1)); OSM_Port p = fabric.getOSM_Port(pKey); String errStr = fda.getPortErrorState(n.getNodeGuid(), pn + 1); // if the error string is blank, provide the up/down direction of the port if ((errStr == null) || (errStr.length() < 1)) errStr = v.getPortDirection(pn + 1) + " link"; // is this one of the active links? If so, display it for (Map.Entry<String, IB_Link> entry : links.entrySet()) { IB_Link l = entry.getValue(); if (l.contains(p)) { // not one of the down ones buff.append(SmtNode.getLinkLine(p, l, fabric, String.format(portFormatString, p.getPortNumber(), errStr)) + SmtConstants.NEW_LINE); break; }/* w ww .j a v a 2 s .com*/ } } return buff.toString(); }