Example usage for java.util HashSet iterator

List of usage examples for java.util HashSet iterator

Introduction

In this page you can find the example usage for java.util HashSet iterator.

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:cn.caimatou.canting.utils.http.asynchttp.RetryHandler.java

protected boolean isInList(HashSet<Class<?>> list, Throwable error) {
    Iterator<Class<?>> itr = list.iterator();
    while (itr.hasNext()) {
        if (itr.next().isInstance(error)) {
            return true;
        }//from   w ww  . j  av a 2  s  .co  m
    }
    return false;
}

From source file:com.espertech.esper.epl.join.table.PropertyCompositeEventTable.java

public Iterator<EventBean> iterator() {
    HashSet<EventBean> result = new LinkedHashSet<EventBean>();
    chain.getAll(result, index);//from ww w. j  av  a 2 s.co m
    return result.iterator();
}

From source file:Utils.CVEUtils.java

/**
 * Lookup a load of CVEs at once./*  ww  w  . j a v  a  2 s  .c  om*/
 *
 * @param cves
 * @return a vector of String[] with format { cveid, cvss_risk, summary }
 */
public Vector getCVEs(HashSet cves) {
    Vector answer = new Vector();
    ArrayList al = new ArrayList();

    Iterator it = cves.iterator();
    while (it.hasNext()) {
        String cve = (String) it.next();
        String[] cve_details = getCVE(cve);
        // If it is null then that vuln didn't exist.
        if (cve_details != null) {
            answer.add(cve_details);

            CVE c = new CVE();
            c.setCveId(cve_details[0]);
            c.setRiskScore(cve_details[1]);
            c.setSummary(cve_details[2]);

            al.add(c);

        } else {
            System.out.println("==CVEUtils=getCVEs: No local vuln for " + cve + ", consider updating");
        }
    }

    Collections.sort(al, Collections.reverseOrder());

    Vector actual_answer = new Vector();
    actual_answer.addAll(al);

    return actual_answer;
}

From source file:org.infoglue.deliver.portal.information.DynamicInformationProviderIG.java

public Iterator getResponseContentTypes() {
    log.debug("getResponseContentTypes()");
    HashSet responseMimeTypes = new HashSet(NumberOfKnownMimetypes);
    responseMimeTypes.add("text/html");

    return responseMimeTypes.iterator();
}

From source file:edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer.java

/**
  * Extracts the weak components from a graph.
  * @param graph the graph whose weak components are to be extracted
  * @return the list of weak components/* w w  w . j av  a 2s.c  o m*/
  */
public Set<Set<V>> transform(Graph<V, E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
        Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for (V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}

From source file:org.accada.hal.impl.sim.CmdLineSim.java

private void getInputString(String prompt) throws IOException {
    System.out.print(prompt);//w  ww  .  j ava  2 s.c  o m
    String cmd = cmdLineIn.readLine();

    if (cmd.equalsIgnoreCase("add")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.add(sourceId, tagId)) {
            System.out.println("OK.");
        } else {
            System.out.println("Failed.");
        }
    } else if (cmd.equalsIgnoreCase("sourceids")) {
        String[] sourceIds = null;
        sourceIds = controller.getReadPointNames();
        for (int i = 0; i < sourceIds.length; i++) {
            System.out.println(sourceIds[i]);
        }
    } else if (cmd.equalsIgnoreCase("remove")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.remove(sourceId, tagId)) {
            System.out.println("OK.");
        } else {
            System.out.println("Failed.");
        }
    } else if (cmd.equalsIgnoreCase("contains")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.contains(sourceId, tagId)) {
            System.out.println("Yes.");
        } else {
            System.out.println("No.");
        }
    } else if (cmd.equalsIgnoreCase("getall")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();

        HashSet s = (HashSet) controller.getTagsFromReadPoint(sourceId);
        Iterator it = s.iterator();
        while (it.hasNext()) {
            System.out.println(((Tag) it.next()).getTagID());
        }
    } else if (cmd.equalsIgnoreCase("exit")) {
        System.exit(0);
    } else {
        log.error("Unknown Command");
        log.info("Usage: Available commmands:");
        log.info(" sourceids, add, remove, contains, getall");
    }
}

From source file:org.accada.reader.hal.impl.sim.CmdLineSim.java

private void getInputString(String prompt) throws IOException {
    System.out.print(prompt);//w  w  w .  j a v a  2s.  com
    String cmd = cmdLineIn.readLine();

    if (cmd.equalsIgnoreCase("add")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.add(sourceId, tagId)) {
            System.out.println("OK.");
        } else {
            System.out.println("Failed.");
        }
    } else if (cmd.equalsIgnoreCase("sourceids")) {
        String[] sourceIds = null;
        try {
            sourceIds = controller.getReadPointNames();
        } catch (HardwareException ignored) {
        }
        for (int i = 0; i < sourceIds.length; i++) {
            System.out.println(sourceIds[i]);
        }
    } else if (cmd.equalsIgnoreCase("remove")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.remove(sourceId, tagId)) {
            System.out.println("OK.");
        } else {
            System.out.println("Failed.");
        }
    } else if (cmd.equalsIgnoreCase("contains")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();
        System.out.print("Tag ID> ");
        String tagId = cmdLineIn.readLine();
        if (controller.contains(sourceId, tagId)) {
            System.out.println("Yes.");
        } else {
            System.out.println("No.");
        }
    } else if (cmd.equalsIgnoreCase("getall")) {
        System.out.print("Source ID> ");
        String sourceId = cmdLineIn.readLine();

        HashSet s = (HashSet) controller.getTagsFromReadPoint(sourceId);
        Iterator it = s.iterator();
        while (it.hasNext()) {
            System.out.println(((Tag) it.next()).getTagID());
        }
    } else if (cmd.equalsIgnoreCase("exit")) {
        System.exit(0);
    } else {
        log.error("Unknown Command");
        log.info("Usage: Available commmands:");
        log.info(" sourceids, add, remove, contains, getall");
    }
}

From source file:TreePrinter.java

public void print(PrintStream s, Locale l) {
    printStream = s;//from  w w  w .ja  v  a  2  s.  com
    HashSet sharedGroups = new HashSet();
    printTree(l, 0, sharedGroups);
    Iterator iterator = sharedGroups.iterator();
    while (iterator.hasNext()) {
        SharedGroup sg = (SharedGroup) iterator.next();
        print(s, sg);
    }
}

From source file:org.xwalk.runtime.extension.api.contacts.ContactEventListener.java

private JSONArray convertSet2JSONArray(HashSet<String> set) {
    JSONArray jsonArray = new JSONArray();
    Iterator<String> iterator = set.iterator();
    while (iterator.hasNext()) {
        jsonArray.put(iterator.next());//from  w w  w.j a  v a  2  s.  c om
    }
    return jsonArray;
}

From source file:org.openvpms.component.system.common.jxpath.BigDecimalOperationRelationalExpression.java

/**
 * Learn whether there is an intersection between two Iterators.
 *
 * @param lit left Iterator/*from   www  .  ja  v  a 2 s . c  o m*/
 * @param rit right Iterator
 * @return whether a match was found
 */
private boolean findMatch(Iterator lit, Iterator rit) {
    HashSet<Object> left = new HashSet<Object>();
    while (lit.hasNext()) {
        left.add(lit.next());
    }
    while (rit.hasNext()) {
        if (containsMatch(left.iterator(), rit.next())) {
            return true;
        }
    }
    return false;
}