Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

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

Prototype

int size();

Source Link

Document

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

Usage

From source file:expansionBlocks.ProcessCommunities.java

private static double compareCommunities(Set<Entity> c1, Set<Entity> c2) {
    Collection intersection = CollectionUtils.intersection(c1, c2);
    double d, d1, d2;
    d1 = ((double) intersection.size()) / ((double) c1.size());
    d2 = ((double) intersection.size()) / ((double) c2.size());
    d = d1 > d2 ? d1 : d2;/*from  w w w . j av  a  2s. c o m*/

    return d;

}

From source file:gov.nih.nci.caintegrator.application.arraydata.ArrayDesignChecker.java

private static void checkGeneReporters(Platform platform) {
    PlatformHelper platformHelper = new PlatformHelper(platform);
    Set<ReporterList> geneReporters = platformHelper.getReporterLists(ReporterTypeEnum.GENE_EXPRESSION_GENE);
    for (ReporterList reporterList : geneReporters) {
        assertEquals(platform, reporterList.getPlatform());
        Set<String> geneSymbols = new HashSet<String>();
        for (AbstractReporter reporter : reporterList.getReporters()) {
            assertEquals(1, reporter.getGenes().size());
            Gene gene = reporter.getGenes().iterator().next();
            assertEquals(reporter.getName(), gene.getSymbol());
            geneSymbols.add(gene.getSymbol());
        }//w  w w  .  jav a  2 s. com
        assertEquals(reporterList.getReporters().size(), geneSymbols.size());
    }
}

From source file:com.mycompany.myelasticsearch.DocumentReader.java

public static void getAllCapitalWords(String docText) {
    Set<String> allCapsWords = new HashSet<>();
    Pattern p = Pattern.compile("\\b[A-Z]{2,}\\b");
    Matcher m = p.matcher(docText);
    while (m.find()) {
        String word = m.group();//from  w  ww .  j  a v  a 2 s  .  c om
        // System.out.println(word);
        allCapsWords.add(word);
    }

    for (String allcaps : allCapsWords) {
        System.out.println(allcaps);
    }
    System.out.println("Caps word count" + allCapsWords.size());
    org.json.simple.JSONObject obj = new org.json.simple.JSONObject();
    int count = 0;
    for (String output : outputArray) {
        obj.put(String.valueOf(count), output.replaceAll("\\s+", " "));
        count++;
    }
    try {

        FileWriter file = new FileWriter("CapsWord.txt");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.uni_potsdam.hpi.asg.logictool.helper.BDDHelper.java

public static BDD mergeBDDs(BDD bdd, NetlistVariable replaceVar, BDD replaceBdd, Netlist netlist) {

    Set<NetlistVariable> bddvars = BDDHelper.getVars(bdd, netlist);
    if (!bddvars.contains(replaceVar)) {
        logger.error("ReplaceVar not in Vars");
        return null;
    }/* www .  j a  v a2s . com*/

    if (bddvars.size() == 1) {
        //         logger.debug("Shortcut");
        //         logger.debug("BDD: " + getFunctionString(bdd, netlist));
        //         logger.debug("ReplBDD: " + getFunctionString(replaceBdd, netlist));
        //         logger.debug("ReplVar: " + replaceVar.getName());
        if (isPos(bdd, replaceVar)) {
            return replaceBdd;
        } else {
            return replaceBdd.not();
        }
        //         return replaceBdd;//.and(netlist.getFac().one());
    }

    SortedSet<NetlistVariable> newinputs = new TreeSet<>();
    newinputs.addAll(bddvars);
    newinputs.addAll(BDDHelper.getVars(replaceBdd, netlist));
    newinputs.remove(replaceVar);
    //      System.out.println("New Inp: " + newinputs.toString());

    BDD retVal = netlist.getFac().zero();
    BitSet b = new BitSet(newinputs.size());
    for (int i = 0; i < Math.pow(2, newinputs.size()); i++) {
        //         System.out.println(i + ": " + BitSetHelper.formatBitset(b, newinputs.size()));
        int index = 0;
        BDD bdd_new = bdd;
        BDD replacBdd_new = replaceBdd;
        BDD minterm = netlist.getFac().one();
        //TODO: xWITH
        for (NetlistVariable var : newinputs) {
            if (b.get(index)) {
                bdd_new = bdd_new.restrict(var.toBDD());
                replacBdd_new = replacBdd_new.restrict(var.toBDD());
                minterm = minterm.and(var.toBDD());
            } else {
                bdd_new = bdd_new.restrict(var.toNotBDD());
                replacBdd_new = replacBdd_new.restrict(var.toNotBDD());
                minterm = minterm.and(var.toNotBDD());
            }
            index++;
        }
        if (replacBdd_new.isZero()) {
            bdd_new = bdd_new.restrict(replaceVar.toNotBDD());
        } else if (replacBdd_new.isOne()) {
            bdd_new = bdd_new.restrict(replaceVar.toBDD());
        } else {
            logger.error("Repl BDD should be one or zero");
        }

        if (bdd_new.isZero()) {

        } else if (bdd_new.isOne()) {
            retVal.orWith(minterm);
        } else {
            logger.error("BDD should be one or zero");
        }

        BitSetHelper.dualNext(b);
    }

    //      if(bddvars.size() == 1) {
    //         logger.debug("RetVal: " + getFunctionString(retVal, netlist));
    //      }

    return retVal;
}

From source file:bioLockJ.util.MetadataUtil.java

/**
 * The attributeMap maps attributes to their set of values.  Only done for metadata that will
 * be used in the R-script./*from  ww  w .  j a v a 2  s  .c  om*/
 *
 * @throws Exception
 */
private static void populateAttributeMap() throws Exception {
    //Log.out.warn( "===> calling populateAttributeMap() for metaId = " + metaId );
    //Log.out.warn( "===> metadataMap.get( metaId ) = " + metadataMap.get( metaId ) );
    Log.out.info("===> All rScriptFields = " + rScriptFields);

    final Map<String, Integer> colIndexMap = new HashMap<>();
    int j = 0;
    for (final String att : metadataMap.get(metaId)) {
        if (rScriptFields.contains(att)) {
            Log.out.info("Initialize Attribute Map | attribute(" + att + ") = index(" + j + ")");
            colIndexMap.put(att, j);
            attributeMap.put(att, new HashSet<>());
        }
        j++;
    }

    for (final String att : colIndexMap.keySet()) {
        final int target = colIndexMap.get(att);
        for (final String key : metadataMap.keySet()) {

            if (!key.equals(metaId)) {
                //               Log.out.warn( "===> metadataMap KEY DOES NOT MATCH metaId" );
                //               Log.out.warn( "===> metadataMap CHECK IF --> key( " + key + " ) = metaId( " + metaId + " )" );
                //               Log.out.warn(
                //                     "===> key LENGTH( " + key.length() + " ) = metaId LENGTH( " + metaId.length() + " )" );
                int i = 0;
                final List<String> row = metadataMap.get(key);
                for (final String value : row) {
                    if ((i++ == target) && !value.equals(Config.requireString(Config.INPUT_NULL_VALUE))) {
                        Log.out.debug(
                                "===> Add (" + value + ") to existing attributeMap " + attributeMap.get(att));
                        attributeMap.get(att).add(value);
                    }
                }
            }
        }
    }

    for (final String key : attributeMap.keySet()) {
        final Set<String> vals = attributeMap.get(key);
        Log.out.info("Attribute Map (" + key + ") = " + vals);
        if (nominalFields.contains(key) && (vals.size() < 2)) {
            throw new Exception("Property " + RScript.R_NOMINAL_DATA + " contains attribute [" + key
                    + "] with only " + vals.size()
                    + " values in the metadata file.  Statistical tests require at least 2 unique options.");
        } else if (nominalFields.contains(key) && (vals.size() == 2)) {

            binaryFields.add(key);
            nominalFields.remove(key);
        } else if (numericFields.contains(key)) {
            for (final String val : vals) {
                if (!NumberUtils.isNumber(val)) {
                    throw new Exception("Property " + RScript.R_NUMERIC_DATA + " contains attribute [" + key
                            + "] with non-numeric data [" + val + "]");
                }
            }
        }
    }
}

From source file:controllers.Common.java

@Util
public static void flashParamsExcept(String... paramNames) {
    Set<String> names = Sets.newHashSet(params.all().keySet());
    names.removeAll(Arrays.asList(paramNames));
    String[] array = new String[names.size()];
    params.flash(names.toArray(array));// ww  w.j a  v  a2s  .  c  om
}

From source file:com.intuit.autumn.metrics.MetricsServices.java

/**
 * Metrics services configuration utility.
 *
 * @return collection of enabled metrics services.
 *///from  ww w . j a  va2  s  . c  om

// todo: ?do better?
public static Set<Class<? extends Service>> getEnabledMetricsServices() {
    LOGGER.debug("getting enabled metrics services");

    Properties properties = create(PROPERTY_NAME, MetricsModule.class);
    Set<Class<? extends Service>> metricsServices = newHashSet();

    addIfEnabled(properties, metricsServices, "metrics.csv.enabled");
    addIfEnabled(properties, metricsServices, METRICS_GRAPHITE_ENABLED_KEY);
    // note: graphite is needed for hystrix ( don't be alarmed )
    addIfEnabled(properties, metricsServices, "metrics.hystrix.enabled", METRICS_GRAPHITE_ENABLED_KEY);
    addIfEnabled(properties, metricsServices, "metrics.jmx.enabled");

    LOGGER.debug("got enabled metrics services count: {}", metricsServices.size());

    return metricsServices;
}

From source file:it.units.malelab.ege.util.Utils.java

public static double multisetDiversity(Multiset m, Set d) {
    double[] counts = new double[d.size()];
    int i = 0;// w  ww  .  j  a  v  a 2 s. c  o m
    for (Object possibleValue : d) {
        counts[i] = m.count(possibleValue);
        i = i + 1;
    }
    return 1d - normalizedVariance(counts);
}

From source file:net.lldp.checksims.submission.Submission.java

/**
 * Turn a list of files and a name into a Submission.
 *
 * The contents of a submission are built deterministically by reading in files in alphabetical order and appending
 * their contents./*  ww  w. j  av  a2s  .  c o m*/
 *
 * @param name Name of the new submission
 * @param files List of files to include in submission
 * @param splitter Tokenizer for files in the submission
 * @return A new submission formed from the contents of all given files, appended and tokenized
 * @throws IOException Thrown on error reading from file
 * @throws NoMatchingFilesException Thrown if no files are given
 */
static Submission submissionFromFiles(String name, Set<File> files)
        throws IOException, NoMatchingFilesException {
    checkNotNull(name);
    checkArgument(!name.isEmpty(), "Submission name cannot be empty");
    checkNotNull(files);

    Logger logs = LoggerFactory.getLogger(Submission.class);

    if (files.size() == 0) {
        throw new NoMatchingFilesException(
                "No matching files found, cannot create submission named \"" + name + "\"");
    }

    // To ensure submission generation is deterministic, sort files by name, and read them in that order
    List<File> orderedFiles = Ordering
            .from((File file1, File file2) -> file1.getName().compareTo(file2.getName()))
            .immutableSortedCopy(files);

    StringBuilder fileContent = new StringBuilder();

    // Could do this with a .stream().forEach(...) but we'd have to handle the IOException inside
    for (File f : orderedFiles) {
        String content = FileUtils.readFileToString(f, StandardCharsets.UTF_8);

        fileContent.append(content);

        if (!content.endsWith("\n") && !content.isEmpty()) {
            fileContent.append("\n");
        }
    }

    String contentString = fileContent.toString();

    if (contentString.length() > 7500 * 4) { // large number of tokens * average token length
        logs.warn(
                "Warning: Submission " + name + " has very large source size (" + contentString.length() + ")");
    }

    return new ConcreteSubmission(name, contentString);
}

From source file:io.fabric8.kubernetes.pipeline.devops.ApplyStepExecution.java

/**
 * Should we try to create a route for the given service?
 * <p>/*  www .j a v  a2 s. com*/
 * By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443
 *
 * @return true if we should create an OpenShift Route for this service.
 */
protected static boolean shouldCreateRouteForService(Service service, String id, TaskListener listener) {
    if ("kubernetes".equals(id) || "kubernetes-ro".equals(id)) {
        return false;
    }
    Set<Integer> ports = KubernetesHelper.getPorts(service);
    if (ports.size() == 1) {
        return true;
    } else {
        listener.getLogger().println("Not generating route for service " + id
                + " as only single port services are supported. Has ports: " + ports);
        return false;
    }
}