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:com.addthis.hydra.job.alert.JobAlertUtil.java

/**
 * Count the total number of hits along a certain path in a tree object
 * @param jobId The job to query/* w w w . java2s  .com*/
 * @param checkPath The path to check, e.g.
 * @return The number of hits along the specified path
 */
public static long getQueryCount(String jobId, String checkPath) {
    String queryURL = getQueryURL(jobId, checkPath, defaultOps, defaultOps);

    HashSet<String> result = new JSONFetcher.SetLoader(queryURL)
            .setContention(alertQueryTimeout, alertQueryRetries, alertQueryBackoff).load();
    if (result == null || result.isEmpty()) {
        log.warn("Found no data for job={} checkPath={}; returning zero", jobId, checkPath);
        return 0;
    } else if (result.size() > 1) {
        log.warn("Found multiple results for job={} checkPath={}; using first row", jobId, checkPath);
    }
    String raw = result.iterator().next();
    return Long.parseLong(QUERY_TRIM_PATTERN.matcher(raw).replaceAll("")); // Trim [] characters and parse as long

}

From source file:com.velonuboso.made.core.common.Helper.java

/**
 * Modification by rhgarcia from the implementation of M. Jessup 
 * at StackOverflow.//from  ww w  .  j a v a  2 s  . com
 * http://stackoverflow.com/users/294738/m-jessup
 */
public static ArrayList<Class> topologicalOrder(ArrayList<Class> classes) throws Exception {

    Node[] allNodes = new Node[classes.size()];
    HashMap<String, Node> nodes = new HashMap<String, Node>();

    for (int i = 0; i < classes.size(); i++) {
        Class c = classes.get(i);
        Node n = new Node(c);
        allNodes[i] = n;
        nodes.put(c.getSimpleName(), n);
    }

    for (int i = 0; i < allNodes.length; i++) {
        Node n = allNodes[i];
        Class c = n.getC();
        Archetype a = (Archetype) c.getConstructors()[0].newInstance();
        ArrayList<Class> dependencies = a.getDependencies();
        for (int j = 0; j < dependencies.size(); j++) {
            Class dep = dependencies.get(j);
            Node nAux = nodes.get(dep.getSimpleName());
            if (nAux != null) {
                nAux.addEdge(n);
            }
        }
    }

    //L <- Empty list that will contain the sorted elements
    ArrayList<Node> L = new ArrayList<Node>();

    //S <- Set of all nodes with no incoming edges
    HashSet<Node> S = new HashSet<Node>();
    for (Node n : allNodes) {
        if (n.inEdges.size() == 0) {
            S.add(n);
        }
    }

    //while S is non-empty do
    while (!S.isEmpty()) {
        //remove a node n from S
        Node n = S.iterator().next();
        S.remove(n);

        //insert n into L
        L.add(n);

        //for each node m with an edge e from n to m do
        for (Iterator<Edge> it = n.outEdges.iterator(); it.hasNext();) {
            //remove edge e from the graph
            Edge e = it.next();
            Node m = e.to;
            it.remove();//Remove edge from n
            m.inEdges.remove(e);//Remove edge from m

            //if m has no other incoming edges then insert m into S
            if (m.inEdges.isEmpty()) {
                S.add(m);
            }
        }
    }
    //Check to see if all edges are removed
    boolean cycle = false;
    for (Node n : allNodes) {
        if (!n.inEdges.isEmpty()) {
            cycle = true;
            break;
        }
    }
    if (cycle) {
        throw new Exception("Cycle present, topological sort not possible");
    }
    System.out.println("Topological Sort: " + Arrays.toString(L.toArray()));

    ArrayList<Class> ret = new ArrayList<Class>();
    for (Node n : L) {
        ret.add(n.getC());
    }
    return ret;
}

From source file:com.alibaba.jstorm.utils.LoadConf.java

public static InputStream getConfigFileInputStream(String configFilePath, boolean canMultiple)
        throws IOException {
    if (null == configFilePath) {
        throw new IOException("Could not find config file, name not specified");
    }//w w w  .  j  a va  2s .c o  m

    HashSet<URL> resources = new HashSet<>(findResources(configFilePath));
    if (resources.isEmpty()) {
        File configFile = new File(configFilePath);
        if (configFile.exists()) {
            return new FileInputStream(configFile);
        }
    } else if (resources.size() > 1 && !canMultiple) {
        throw new IOException("Found multiple " + configFilePath + " resources. "
                + "You're probably bundling storm jars with your topology jar. " + resources);
    } else {
        LOG.debug("Using " + configFilePath + " from resources");
        URL resource = resources.iterator().next();
        return resource.openStream();
    }
    return null;
}

From source file:SerialVersionUID.java

/**
 * Create a Map<String, ClassVersionInfo> for the jboss dist jars.
 * /*from   w w w  .j a  v  a  2 s  . co m*/
 * @param jbossHome -
 *          the jboss dist root directory
 * @return Map<String, ClassVersionInfo>
 * @throws IOException
 */
public static Map generateJBossSerialVersionUIDReport(File jbossHome) throws IOException {
    // Obtain the jars from the /lib, common/ and /server/all locations
    HashSet jarFiles = new HashSet();
    File lib = new File(jbossHome, "lib");
    buildJarSet(lib, jarFiles);
    File common = new File(jbossHome, "common");
    buildJarSet(common, jarFiles);
    File all = new File(jbossHome, "server/all");
    buildJarSet(all, jarFiles);
    URL[] cp = new URL[jarFiles.size()];
    jarFiles.toArray(cp);
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    URLClassLoader completeClasspath = new URLClassLoader(cp, parent);

    TreeMap classVersionMap = new TreeMap();
    Iterator jarIter = jarFiles.iterator();
    while (jarIter.hasNext()) {
        URL jar = (URL) jarIter.next();
        try {
            generateJarSerialVersionUIDs(jar, classVersionMap, completeClasspath, "");
        } catch (IOException e) {
            log.info("Failed to process jar: " + jar);
        }
    }

    return classVersionMap;
}

From source file:org.squale.squalix.util.file.FileUtility.java

/**
 * Rcupre le nom absolu du fichier java compil correspondant  la classe pass en paramtre parmi tous les noms
 * de fichier prsents dans le set.//w ww . j ava  2s  .  c  o m
 * 
 * @param pFilesName la liste des noms des fichiers
 * @param pAbsoluteClassName le nom absolu de la classe
 * @return le nom absolu du fichier compil de la classe <code>pAbsoluteClassName</code>
 */
public static String getClassFileName(HashSet pFilesName, String pAbsoluteClassName) {
    // Le nom de la classe sans son package:
    String classPath = pAbsoluteClassName.replace('.', File.separatorChar);
    Iterator it = pFilesName.iterator();
    String str = "";
    String result = null;
    boolean found = false;
    // Le nom du fichier compil associ  la classe a pour nom: nomDeLaClasse.class
    while (it.hasNext() && !found) {
        str = (String) it.next();
        found = str.endsWith(classPath + COMPILED_FILE_EXTENSION);
    }
    if (found) {
        result = str;
    }
    return result;
}

From source file:edu.cens.loci.classes.LociWifiFingerprint.java

/**
 * Calculated Tanimoto score between to Wifi fingerprints
 * @param sig1 is a Wifi fingerprint/*from   ww  w.ja va2  s .c  o  m*/
 * @param sig2 is a Wifi fingerprint
 * @param repAP1 
 * @param repAP2
 * @param rrThreshold is used to filter low response rate APs
 * @param isDebugOn
 * @return
 */
public static double tanimotoScore(LociWifiFingerprint sig1, LociWifiFingerprint sig2, HashSet<String> repAP1,
        HashSet<String> repAP2, double rrThreshold, boolean isDebugOn) {

    if (repAP1 == null)
        MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use all.");
    else
        MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use rep.");

    // use every beacon when repAP is empty
    if (repAP1 == null || repAP1.isEmpty())
        repAP1 = sig1.getBssids();
    if (repAP2 == null || repAP2.isEmpty())
        repAP2 = sig2.getBssids();

    // use only the union of both representative set
    HashSet<String> union = new HashSet<String>(repAP1);
    union.addAll(repAP2);

    // two arrays to save RSS values 
    double a[] = new double[union.size()];
    double b[] = new double[union.size()];

    // fill in the arrays with RSS values
    Iterator<String> iterator = union.iterator();
    int cnt = 0;

    String debugSsids = "   ";
    String debugRssA = "rss (a) : ";
    String debugRssB = "rss (b) : ";
    String debugNorA = "nor (a) : ";
    String debugNorB = "nor (b) : ";
    String debugCntA = "cnt (a) : ";
    String debugCntB = "cnt (b) : ";
    String debugRRA = "rr  (a) : ";
    String debugRRB = "rr  (b) : ";

    while (iterator.hasNext()) {
        String bssid = iterator.next();

        int aIntVal = sig1.getAvgRss(bssid);
        int bIntVal = sig2.getAvgRss(bssid);
        double rr1 = sig1.getResponseRate(bssid);
        double rr2 = sig2.getResponseRate(bssid);

        if (rr1 >= rrThreshold)
            a[cnt] = raw2normal(aIntVal, pMinRss, pMaxRss);
        else
            a[cnt] = raw2normal(0, pMinRss, pMaxRss);

        if (rr2 >= rrThreshold)
            b[cnt] = raw2normal(bIntVal, pMinRss, pMaxRss);
        else
            b[cnt] = raw2normal(0, pMinRss, pMaxRss);

        cnt++;

        if (isDebugOn) {
            String ssid = sig1.getSsid(bssid);
            if (ssid == null)
                ssid = sig2.getSsid(bssid);
            if (ssid == null)
                ssid = "unknown";

            int count1 = sig1.getCount(bssid);
            int count2 = sig2.getCount(bssid);

            debugSsids = debugSsids + String.format("%10s", ssid.substring(0, Math.min(ssid.length(), 9)));
            debugRssA = debugRssA + String.format("%10d", aIntVal);
            debugRssB = debugRssB + String.format("%10d", bIntVal);
            debugNorA = debugNorA + String.format("%10.2f", a[cnt - 1]);
            debugNorB = debugNorB + String.format("%10.2f", b[cnt - 1]);
            debugCntA = debugCntA + String.format("%10d", count1);
            debugCntB = debugCntB + String.format("%10d", count2);
            debugRRA = debugRRA + String.format("%10.2f", rr1);
            debugRRB = debugRRB + String.format("%10.2f", rr2);
        }
    }

    MyLog.d(isDebugOn, TAG, debugSsids);
    MyLog.d(isDebugOn, TAG, debugRssA);
    MyLog.d(isDebugOn, TAG, debugRssB);
    MyLog.d(isDebugOn, TAG, debugNorA);
    MyLog.d(isDebugOn, TAG, debugNorB);
    MyLog.d(isDebugOn, TAG, debugCntA);
    MyLog.d(isDebugOn, TAG, debugCntB);
    MyLog.d(isDebugOn, TAG, debugRRA);
    MyLog.d(isDebugOn, TAG, debugRRB);

    return tanimotoSimilarity(a, b);
}

From source file:amie.keys.CSAKey.java

private static HashSet<HashSet<Integer>> subSet(HashSet<HashSet<Integer>> nonKeysInt2, int start, int end) {
    int counter = 0;
    Iterator<HashSet<Integer>> it = nonKeysInt2.iterator();
    HashSet<HashSet<Integer>> result = new HashSet<>();
    while (counter < start) {
        it.next();/*from   w w w. java 2  s .  c  o m*/
        ++counter;
    }

    while (counter < end) {
        result.add(it.next());
        ++counter;
    }

    return result;
}

From source file:certh.iti.mklab.jSimilarity.documentUtils.Corpus.java

/**
 *
 * @param predicate/*  w ww .j a  v a  2  s . c o  m*/
 * @return
 */
public Iterator<T> iterator(Predicate<T> predicate) {
    HashSet subset = new HashSet(CollectionUtils.select(corpus, predicate));
    return subset.iterator();
}

From source file:org.apache.accumulo.server.init.Initialize.java

private static void addVolumes(VolumeManager fs) throws IOException {

    String[] volumeURIs = VolumeConfiguration.getVolumeUris(SiteConfiguration.getInstance());

    HashSet<String> initializedDirs = new HashSet<String>();
    initializedDirs.addAll(Arrays.asList(ServerConstants.checkBaseUris(volumeURIs, true)));

    HashSet<String> uinitializedDirs = new HashSet<String>();
    uinitializedDirs.addAll(Arrays.asList(volumeURIs));
    uinitializedDirs.removeAll(initializedDirs);

    Path aBasePath = new Path(initializedDirs.iterator().next());
    Path iidPath = new Path(aBasePath, ServerConstants.INSTANCE_ID_DIR);
    Path versionPath = new Path(aBasePath, ServerConstants.VERSION_DIR);

    UUID uuid = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(iidPath, SiteConfiguration.getInstance()));
    for (Pair<Path, Path> replacementVolume : ServerConstants.getVolumeReplacements()) {
        if (aBasePath.equals(replacementVolume.getFirst()))
            log.error(aBasePath + " is set to be replaced in " + Property.INSTANCE_VOLUMES_REPLACEMENTS
                    + " and should not appear in " + Property.INSTANCE_VOLUMES
                    + ". It is highly recommended that this property be removed as data could still be written to this volume.");
    }//  w w w .  j  a v  a  2s  .  co m

    if (ServerConstants.DATA_VERSION != Accumulo.getAccumuloPersistentVersion(
            versionPath.getFileSystem(CachedConfiguration.getInstance()), versionPath)) {
        throw new IOException("Accumulo " + Constants.VERSION + " cannot initialize data version "
                + Accumulo.getAccumuloPersistentVersion(fs));
    }

    initDirs(fs, uuid, uinitializedDirs.toArray(new String[uinitializedDirs.size()]), true);
}

From source file:org.exoplatform.content.service.NewContentNavListener.java

private void initDB() throws Exception {
    HashSet<String> users = config_.getPredefinedOwner();
    Iterator<String> iter = users.iterator();
    while (iter.hasNext()) {
        String user = iter.next();
        createContentConfigForUser(user);
    }//from   ww w  .j a v a  2  s  . c o m
}