Example usage for java.util HashMap entrySet

List of usage examples for java.util HashMap entrySet

Introduction

In this page you can find the example usage for java.util HashMap entrySet.

Prototype

Set entrySet

To view the source code for java.util HashMap entrySet.

Click Source Link

Document

Holds cached entrySet().

Usage

From source file:com.pari.nm.utils.backup.BackupRestore.java

private static void validateCSPCInstanace() {
    // Get the NCCM Server IP Address
    String NCCMIPAdress = null;/*w  ww  .  j  a v  a 2 s .  c om*/
    ServerStatus serverStatus = ServerStatusFactory.getInstance().getStatus();
    HashMap ips = serverStatus.getIps();
    if (ips != null) {
        Iterator it = ips.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry ip = (Map.Entry) it.next();
            if (ip.getValue() != null && !ip.getValue().equals("")) {
                NCCMIPAdress = String.valueOf(ip.getValue());
                break;
            }
        }
    }
    if (NCCMIPAdress != null) {
        // Get the CSPC instance detail from DB
        List<CspcInfo> cspcInfoList = CspcDBHelper.getCspcInfoList();
        for (CspcInfo cspcInfoObj : cspcInfoList) {
            // If both the IP Address are different update the Cspc Info with the latest NCCM Server IP Address.
            if (!NCCMIPAdress.equals(cspcInfoObj.getNccmIp())) {
                cspcInfoObj.setNccmIp(NCCMIPAdress);
                try {
                    System.out.println(
                            "NCCM IP Address present in cspc_customer_wing_instance table is different from currect NCCM IP Address");
                    CspcDBHelper.updateCspcInfo(cspcInfoObj);
                } catch (Exception e) {
                    System.out.println(
                            "Failed to update the NCCM IP Address in cspc_customer_wing_instance table");
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:com.eternitywall.ots.OtsCli.java

public static void verify(String argsOts, Hash hash, String argsFile) {
    try {//from  ww  w .ja v  a2  s.  c  o m
        Path pathOts = Paths.get(argsOts);
        byte[] byteOts = Files.readAllBytes(pathOts);
        DetachedTimestampFile detachedOts = DetachedTimestampFile.deserialize(byteOts);
        DetachedTimestampFile detached;
        HashMap<VerifyResult.Chains, VerifyResult> verifyResults;

        if (shasum == null) {
            // Read from file
            File file = new File(argsFile);
            System.out.println("Assuming target filename is '" + argsFile + "'");
            detached = DetachedTimestampFile.from(new OpSHA256(), file);
        } else {
            // Read from hash option
            System.out.println("Assuming target hash is '" + Utils.bytesToHex(hash.getValue()) + "'");
            detached = DetachedTimestampFile.from(hash);
        }

        try {
            verifyResults = OpenTimestamps.verify(detachedOts, detached);

            for (Map.Entry<VerifyResult.Chains, VerifyResult> entry : verifyResults.entrySet()) {
                String chain = "";

                if (entry.getKey() == VerifyResult.Chains.BITCOIN) {
                    chain = BitcoinBlockHeaderAttestation.chain;
                } else if (entry.getKey() == VerifyResult.Chains.LITECOIN) {
                    chain = LitecoinBlockHeaderAttestation.chain;
                } else if (entry.getKey() == VerifyResult.Chains.ETHEREUM) {
                    chain = EthereumBlockHeaderAttestation.chain;
                }

                System.out.println(
                        "Success! " + Utils.toUpperFirstLetter(chain) + " " + entry.getValue().toString());
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());

            return;
        }
    } catch (Exception e) {
        log.severe("No valid file");
    }
}

From source file:eu.geopaparazzi.library.network.NetworkUtilities.java

/**
 * Sends a {@link MultipartEntity} post with text and image files.
 * /* w  w w  .  j  a va  2  s  . c  o  m*/
 * @param url the url to which to POST to.
 * @param user the user or <code>null</code>.
 * @param pwd the password or <code>null</code>.
 * @param stringsMap the {@link HashMap} containing the key and string pairs to send.
 * @param filesMap the {@link HashMap} containing the key and image file paths 
 *                  (jpg, png supported) pairs to send.
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws ClientProtocolException
 */
public static void sentMultiPartPost(String url, String user, String pwd, HashMap<String, String> stringsMap,
        HashMap<String, File> filesMap)
        throws UnsupportedEncodingException, IOException, ClientProtocolException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(url);

    if (user != null && pwd != null) {
        String ret = getB64Auth(user, pwd);
        httppost.setHeader("Authorization", ret);
    }

    MultipartEntity mpEntity = new MultipartEntity();
    Set<Entry<String, String>> stringsEntrySet = stringsMap.entrySet();
    for (Entry<String, String> stringEntry : stringsEntrySet) {
        ContentBody cbProperties = new StringBody(stringEntry.getValue());
        mpEntity.addPart(stringEntry.getKey(), cbProperties);
    }

    Set<Entry<String, File>> filesEntrySet = filesMap.entrySet();
    for (Entry<String, File> filesEntry : filesEntrySet) {
        String propName = filesEntry.getKey();
        File file = filesEntry.getValue();
        if (file.exists()) {
            String ext = file.getName().toLowerCase().endsWith("jpg") ? "jpeg" : "png";
            ContentBody cbFile = new FileBody(file, "image/" + ext);
            mpEntity.addPart(propName, cbFile);
        }
    }

    httppost.setEntity(mpEntity);
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    if (resEntity != null) {
        resEntity.consumeContent();
    }

    httpclient.getConnectionManager().shutdown();
}

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 w w  w .  j  ava  2 s .  co m
        }
    } else
        System.err.println("Unable to show routing table for null objects");

    return buff.toString();
}

From source file:edu.ehu.galan.lite.model.Document.java

/**
 * Return a Json string with the results of the document using GSon library
 *
 * @param pDoc//from ww  w . j av  a2  s .co  m
 * @return String - the String containing the Json
 */
public static String getJsonResults(Document pDoc) {
    Doc msg = new Doc();
    msg.setName(pDoc.name);
    msg.setKnowledgeSource(pDoc.getSource().toString());
    List<MsgTop> list = new ArrayList<>();
    for (Topic string : pDoc.topicList) {
        MsgTop top = new MsgTop();
        top.setSourceTitle(string.getSourceTitle());
        top.setDefinition(string.getSourceDef());
        top.setId(string.getId());
        top.setTopic(string.getTopic());
        top.setLabels(string.getLabelList());
        top.setDomainRelatedness(string.getDomainRelatedness());
        List<Translation> transList = new ArrayList<>();
        HashMap<String, String> map = string.getTranslations();
        Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> pairs = it.next();
            Translation trans = new Translation();
            trans.setLang(pairs.getKey());
            trans.setText(pairs.getValue());
            transList.add(trans);
        }
        top.setTranslations(transList);
        List<Parent> parentList = new ArrayList<>();
        HashMap<Integer, String> map2 = string.getParentCategories();
        Iterator<Map.Entry<Integer, String>> itr = map2.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry<Integer, String> pairs = itr.next();
            Parent trans = new Parent();
            trans.setId(pairs.getKey());
            trans.setSourceTitle(pairs.getValue());
            parentList.add(trans);
        }
        top.setParentCategories(parentList);
        list.add(top);
    }
    msg.setTopics(list);
    msg.setTopics(list);
    List<DomainRel> listRel = new ArrayList<>();
    for (Map.Entry<Integer, String> pair : pDoc.domainTopics.entrySet()) {
        DomainRel rel = new DomainRel();
        rel.setId(pair.getKey());
        rel.setTitle(pair.getValue());
        listRel.add(rel);
    }
    msg.setDomainTopics(listRel);
    Gson son = new GsonBuilder().setPrettyPrinting().create();
    return (son.toJson(msg));

}

From source file:anslab2.AnsLab2.java

public static DefaultTableModel generateTable(boolean fdt, boolean rft, int dataType, ArrayList labels,
        String label) {/*from   w ww  .  ja va2  s . c  o  m*/
    //DefaultTableModel model = new DefaultTableModel();

    HashMap<String, Integer> map = new HashMap<String, Integer>();

    for (Object temp : labels) {
        Integer count = map.get(String.valueOf(temp));
        map.put(String.valueOf(temp), (count == null) ? 1 : count + 1);
    }

    Vector _label = new Vector();
    Vector _freq = new Vector();
    Vector _rel_freq = new Vector();

    if (dataType == 1 || dataType == 3) {
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            _label.add(entry.getKey());
            _freq.add(entry.getValue());
            _rel_freq.add(((double) entry.getValue() / labels.size()) * (100));
        }
        string_maps = map;
        model.addColumn(label, _label);
    }

    else if (dataType == 2) {
        TreeMap<Double, Integer> num_map = new TreeMap<Double, Integer>();

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            num_map.put(Double.valueOf(entry.getKey()), entry.getValue());
        }

        for (Map.Entry<Double, Integer> entry1 : num_map.entrySet()) {
            _label.add(entry1.getKey());
            _freq.add(entry1.getValue());
            _rel_freq.add(round(((double) entry1.getValue() / labels.size()) * (100), 2));
        }
        double_maps = num_map;
        model.addColumn(label, _label);
    }

    if (fdt == true) {
        model.addColumn("Frequency", _freq);
    }
    if (rft == true) {
        model.addColumn("Relative Frequency", _rel_freq);
    }

    return model;
}

From source file:com.ga.logic.abstractclasses.RecordAbstract.java

@Override
public void setMeta(HashMap args) {
    argsSet = args.entrySet();
    Iterator argsIterator = argsSet.iterator();
    this.meta = new JSONObject();
    while (argsIterator.hasNext()) {
        Map.Entry argsElement = (Map.Entry) argsIterator.next();
        this.meta.put(argsElement.getKey().toString(), argsElement.getValue().toString());
    }/*from w  w w.ja  va 2 s .c o  m*/
}

From source file:com.polyvi.xface.extension.XDeviceExt.java

@Override
public void init(XExtensionContext extensionContext, XIWebContext webContext) {
    super.init(extensionContext, webContext);
    mDeviceInfo = new JSONObject();
    HashMap<String, Object> deviceInfo = new XDeviceInfo().getDeviceInfo(getContext());
    Iterator<Entry<String, Object>> it = deviceInfo.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        try {//  w  w w  .  j  a v  a 2s . com
            mDeviceInfo.put((String) entry.getKey(), entry.getValue());
        } catch (JSONException e) {
            XLog.e(XDeviceExt.class.getSimpleName(), "JSONException:", e);
        }
    }
}

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[]>();
    }//from   w  ww  . ja v  a2s  .  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.tecapro.inventory.common.tag.MSRadioTag.java

private Boolean keyExistTed(String key, List<HashMap<String, Boolean>> checkList) {
    Boolean result = false;//from w  ww  . j ava 2  s  .  c  o  m
    Iterator<HashMap<String, Boolean>> ite = checkList.iterator();
    while (ite.hasNext()) {
        HashMap<String, Boolean> item = ite.next();
        Iterator<?> iter = item.entrySet().iterator();
        if (iter.hasNext()) {
            Map.Entry<?, ?> mEntry = (Map.Entry<?, ?>) iter.next();
            if (key.equals(mEntry.getKey())) {
                result = true;
            }
        }
    }
    return result;
}