Example usage for java.util HashSet size

List of usage examples for java.util HashSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:functionaltests.execremote.TestExecRemote.java

private void scriptOnNodeSource(String nsName, HashSet<String> nodesUrls) throws Exception {
    RMTHelper.log("Test 6 - Execute script on a specified nodesource name");
    SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript");
    HashSet<String> targets = new HashSet<>(1);
    targets.add(nsName);/*from  ww  w.  ja  v a 2  s. com*/

    List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script,
            TargetType.NODESOURCE_NAME.toString(), targets);

    assertEquals("The size of result list must equal to size of nodesource", nodesUrls.size(), results.size());
    for (ScriptResult<Object> res : results) {
        Throwable exception = res.getException();
        if (exception != null) {
            RMTHelper.log("An exception occured while executing the script remotely:");
            exception.printStackTrace(System.out);
        }
        assertNull("No exception must occur", exception);
    }
}

From source file:org.oscarehr.web.MisReportUIBean.java

private DataRow getTotalIndividualsServed() {
    HashSet<Integer> individuals = new HashSet<Integer>();

    // count individuals in the system pertaining to the allowed programs during that time frame.
    for (Program program : selectedPrograms) {
        addIndividualsServedInProgram(individuals, program);
    }//  w  w  w . j  a  va  2  s  .c om

    return (new DataRow(4552440, "Individuals Served, (total clients)", individuals.size()));
}

From source file:com.act.reachables.Network.java

void addNode(Node n, Long nid) {
    if (this.nodeMapping.containsKey(n)) {
        if (!Boolean.valueOf((String) Node.getAttribute(n.id, "isrxn"))) {
            return;
        }// w  w w. j a  v a2s.c  om

        Node currentNode = this.nodeMapping.get(n);
        if (Node.getAttribute(nid, "reaction_ids") != null) {
            HashSet s = ((HashSet) Node.getAttribute(currentNode.id, "reaction_ids"));
            s.addAll((HashSet) Node.getAttribute(nid, "reaction_ids"));

            Node.setAttribute(currentNode.id, "reaction_ids", s);
            Node.setAttribute(currentNode.id, "reaction_count", s.size());
        }

        if (Node.getAttribute(nid, "organisms") != null) {
            HashSet orgs = ((HashSet) Node.getAttribute(currentNode.id, "organisms"));
            orgs.addAll((HashSet) Node.getAttribute(nid, "organisms"));

            Node.setAttribute(currentNode.id, "organisms", orgs);
        }
    } else {
        this.idToNode.put(nid, n);
        this.nodeMapping.put(n, n);
        this.nids.put(n, nid);
    }
}

From source file:com.orange.analysis.anasoot.main.AndroidPhase.java

@Override
public boolean run(String entryName, AppDescription descr, RuleFile ruleFile, PrintStream outStream)
        throws IOException, Alert {
    boolean xmlFormat = anasootconfig.xmlFormat();
    HashSet<String> restriction;
    if (entryName != null) {
        restriction = new HashSet<String>();
        restriction.add(entryName);/* ww  w  .ja va2  s . co  m*/
    } else {
        restriction = null;
    }
    if (!(descr instanceof APKDescr))
        throw new RuntimeException("Android app expected.");
    APKDescr apk = (APKDescr) descr;

    HashSet<String> notImplemented = new HashSet<String>();
    if (!xmlFormat && entryName == null) {
        outStream.println(HtmlOutput.header(1, "Global content analysis"));
    }

    Map<String, JavaReport> reports = runSoot(apk, ruleFile, restriction, notImplemented, outStream);

    boolean verdict = true;
    // Output unresolved classes.

    verdict &= !apk.resolutionErrors(xmlFormat, outStream);
    // Output unresolved components
    if (notImplemented.size() != 0) {
        if (xmlFormat) {
            XMLStream xmlout = new XMLStream(outStream);
            for (String classname : notImplemented) {
                xmlout.element("unknownComponent");
                xmlout.attribute("class", classname);
                xmlout.endElement();
            }
        } else {
            outStream.println(HtmlOutput.header(4,
                    HtmlOutput.color("red", "References in the manifest to unknown components")));
            outStream.println("<ul>");
            for (String classname : notImplemented) {
                outStream.println("<li>" + HtmlOutput.escape(classname) + "</li>");
            }
            outStream.println("</ul>");
        }
    }

    for (JavaReport report : reports.values()) {
        verdict &= report.getFinalVerdict();
    }
    if (scoreReport != null) {
        scoreValue = scoreReport.getScore();
        verdict &= scoreValue <= scoreReport.getThreshold();
    }
    File sootDir = new File(androidOutput);
    if (sootDir.exists() && !FileUtilities.removeDir(sootDir))
        Out.getLog().println("Cannot destroy sootOutput file.");

    return verdict;
}

From source file:com.antsdb.saltedfish.server.mysql.replication.MysqlSlave.java

private Parameters toParameters(TableMeta meta, Row row) {
    List<Column> columns = row.getColumns();
    Object[] pureValues;//from www .  j  ava 2  s . co  m

    PrimaryKeyMeta keyMeta = meta.getPrimaryKey();
    if (keyMeta != null) {
        List<ColumnMeta> primaryKeys = keyMeta.getColumns(meta);
        HashSet<Integer> pkNum = new HashSet<>();
        for (ColumnMeta key : primaryKeys) {
            pkNum.add(key.getColumnId());
        }

        pureValues = new Object[pkNum.size()];
        for (int i = 0; i < columns.size(); i++) {
            // col id starts with 1
            if (pkNum.contains(i + 1)) {
                pureValues[i] = toParameter(columns.get(i));
            }
        }
    } else {
        pureValues = new Object[columns.size()];
        for (int i = 0; i < columns.size(); i++) {
            pureValues[i] = toParameter(columns.get(i));
        }
    }
    return new Parameters(pureValues);
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCacheDirectives(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CacheDirectiveEntry> directives = dfs.listCacheDirectives(null);
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CacheDirectiveEntry directive = directives.next();
        String pollName = directive.getInfo().getPool();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);//from  w  w  w .  ja v  a2s. co  m
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:org.apache.storm.utils.Utils.java

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

    HashSet<URL> resources = new HashSet<URL>(findResources(configFilePath));
    if (resources.isEmpty()) {
        File configFile = new File(configFilePath);
        if (configFile.exists()) {
            return new FileInputStream(configFile);
        }
    } else if (resources.size() > 1) {
        throw new IOException("Found multiple " + configFilePath
                + " resources. You're probably bundling the 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:org.opendaylight.controller.clustering.services_implementation.internal.ClusteringServicesIT.java

@Test
public void clusterTest() throws CacheExistException, CacheConfigException, CacheListenerAddException {

    String container1 = "Container1";
    String container2 = "Container2";
    String cache1 = "Cache1";
    String cache2 = "Cache2";
    String cache3 = "Cache3";

    HashSet<cacheMode> cacheModeSet = new HashSet<cacheMode>();
    cacheModeSet.add(cacheMode.NON_TRANSACTIONAL);
    ConcurrentMap cm11 = this.clusterServices.createCache(container1, cache1, cacheModeSet);
    assertNotNull(cm11);//from   ww  w.  j  a v  a  2  s  . c om

    assertNull(this.clusterServices.getCache(container2, cache2));
    assertEquals(cm11, this.clusterServices.getCache(container1, cache1));

    assertFalse(this.clusterServices.existCache(container2, cache2));
    assertTrue(this.clusterServices.existCache(container1, cache1));

    ConcurrentMap cm12 = this.clusterServices.createCache(container1, cache2, cacheModeSet);
    ConcurrentMap cm23 = this.clusterServices.createCache(container2, cache3, cacheModeSet);

    HashSet<String> cacheList = (HashSet<String>) this.clusterServices.getCacheList(container1);
    assertEquals(2, cacheList.size());
    assertTrue(cacheList.contains(cache1));
    assertTrue(cacheList.contains(cache2));
    assertFalse(cacheList.contains(cache3));

    assertNotNull(this.clusterServices.getCacheProperties(container1, cache1));

    HashSet<IGetUpdates<?, ?>> listeners = (HashSet<IGetUpdates<?, ?>>) this.clusterServices
            .getListeners(container1, cache1);
    assertEquals(0, listeners.size());

    IGetUpdates<?, ?> getUpdate1 = new GetUpdates();
    this.clusterServices.addListener(container1, cache1, getUpdate1);
    listeners = (HashSet<IGetUpdates<?, ?>>) this.clusterServices.getListeners(container1, cache1);
    assertEquals(1, listeners.size());
    this.clusterServices.addListener(container1, cache1, new GetUpdates());
    listeners = (HashSet<IGetUpdates<?, ?>>) this.clusterServices.getListeners(container1, cache1);
    assertEquals(2, listeners.size());

    listeners = (HashSet<IGetUpdates<?, ?>>) this.clusterServices.getListeners(container2, cache3);
    assertEquals(0, listeners.size());

    this.clusterServices.removeListener(container1, cache1, getUpdate1);
    listeners = (HashSet<IGetUpdates<?, ?>>) this.clusterServices.getListeners(container1, cache1);
    assertEquals(1, listeners.size());

    InetAddress addr = this.clusterServices.getMyAddress();
    assertNotNull(addr);

    List<InetAddress> addrList = this.clusterServices.getClusteredControllers();

    this.clusterServices.destroyCache(container1, cache1);
    assertFalse(this.clusterServices.existCache(container1, cache1));

}

From source file:com.nttec.everychan.ui.presentation.Subscriptions.java

/**
 * ,    ? ? ?, ?  {@link #detectOwnPost(String, String, String, String)},
 * ? ?,  ?  ? (?)//  w w w  . ja va2  s  . c  o m
 * @param page ?
 * @param startPostIndex  ? ( ?)  ?, ? ?  ?? ?
 */
@SuppressWarnings("unchecked")
public void checkOwnPost(SerializablePage page, int startPostIndex) {
    if (page.pageModel == null || page.pageModel.type != UrlPageModel.TYPE_THREADPAGE || page.posts == null)
        return;
    String chan = page.pageModel.chanName;
    String board = page.pageModel.boardName;
    String thread = page.pageModel.threadNumber;
    Object[] tuple = waitingOwnPost;
    if (tuple != null && tuple[0].equals(chan) && tuple[1].equals(board) && tuple[2].equals(thread)) {
        waitingOwnPost = null;
        int postCount = page.posts.length - startPostIndex;
        if (postCount <= 1) {
            if (postCount == 1 && page.posts[startPostIndex] != null)
                addSubscription(chan, board, thread, page.posts[startPostIndex].number);
            return;
        }
        List<int[]> result = new ArrayList<>(postCount);
        List<String> waitingWords = (List<String>) tuple[3];
        for (int i = startPostIndex; i < page.posts.length; ++i) {
            if (page.posts[i] == null || page.posts[i].comment == null)
                continue;
            HashSet<String> postWords = new HashSet<>(commentToWordsList(htmlToComment(page.posts[i].comment)));
            //Logger.d(TAG, "checking post i=" + i + "\ncomment: " + page.posts[i].comment+"\nwords:" + postWords);
            int wordsCount = 0;
            for (String waitingWord : waitingWords)
                if (postWords.remove(waitingWord))
                    ++wordsCount;
            result.add(new int[] { i, wordsCount, postWords.size() });
            //Logger.d(TAG, "result: overlap=" + wordsCount + "; remained=" + postWords.size());
        }
        if (result.size() == 0)
            return;
        Collections.sort(result, new Comparator<int[]>() {
            @Override
            public int compare(int[] lhs, int[] rhs) {
                int result = compareInt(rhs[1], lhs[1]);
                if (result == 0)
                    result = compareInt(lhs[2], rhs[2]);
                if (result == 0)
                    result = compareInt(lhs[0], rhs[0]);
                return result;
            }

            private int compareInt(int lhs, int rhs) {
                return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
            }
        });
        //for (int[] entry : result) Logger.d(TAG, "[" + entry[0] + ";" + entry[1] + ";" + entry[2] + "]");
        addSubscription(chan, board, thread, page.posts[result.get(0)[0]].number);
    }
}

From source file:org.dcm4che2.tool.dcm2jpg.Dcm2Jpg.java

private void showFormatNames() {
    System.out.println("List of supported Format Names of registered ImageWriters:");
    Iterator<ImageWriterSpi> writers = ServiceRegistry.lookupProviders(ImageWriterSpi.class);
    HashSet<String> allNames = new HashSet<String>();
    String[] names;/*from w  w w  .  j a va2  s.c  o m*/
    for (; writers.hasNext();) {
        names = writers.next().getFormatNames();
        for (int i = 0; i < names.length; i++) {
            allNames.add(names[i].toUpperCase());
        }
    }
    System.out.print("   Found " + allNames.size() + " format names: ");
    for (String n : allNames) {
        System.out.print("'" + n + "', ");
    }
    System.out.println();
}