List of usage examples for java.util HashMap size
int size
To view the source code for java.util HashMap size.
Click Source Link
From source file:gov.llnl.lc.smt.command.route.SmtRoute.java
public static String getSwitchSummary(OpenSmMonitorService oms, RT_Table table) { StringBuffer buff = new StringBuffer(); if ((oms != null) && (table != null)) { HashMap<String, RT_Node> NodeRouteMap = table.getSwitchGuidMap(); if (NodeRouteMap != null) { buff.append("(" + NodeRouteMap.size() + ") Switches with routing tables [total routes=" + table.getNumRoutes() + "]" + SmtConstants.NEW_LINE); for (Map.Entry<String, RT_Node> entry : NodeRouteMap.entrySet()) { RT_Node rn = entry.getValue(); buff.append(SmtRoute.getNodeHeader(" ", rn, table, oms.getFabric())); }//from ww w . j a v a 2 s .c o m } } else System.err.println("Unable to show routing table for null objects"); return buff.toString(); }
From source file:integratedtoolkit.util.OptimisComponents.java
public static HashMap<String, Object[]>[] getVMs() throws XmlException { System.out.println("GETTING VMs"); HashMap<String, Object[]>[] vmlist = new HashMap[3]; for (int i = 0; i < 3; i++) { vmlist[i] = new HashMap<String, Object[]>(); }// ww w. j a va 2 s . c o m try { LinkedList<InfrastructureProvider> ips = serviceManager.getProvidersData(serviceId); for (InfrastructureProvider ip : ips) { String ipName = ip.getId(); String ipv4 = ip.getIpAddress(); System.out.println("\t " + ipName + "-" + ipv4); Vm[] vms = ip.getVms().getVmArray(); for (Vm vm : vms) { String IPv4 = vm.getId(); System.out.println("\t\t " + IPv4); MachineStatus currentStatus; if (vm.getStatus().toUpperCase().compareTo("READY") == 0) { currentStatus = MachineStatus.READY; } else if (vm.getStatus().toUpperCase().compareTo("TOBESAVED") == 0) { currentStatus = MachineStatus.TOBESAVED; } else if (vm.getStatus().toUpperCase().compareTo("SAVED") == 0) { currentStatus = MachineStatus.SAVED; } else { currentStatus = MachineStatus.NOT_DEFINED; } Instance instance = instances.get(IPv4); if (instance == null) { System.out.println("\t\t\tInstance seen for the first time"); String instanceName = vm.getType(); instance = createInstance(IPv4, instanceName, ipName, ipv4); instances.put(IPv4, instance); } MachineStatus oldStatus = instance.status; if (currentStatus == MachineStatus.READY) { if (oldStatus == null) { System.out.println("\t\t\tUnused VM. Starting..."); //New VM detected boolean available = true; if (instance.component == null) { //Machine out of the service system instance.status = MachineStatus.READY; } else { HashMap<String, LocationProperties> properties = instance.component.locations; if (properties != null) { System.out.println("\t\t\tComponent has " + properties.size() + " locations"); System.out.println("\t\t\t Locations:"); for (java.util.Map.Entry<String, LocationProperties> e : properties .entrySet()) { String location = e.getKey(); LocationProperties prop = e.getValue(); String user = prop.user; int slots = prop.slots; if (slots > 0) { //if its not a master String resourceName = getResourceName(IPv4, location); System.out.println("\t\t\t *" + resourceName); Resource resource = instance.resources.get(resourceName); if (resource == null) { if (connectionAvailable(resourceName, user)) { resource = new Resource(resourceName); resource.instance = instance; resources.put(resourceName, resource); instance.resources.put(resourceName, resource); } else { available = false; } } //else It was already available } // else it's a useless resource. No need to do anything } System.out.println("\t\t\t End resources analysis:"); long deploymentTime = System.currentTimeMillis() - instance.firstSeenTimestamp; String timeString = ""; try { String xml = vm.toString(); int init = xml.indexOf("<ser:deployment_duration_in_ms>") + 31; int end = xml.indexOf("</ser:deployment_duration_in_ms>"); timeString = xml.substring(init, end); } catch (Exception ex) { } deploymentTime = deploymentTime + Long.parseLong(timeString); deploymentTime += 20000l; if (available) { System.out.println("\t\t\tis Available"); instance.status = MachineStatus.READY; instance.deploymentTime = deploymentTime; for (java.util.Map.Entry<String, LocationProperties> entry : instance.component.locations .entrySet()) { String resourceName = getResourceName(IPv4, entry.getKey()); vmlist[MANDATORY].put(resourceName, entry.getValue().getArray()); System.out.println("Added as a Mandatory VM to the VM list"); } } else { System.out.println("\t\t\thas not been available for " + deploymentTime); if ((deploymentTime - Long.parseLong(timeString)) > 300000) { destroyInstance(instance); System.out.println("VM is not accessible. Should restart it"); } } } } } } else if (currentStatus == MachineStatus.TOBESAVED) { if (oldStatus == null) { destroyInstance(instance); } else if (oldStatus == MachineStatus.READY) { instance.status = MachineStatus.TOBESAVED; for (String resourceName : instance.resources.keySet()) { vmlist[TERMINATE].put(resourceName, null); } } } } } } catch (Exception e) { e.printStackTrace(); } return vmlist; }
From source file:com.flipkart.fdp.migration.distcp.core.MirrorDistCPDriver.java
@SuppressWarnings("static-access") public static DCMConfig getParams(String[] args) throws Exception { Options options = new Options(); options.addOption("p", true, "properties filename from the classpath"); options.addOption("P", true, "external properties filename"); options.addOption("D", true, "JVM and Hadoop Configuration Override"); options.addOption("V", true, "Custom runtime config variables"); options.addOption("J", true, "properties as JSON String"); options.addOption("libjars", true, "JVM and Hadoop Configuration Override"); options.addOption(OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("D")); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String path = null;/*from w w w . ja va 2 s . co m*/ if (cmd.hasOption('p')) { path = cmd.getOptionValue('p'); } else if (cmd.hasOption('P')) { path = cmd.getOptionValue('P'); } HashMap<String, String> varMap = new HashMap<String, String>(); if (cmd.hasOption('V')) { String runtimeVars[] = cmd.getOptionValues('V'); for (String var : runtimeVars) { String kv[] = var.split("="); varMap.put("#" + kv[0], kv[1]); } } if (cmd.hasOption('J')) { String configString = cmd.getOptionValue('J'); Gson gson = new Gson(); return gson.fromJson(configString, DCMConfig.class); } if (path == null || !new File(path).exists()) { throw new Exception("Unable to load Config File..."); } String configString = MirrorUtils.getFileAsString(path); if (varMap.size() > 0) { for (Entry<String, String> kv : varMap.entrySet()) { System.out.println("Custom Config Replacer: " + kv.getKey() + ", with: " + kv.getValue()); configString = configString.replace(kv.getKey(), kv.getValue()); } } Gson gson = new Gson(); return gson.fromJson(configString, DCMConfig.class); }
From source file:com.vmware.qe.framework.datadriven.utils.XMLUtil.java
/** * Finds all the children node and put it in HashMap<String,Node> where it represents tagName * and Node For example to get all the children of tag <parent> from the following xml node : * <parent> <one> something </one> <two> something </two> <three> something </three> </parent> * you pass <parent> node and it returns {{("one",<one>) ("two",<two>) ("three",<three>)} * //from ww w . j a v a 2 s.co m * @param parentNode : parentNode to lookup into for tags * @return HashMap of <NodeName,Node> that is found based on tags given in tags arrayList */ public static HashMap<String, Node> getChildrenByTagNames(Node parentNode) { HashMap<String, Node> resultList = new HashMap<String, Node>(); Node child = null; if (parentNode != null) { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { resultList.put(child.getNodeName(), child); } } } return resultList.size() == 0 ? null : resultList; }
From source file:edu.ehu.galan.wiki2wordnet.wikipedia2wordnet.Mapper.java
private static void disambiguateUKB(HashMap<String, List<Wiki2WordnetMapping>> pUkbList, List<String> pDesambContext, String pFile, IDictionary pWordnet, HashMap<String, Integer> pMappings, String pUkbBinDir) {//from w ww .j ava 2 s .c o m logger.debug("Desambiguating Wornet synsets via UKB method"); HashMap<String, List<String>> toDisam = new HashMap<>(); logger.debug("Finding gold topics for disambiguation..."); Function<String, String> contextSynsets = (String t) -> pWordnet .getSynset(new SynsetID(pMappings.get(t), POS.NOUN)).getWords().get(0).getLemma(); List<String> context = pDesambContext.stream().map(contextSynsets).collect(toList()); for (String topics21 : pUkbList.keySet()) { toDisam.put(pWordnet.getSynset(new SynsetID(pMappings.get(topics21), POS.NOUN)).getWords().get(0) .getLemma().toLowerCase(), context); } UKBUtils.prepareInput(toDisam, pFile); HashMap<String, Integer> synsets = UKBUtils.processUKB(pUkbBinDir, pFile); if (toDisam.size() == synsets.size()) { for (String topics21 : pUkbList.keySet()) { Integer inte = synsets.get(pWordnet.getSynset(new SynsetID(pMappings.get(topics21), POS.NOUN)) .getWords().get(0).getLemma().toLowerCase()); pMappings.put(topics21, inte); } logger.debug("UKB disambiguation using WordNet finished"); } else { logger.error("The number of topics to disambiguate via ukb must be the same than the ouput size"); } }
From source file:edu.utexas.cs.bevomaps.DataLayer.java
/** * Helper method to parse the JSON and insert into HashMaps * * @param buildingJSON subclass of ParseObject, stores building data in JSON format * @return This will return the HashMap of HashMaps or null if there is a problem *///from www . j a v a2 s . c o m private static HashMap<String, HashMap<String, String>> extractImageMap(BuildingJSON buildingJSON) { HashMap<String, HashMap<String, String>> imageMaps = new HashMap<>(); JSONObject json = buildingJSON.getBuildingJSON(); Iterator<String> iter = json.keys(); while (iter.hasNext()) { String building = iter.next(); JSONObject buildingInfo; try { buildingInfo = json.getJSONObject(building); HashMap<String, String> buildingInfoMap = new HashMap<>(); Iterator<String> innerIter = buildingInfo.keys(); while (innerIter.hasNext()) { String key = innerIter.next(); buildingInfoMap.put(key, buildingInfo.getString(key)); } imageMaps.put(building, buildingInfoMap); } catch (JSONException jsonException) { Log.e(TAG, jsonException.toString()); } } if (imageMaps.size() > 0) { return imageMaps; } else return null; }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
public static HashMap<String, Double> GetSourceSubstringMax(HashMap<Pair<String, String>, Double> counts) { HashMap<String, Double> result = new HashMap<>(counts.size()); for (Pair<String, String> key : counts.keySet()) { Double value = counts.get(key); if (result.containsKey(key.getFirst())) result.put(key.getFirst(), Math.max(value, result.get(key.getFirst()))); else/*from w w w . ja va 2s.c om*/ result.put(key.getFirst(), value); } return result; }
From source file:de.document.controller.SearchController.java
@RequestMapping(value = "/{word}", method = { RequestMethod.GET }) public HashMap search(@PathVariable("word") String word) throws IOException, ParseException { HashMap entity = this.service.searchText(word); System.out.println(entity.size()); return entity; }
From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java
public static HashMap<String, Integer> getFeatureOffsetIndex(FeatureStore instanceList) { HashMap<String, Integer> featureOffsetIndex = new HashMap<String, Integer>(); for (int i = 0; i < instanceList.getNumberOfInstances(); i++) { Instance instance = instanceList.getInstance(i); for (Feature feature : instance.getFeatures()) { String featureName = feature.getName(); if (!featureOffsetIndex.containsKey(featureName)) { featureOffsetIndex.put(featureName, featureOffsetIndex.size()); }//from w ww . ja va2s. c o m } } return featureOffsetIndex; }
From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java
public static void writeFeatureNamesToFile(FeatureStore instanceList, File outputFile) throws IOException { BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile)), "UTF-8")); HashMap<String, Integer> featureOffsetIndex = new HashMap<String, Integer>(); for (int i = 0; i < instanceList.getNumberOfInstances(); i++) { Instance instance = instanceList.getInstance(i); for (Feature feature : instance.getFeatures()) { String featureName = feature.getName(); if (!featureOffsetIndex.containsKey(featureName)) { featureOffsetIndex.put(featureName, featureOffsetIndex.size()); bw.write(featureName + " "); }//w w w. j a v a2s. co m } } bw.write(MalletTestTask.OUTCOME_CLASS_LABEL_NAME); bw.close(); }