Example usage for java.util LinkedHashSet size

List of usage examples for java.util LinkedHashSet size

Introduction

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

Prototype

int size();

Source Link

Document

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

Usage

From source file:org.apache.druid.initialization.Initialization.java

/**
 * Find all the extension files that should be loaded by druid.
 * <p/>//  www  .j a  va 2  s  .  co m
 * If user explicitly specifies druid.extensions.loadList, then it will look for those extensions under root
 * extensions directory. If one of them is not found, druid will fail loudly.
 * <p/>
 * If user doesn't specify druid.extension.toLoad (or its value is empty), druid will load all the extensions
 * under the root extensions directory.
 *
 * @param config ExtensionsConfig configured by druid.extensions.xxx
 *
 * @return an array of druid extension files that will be loaded by druid process
 */
public static File[] getExtensionFilesToLoad(ExtensionsConfig config) {
    final File rootExtensionsDir = new File(config.getDirectory());
    if (rootExtensionsDir.exists() && !rootExtensionsDir.isDirectory()) {
        throw new ISE("Root extensions directory [%s] is not a directory!?", rootExtensionsDir);
    }
    File[] extensionsToLoad;
    final LinkedHashSet<String> toLoad = config.getLoadList();
    if (toLoad == null) {
        extensionsToLoad = rootExtensionsDir.listFiles();
    } else {
        int i = 0;
        extensionsToLoad = new File[toLoad.size()];
        for (final String extensionName : toLoad) {
            File extensionDir = new File(extensionName);
            if (!extensionDir.isAbsolute()) {
                extensionDir = new File(rootExtensionsDir, extensionName);
            }

            if (!extensionDir.isDirectory()) {
                throw new ISE("Extension [%s] specified in \"druid.extensions.loadList\" didn't exist!?",
                        extensionDir.getAbsolutePath());
            }
            extensionsToLoad[i++] = extensionDir;
        }
    }
    return extensionsToLoad == null ? new File[] {} : extensionsToLoad;
}

From source file:org.opencb.opencga.storage.core.metadata.StudyConfiguration.java

public static LinkedHashMap<String, Integer> getReturnedSamplesPosition(StudyConfiguration studyConfiguration,
        LinkedHashSet<String> returnedSamples,
        Function<StudyConfiguration, BiMap<String, Integer>> getIndexedSamplesPosition) {
    LinkedHashMap<String, Integer> samplesPosition;
    if (returnedSamples == null || returnedSamples.isEmpty()) {
        BiMap<Integer, String> unorderedSamplesPosition = getIndexedSamplesPosition(studyConfiguration)
                .inverse();//w w  w . jav  a 2 s.  c o m
        samplesPosition = new LinkedHashMap<>(unorderedSamplesPosition.size());
        for (int i = 0; i < unorderedSamplesPosition.size(); i++) {
            samplesPosition.put(unorderedSamplesPosition.get(i), i);
        }
    } else {
        samplesPosition = new LinkedHashMap<>(returnedSamples.size());
        int index = 0;
        BiMap<String, Integer> indexedSamplesId = getIndexedSamplesPosition.apply(studyConfiguration);
        for (String returnedSample : returnedSamples) {
            if (!returnedSample.isEmpty() && StringUtils.isNumeric(returnedSample)) {
                returnedSample = studyConfiguration.getSampleIds().inverse()
                        .get(Integer.parseInt(returnedSample));
            }
            if (!samplesPosition.containsKey(returnedSample)) {
                if (indexedSamplesId.containsKey(returnedSample)) {
                    samplesPosition.put(returnedSample, index++);
                }
            }
        }
        //                for (String sample : indexedSamplesId.keySet()) {
        //                    samplesPosition.put(sample, index++);
        //                }
    }
    return samplesPosition;
}

From source file:com.google.gwt.emultest.java.util.LinkedHashSetTest.java

@SuppressWarnings("unchecked")
public void testClone() {
    LinkedHashSet<String> srcSet = new LinkedHashSet<String>();
    checkEmptyLinkedHashSetAssumptions(srcSet);

    // Check empty clone behavior
    LinkedHashSet<String> dstSet = (LinkedHashSet<String>) srcSet.clone();
    assertNotNull(dstSet);// w ww. ja va2 s. c om
    assertEquals(dstSet.size(), srcSet.size());
    assertEquals(dstSet.toArray(), srcSet.toArray());

    // Check non-empty clone behavior
    srcSet.add(VALUE_1);
    srcSet.add(VALUE_2);
    srcSet.add(VALUE_3);
    srcSet.add(VALUE_4);
    dstSet = (LinkedHashSet<String>) srcSet.clone();
    assertNotNull(dstSet);
    assertEquals(dstSet.size(), srcSet.size());
    assertEquals(dstSet.toArray(), srcSet.toArray());
}

From source file:com.aurel.track.teamgeist.TeamgeistServicesTest.java

/**
 * This method iterate through the Set which contains all action names used by Teamgeist.
 * If an action missing the test fails.//w  w  w. ja  v a 2s  .co m
 */
@Test
public void testServices() {
    LinkedHashSet<String> actionNamesSet = getActinNames();
    if (actionNamesSet != null && actionNamesSet.size() > 0) {
        for (String actionName : actionNamesSet) {
            try {
                ActionProxy actionProxy = getActionProxy("/" + actionName);
                assertNotNull(actionProxy);
                Class<?> actionClass = Class.forName(actionProxy.getAction().getClass().getName());
                actionClass.getMethod(actionProxy.getMethod());
            } catch (NoSuchMethodException noMethodEX) {
                fail("No such method exception at: " + actionName);
                System.out.println("No such method: " + actionName);
            } catch (ClassNotFoundException noClassEx) {
                fail("Class not found exception at: " + actionName);
                System.out.println("No such class: " + actionName);
            } catch (NullPointerException nullEx) {
                fail("Null pointer exception at: " + actionName);
                System.out.println("Null pointer at: " + actionName);
            }
        }
        System.out.println(
                "Number of actions: " + actionNamesSet.size() + ". " + "The test was executed successfully!");
    } else {
        fail("Error while parsing Services file!");
    }
}

From source file:org.mskcc.cbio.oncokb.quest.VariantAnnotationXML.java

public static String annotate(Alteration alt, String tumorType) {
        //        GeneBo geneBo = ApplicationContextSingleton.getGeneBo();

        StringBuilder sb = new StringBuilder();

        Gene gene = alt.getGene();//from   w w w  . j a  v  a2 s  .c  o m

        //        Set<Gene> genes = new HashSet<Gene>();
        //        if (gene.getEntrezGeneId() > 0) {
        //            genes.add(gene);
        //        } else {
        // fake gene... could be a fusion gene
        //            Set<String> aliases = gene.getGeneAliases();
        //            for (String alias : aliases) {
        //                Gene g = geneBo.findGeneByHugoSymbol(alias);
        //                if (g != null) {
        //                    genes.add(g);
        //                }
        //            }
        //        }

        List<TumorType> relevantTumorTypes = TumorTypeUtils.getMappedOncoTreeTypesBySource(tumorType, "quest");

        AlterationUtils.annotateAlteration(alt, alt.getAlteration());

        AlterationBo alterationBo = ApplicationContextSingleton.getAlterationBo();
        LinkedHashSet<Alteration> alterations = alterationBo.findRelevantAlterations(alt, true);

        // In previous logic, we do not include alternative alleles
        List<Alteration> alternativeAlleles = AlterationUtils.getAlleleAlterations(alt);
        alterations.removeAll(alternativeAlleles);

        EvidenceBo evidenceBo = ApplicationContextSingleton.getEvidenceBo();

        // find all drugs
        //List<Drug> drugs = evidenceBo.findDrugsByAlterations(alterations);

        // find tumor types
        Set<String> tumorTypes = new HashSet<>();

        if (alterations != null && alterations.size() > 0) {
            List<Object> tumorTypesEvidence = evidenceBo
                    .findTumorTypesWithEvidencesForAlterations(new ArrayList<>(alterations));
            for (Object evidence : tumorTypesEvidence) {
                if (evidence != null) {
                    Object[] evidences = (Object[]) evidence;
                    if (evidences.length > 0 && evidences[0] != null) {
                        tumorTypes.add((String) evidences[0]);
                    }
                }
            }
        }

        //        sortTumorType(tumorTypes, tumorType);
        Query query = new Query(alt);
        query.setTumorType(tumorType);
        // summary
        sb.append("<annotation_summary>");
        sb.append(SummaryUtils.fullSummary(gene, alt,
                alterations.isEmpty() ? Collections.singletonList(alt) : new ArrayList<>(alterations), query,
                relevantTumorTypes));
        sb.append("</annotation_summary>\n");

        // gene background
        List<Evidence> geneBgEvs = evidenceBo.findEvidencesByGene(Collections.singleton(gene),
                Collections.singleton(EvidenceType.GENE_BACKGROUND));
        if (!geneBgEvs.isEmpty()) {
            Evidence ev = geneBgEvs.get(0);
            sb.append("<gene_annotation>\n");
            sb.append("    <description>");
            sb.append(StringEscapeUtils.escapeXml10(ev.getDescription()).trim());
            sb.append("</description>\n");
            exportRefereces(ev, sb, "    ");
            sb.append("</gene_annotation>\n");
        }

        if (alterations.isEmpty()) {
            sb.append("<!-- There is no information about the function of this variant in the MSKCC OncoKB. -->");
            return sb.toString();
        }

        List<Evidence> mutationEffectEbs = evidenceBo.findEvidencesByAlteration(alterations,
                Collections.singleton(EvidenceType.MUTATION_EFFECT));
        for (Evidence ev : mutationEffectEbs) {
            sb.append("<variant_effect>\n");
            sb.append("    <effect>");
            if (ev != null) {
                sb.append(ev.getKnownEffect());
            }
            sb.append("</effect>\n");
            if (ev.getDescription() != null) {
                sb.append("    <description>");
                sb.append(StringEscapeUtils.escapeXml10(ev.getDescription()).trim());
                sb.append("</description>\n");
            }
            if (ev != null) {
                exportRefereces(ev, sb, "    ");
            }

            sb.append("</variant_effect>\n");
        }

        for (String tt : tumorTypes) {
            TumorType oncoTreeType = TumorTypeUtils.getMappedOncoTreeTypesBySource(tt, "quest").get(0);
            boolean isRelevant = relevantTumorTypes.contains(oncoTreeType);

            StringBuilder sbTumorType = new StringBuilder();
            sbTumorType.append("<cancer_type type=\"").append(tt).append("\" relevant_to_patient_disease=\"")
                    .append(isRelevant ? "Yes" : "No").append("\">\n");
            int nEmp = sbTumorType.length();

            // find prognostic implication evidence blob
            Set<Evidence> prognosticEbs = new HashSet<Evidence>(evidenceBo.findEvidencesByAlteration(alterations,
                    Collections.singleton(EvidenceType.PROGNOSTIC_IMPLICATION),
                    Collections.singleton(oncoTreeType)));
            if (!prognosticEbs.isEmpty()) {
                sbTumorType.append("    <prognostic_implications>\n");
                sbTumorType.append("        <description>\n");
                for (Evidence ev : prognosticEbs) {
                    String description = ev.getDescription();
                    if (description != null) {
                        sbTumorType.append("        ").append(StringEscapeUtils.escapeXml10(description).trim())
                                .append("\n");
                    }
                }
                sbTumorType.append("</description>\n");

                for (Evidence ev : prognosticEbs) {
                    exportRefereces(ev, sbTumorType, "        ");
                }
                sbTumorType.append("    </prognostic_implications>\n");
            }

            // STANDARD_THERAPEUTIC_IMPLICATIONS
            List<Evidence> stdImpEbsSensitivity = evidenceBo.findEvidencesByAlteration(alterations,
                    Collections.singleton(EvidenceType.STANDARD_THERAPEUTIC_IMPLICATIONS_FOR_DRUG_SENSITIVITY),
                    Collections.singleton(oncoTreeType));
            List<Evidence> stdImpEbsResisitance = evidenceBo.findEvidencesByAlteration(alterations,
                    Collections.singleton(EvidenceType.STANDARD_THERAPEUTIC_IMPLICATIONS_FOR_DRUG_RESISTANCE),
                    Collections.singleton(oncoTreeType));

            //Remove level_0
            stdImpEbsSensitivity = filterLevelZeroEvidence(stdImpEbsSensitivity);

            //Remove level_R3
            stdImpEbsResisitance = filterResistanceEvidence(stdImpEbsResisitance);

            exportTherapeuticImplications(relevantTumorTypes, stdImpEbsSensitivity, stdImpEbsResisitance,
                    "standard_therapeutic_implications", sbTumorType, "    ", isRelevant);

            // INVESTIGATIONAL_THERAPEUTIC_IMPLICATIONS
            List<Evidence> invImpEbsSensitivity = evidenceBo.findEvidencesByAlteration(alterations,
                    Collections.singleton(EvidenceType.INVESTIGATIONAL_THERAPEUTIC_IMPLICATIONS_DRUG_SENSITIVITY),
                    Collections.singleton(oncoTreeType));
            List<Evidence> invImpEbsResisitance = evidenceBo.findEvidencesByAlteration(alterations,
                    Collections.singleton(EvidenceType.INVESTIGATIONAL_THERAPEUTIC_IMPLICATIONS_DRUG_RESISTANCE),
                    Collections.singleton(oncoTreeType));

            //Remove level_R3
            invImpEbsResisitance = filterResistanceEvidence(invImpEbsResisitance);

            exportTherapeuticImplications(relevantTumorTypes, invImpEbsSensitivity, invImpEbsResisitance,
                    "investigational_therapeutic_implications", sbTumorType, "    ", isRelevant);

            if (sbTumorType.length() > nEmp) {
                sbTumorType.append("</cancer_type>\n");
                sb.append(sbTumorType);
            }
        }

        return sb.toString();
    }

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testStringToSet2() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final String paths = "somepath/style.css,    /another/style2.css, ";
    LinkedHashSet<String> set = pdfStreamResult.stringToSet(paths);
    Assert.assertNotNull(set);// w  w  w .  j  a  va  2  s .c  o  m
    Assert.assertEquals(2, set.size());
    Assert.assertEquals("somepath/style.css", set.toArray()[0]);
    Assert.assertEquals("/another/style2.css", set.toArray()[1]);
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testStringToSet() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final String paths = "/somepath/style.css";
    final LinkedHashSet<String> set = pdfStreamResult.stringToSet(paths);
    Assert.assertNotNull(set);//from  www . j av a  2  s . c o m
    Assert.assertEquals(1, set.size());
    Assert.assertEquals("/somepath/style.css", set.toArray()[0]);
}

From source file:com.geewhiz.pacify.managers.FilterManager.java

private LinkedHashSet<Defect> filterPArchive(PArchive pArchive) {
    logger.info("      Customize Archive [{}]", pArchive.getRelativePath());

    LinkedHashSet<Defect> defects = new LinkedHashSet<Defect>();

    Map<PFile, File> replaceFiles = new HashMap<PFile, File>();

    for (PFile pFile : pArchive.getPFiles()) {
        logger.info("         Customize File [{}]", pFile.getRelativePath());
        logger.debug("             Filtering [{}] in archive [{}] using encoding [{}] and filter [{}]",
                pFile.getRelativePath(), pMarker.getAbsoluteFileFor(pArchive).getAbsolutePath(),
                pFile.getEncoding(), pFile.getFilterClass());

        File fileToFilter = extractFile(pArchive, pFile);
        PacifyFilter pacifyFilter = getFilterForPFile(pArchive, pFile);

        Map<String, String> propertyValues = new HashMap<String, String>();
        LinkedHashSet<Defect> propertyValueDefects = fillPropertyValuesFor(propertyValues, pFile);
        if (propertyValueDefects.size() > 0) {
            return propertyValueDefects;
        }/* w  w  w  . j a v a2  s.  c o  m*/

        String beginToken = pMarker.getBeginTokenFor(pArchive, pFile);
        String endToken = pMarker.getEndTokenFor(pArchive, pFile);
        String encoding = pFile.getEncoding();

        defects.addAll(pacifyFilter.filter(propertyValues, beginToken, endToken, fileToFilter, encoding));

        replaceFiles.put(pFile, fileToFilter);
        logger.info("             [{}] placeholders replaced.", pFile.getPProperties().size());
    }

    try {
        FileUtils.replaceFilesInArchive(pMarker, pArchive, replaceFiles);
    } catch (ArchiveDefect e) {
        defects.add(e);
    }

    for (Entry<PFile, File> entry : replaceFiles.entrySet()) {
        entry.getValue().delete();
    }

    return defects;
}

From source file:ch.unibas.fittingwizard.application.tools.charges.ChargesFileGenerator.java

public File generate(File destination, String chargesFileName, LinkedHashSet<ChargeValue> chargeValues) {
    destination.mkdir();//from w w  w. j a  va2 s.  c o  m
    if (destination == null || !destination.isDirectory()) {
        throw new IllegalArgumentException("Invalid destination directory.");
    }
    if (chargeValues == null || chargeValues.size() == 0) {
        throw new IllegalArgumentException("chargeValues are empty.");
    }

    File output = new File(destination, chargesFileName);
    output.delete();

    List<String> content = new ArrayList<>();
    for (ChargeValue chargeLine : chargeValues) {
        String line = String.format("%s_%s %s", chargeLine.getAtomTypeId().getName(), chargeLine.getType(),
                String.valueOf(chargeLine.getValue()));
        content.add(line);
    }

    try {
        FileUtils.writeLines(output, content);
    } catch (IOException e) {
        throw new RuntimeException("Could not write charges file.");
    }

    return output;
}

From source file:org.apache.cassandra.db.SystemKeyspaceTest.java

private int getDeferredDeletionCount() {
    try {/*  ww w.  j a v  a  2 s .co  m*/
        Class c = Class.forName("java.io.DeleteOnExitHook");
        LinkedHashSet<String> files = (LinkedHashSet<String>) FBUtilities.getProtectedField(c, "files").get(c);
        return files.size();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}