Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

In this page you can find the example usage for java.util Collection toArray.

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this collection.

Usage

From source file:it.cnr.isti.labsedc.glimpse.rules.DroolsRulesManager.java

public static void unloadRule(String ruleName) {

    Collection<KnowledgePackage> ass = kbase.getKnowledgePackages();
    Object esd[] = ass.toArray();
    for (int i = 0; i < esd.length; i++) {

        KnowledgePackage kp = (KnowledgePackage) esd[i];
        Collection<Rule> rls = kp.getRules();
        Object r[] = rls.toArray();
        DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getCanonicalName(),
                "KnowledgeBase name: " + kp.getName());
        if (r.length > 0) {
            for (int j = 0; j < r.length; j++) {
                Rule gg = (Rule) r[j];/*from w w w  .  j a v  a2s .c  o  m*/
                if (gg.getName().compareTo(ruleName) == 0) {
                    kbase.removeRule(kp.getName(), gg.getName());
                }
            }
        }
    }
    DroolsRulesManager.getLoadedRulesInfo();
}

From source file:it.cnr.isti.labsedc.glimpse.rules.DroolsRulesManager.java

public static void getLoadedRulesInfo() {
    DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getCanonicalName(),
            "Listing rules loaded into the knowledgeBases");
    Collection<KnowledgePackage> ass = kbase.getKnowledgePackages();
    Object esd[] = ass.toArray();
    for (int i = 0; i < esd.length; i++) {

        KnowledgePackage kp = (KnowledgePackage) esd[i];
        Collection<Rule> rls = kp.getRules();
        Object r[] = rls.toArray();
        DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getCanonicalName(),
                "KnowledgeBase name: " + kp.getName());
        if (r.length == 0) {
            DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getCanonicalName(),
                    "--! No rules loaded into: " + kp.getName() + " knowledgeBase");
        } else {//from   w  w w.j  a  va  2 s.  co m
            for (int j = 0; j < r.length; j++) {
                Rule gg = (Rule) r[j];
                DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getCanonicalName(),
                        "RuleName: " + gg.getName());
            }
        }
    }
}

From source file:eu.learnpad.simulator.mon.rules.DroolsRulesManager.java

public static void unloadRule(String ruleName) {

    Collection<KnowledgePackage> ass = kbase.getKnowledgePackages();
    Object esd[] = ass.toArray();
    for (int i = 0; i < esd.length; i++) {

        KnowledgePackage kp = (KnowledgePackage) esd[i];
        Collection<Rule> rls = kp.getRules();
        Object r[] = rls.toArray();
        DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getSimpleName(),
                "KnowledgeBase name: " + kp.getName());
        if (r.length > 0) {
            for (int j = 0; j < r.length; j++) {
                Rule gg = (Rule) r[j];/*from w w  w .j  a v a2s .  c  om*/
                if (gg.getName().compareTo(ruleName) == 0) {
                    kbase.removeRule(kp.getName(), gg.getName());
                }
            }
        }
    }
    DroolsRulesManager.getLoadedRulesInfo();
}

From source file:eu.learnpad.simulator.mon.rules.DroolsRulesManager.java

public static void getLoadedRulesInfo() {
    DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getSimpleName(),
            "Listing rules loaded into the knowledgeBases");
    Collection<KnowledgePackage> ass = kbase.getKnowledgePackages();
    Object esd[] = ass.toArray();
    for (int i = 0; i < esd.length; i++) {

        KnowledgePackage kp = (KnowledgePackage) esd[i];
        Collection<Rule> rls = kp.getRules();
        Object r[] = rls.toArray();
        DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getSimpleName(),
                "KnowledgeBase name: " + kp.getName());
        if (r.length == 0) {
            DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getSimpleName(),
                    "--! No rules loaded into: " + kp.getName() + " knowledgeBase");
        } else {/*from  www  .j  a  v  a 2 s  .co m*/
            for (int j = 0; j < r.length; j++) {
                Rule gg = (Rule) r[j];
                DebugMessages.println(TimeStamp.getCurrentTime(), DroolsRulesManager.class.getSimpleName(),
                        "RuleName: " + gg.getName());
            }
        }
    }
}

From source file:org.gw2InfoViewer.factories.HttpsConnectionFactory.java

public static Certificate[] convertByteArrayToCertificate(byte[] sslCertificate) throws CertificateException {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    Collection c = cf.generateCertificates(new ByteArrayInputStream(sslCertificate));
    Certificate[] certs;//  w  w w.java 2  s. c o  m
    certs = new Certificate[c.toArray().length];
    if (c.size() == 1) {
        InputStream certstream = new ByteArrayInputStream(sslCertificate);
        Certificate cert = cf.generateCertificate(certstream);
        certs[0] = cert;
    } else {
        certs = (Certificate[]) c.toArray();
    }

    return certs;
}

From source file:gov.nih.nci.ispy.web.reports.quick.QuickReporterReport.java

public static StringBuffer quickReporterReport(List<String> reporters, String session, String taskId) {
    StringBuffer html = new StringBuffer();
    Document document = DocumentHelper.createDocument();
    Element table = document.addElement("table").addAttribute("id", "reportTable").addAttribute("class",
            "report");
    Element tr = null;//from  ww w.  j a v  a 2  s .  c o m
    Element td = null;

    tr = table.addElement("tr").addAttribute("class", "header");
    td = tr.addElement("td").addAttribute("class", "header").addText("Reporter");
    td = tr.addElement("td").addAttribute("class", "header").addText("Gene Symbol");
    td = tr.addElement("td").addAttribute("class", "header").addText("GenBank AccId");
    td = tr.addElement("td").addAttribute("class", "header").addText("LocusLink");

    if (reporters != null) {
        try {
            GeneExprAnnotationService geService = GeneExprAnnotationServiceFactory.getInstance();

            List<ReporterAnnotation> reporterAnnotations = geService.getAnnotationsListForReporters(reporters);
            for (ReporterAnnotation reporterAnnotation : reporterAnnotations) {
                if (reporterAnnotation != null) {

                    tr = table.addElement("tr").addAttribute("class", "data");

                    //String reporter = reporterAnnotation.getReporter()!=null ? reporterAnnotation.getReporter().getValue().toString() : "N/A";
                    td = tr.addElement("td").addText(reporterAnnotation.getReporterId());
                    //html.append("ReporterID :" +reporterResultset.getReporter().getValue().toString() + "<br/>");
                    Collection<String> geneSymbols = (Collection<String>) reporterAnnotation.getGeneSymbols();
                    String genes = "";
                    if (geneSymbols != null) {
                        genes = StringUtils.join(geneSymbols.toArray(), ",");
                    }
                    if (!genes.equals("")) {
                        td = tr.addElement("td").addText(genes).addAttribute("class", "gene")
                                .addAttribute("name", "gene").addAttribute("id", genes).addElement("input")
                                .addAttribute("type", "checkbox").addAttribute("name", "checkable")
                                .addAttribute("class", "saveElement").addAttribute("value", genes);
                    } else {
                        td = tr.addElement("td").addText(genes).addAttribute("class", "gene")
                                .addAttribute("name", "gene").addAttribute("id", genes);
                    }
                    Collection<String> genBank_AccIDS = (Collection<String>) reporterAnnotation
                            .getGenbankAccessions();
                    String accs = "";
                    if (genBank_AccIDS != null) {
                        accs = StringUtils.join(genBank_AccIDS.toArray(), ",");
                    }

                    td = tr.addElement("td").addText(accs);

                    Collection<String> locusLinkIDs = (Collection<String>) reporterAnnotation.getLocusLinkIds();
                    String ll = "";
                    if (locusLinkIDs != null) {
                        ll = StringUtils.join(locusLinkIDs.toArray(), ",");
                    }

                    td = tr.addElement("td").addText(ll);
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //return html;
    return html.append(document.asXML());
}

From source file:OAT.ui.util.UiUtil.java

public static void fillCombo(JComboBox comboBox, Collection items) {
    comboBox.setModel(new DefaultComboBoxModel(items.toArray()));
}

From source file:com.sunchenbin.store.feilong.core.util.MapUtil.java

/**
 * map,keys,? value ?.//from   w  w w  . j a  va 2  s .c om
 * 
 * @param <K>
 *            the key type
 * @param <T>
 *            the generic type
 * @param map
 *            map
 * @param keys
 *            key
 * @return  keys key ? map  ,null
 * @see java.util.Collection#toArray()
 * @see java.util.Arrays#sort(Object[])
 */
@SuppressWarnings("unchecked")
public static <K, T extends Number> T getMinValue(Map<K, T> map, K[] keys) {
    Map<K, T> subMap = getSubMap(map, keys);

    if (null == subMap) {
        return null;
    }

    Collection<T> values = subMap.values();
    Object[] array = values.toArray();
    Arrays.sort(array);
    return (T) array[0];
}

From source file:eu.wordnice.wnconsole.WNCUtils.java

public static Object checkYaml(Object in) {
    if (in instanceof Configuration) {
        return WNCUtils.YamlToMap((Configuration) in);
    } else if (in instanceof Map<?, ?>) {
        Map<String, Object> retv = new Map<String, Object>();
        java.util.Map<?, ?> inm = (java.util.Map<?, ?>) in;
        java.util.Set<?> keys = inm.keySet();
        int size = keys.size();
        Object[] keys_arr = keys.toArray();
        Object key = null;/*from   www.j  av a2 s  .  c  o m*/
        int i = 0;
        for (; i < size; i++) {
            key = keys_arr[i];
            retv.addWC(("" + key), WNCUtils.checkYaml(inm.get(key)));
        }
        return retv;
    } else if (in instanceof Collection<?>) {
        Set<Object> retv = new Set<Object>();
        Collection<?> inc = (Collection<?>) in;
        int size = inc.size();
        Object[] keys_arr = inc.toArray();
        int i = 0;
        for (; i < size; i++) {
            retv.addWC(WNCUtils.checkYaml(keys_arr[i]));
        }
        return retv;
    }
    return in;
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step9AgreementCollector.java

@SuppressWarnings("unchecked")
public static void computeObservedAgreement(File goldDataFolder, File outputDir) throws Exception {
    // iterate over query containers
    for (File f : FileUtils.listFiles(goldDataFolder, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {

            // only non-empty and annotated results
            // No annotations found for document: clueWebID: clueweb12-1407wb-22-10643, queryID: 1006
            // <clueWebID>clueweb12-1407wb-22-10643</clueWebID>
            // <score>5.93809186</score>
            // <additionalInfo>indri</additionalInfo>
            // <plainText></plainText>

            if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) {
                if (rankedResult.mTurkRelevanceVotes.isEmpty()) {
                    //                        throw new IllegalStateException("No annotations found for document: "
                    System.err.println("No annotations found for document: " + "clueWebID: "
                            + rankedResult.clueWebID + ", queryID: " + queryResultContainer.qID);
                } else {

                    // first, get all the sentence IDs
                    byte[] bytes = new BASE64Decoder()
                            .decodeBuffer(new ByteArrayInputStream(rankedResult.originalXmi.getBytes()));

                    JCas jCas = JCasFactory.createJCas();
                    XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas());

                    // for each sentence, we'll collect all its annotations
                    TreeMap<Integer, SortedMap<String, String>> sentencesAndRelevanceAnnotations = collectSentenceIDs(
                            jCas);/*w w w . j a va 2  s  .com*/

                    // now we will the map with mturk annotations
                    // the list of true/false for each sentence will be consistent (the annotator ordering remains)
                    for (QueryResultContainer.MTurkRelevanceVote mTurkRelevanceVote : rankedResult.mTurkRelevanceVotes) {
                        for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : mTurkRelevanceVote.singleSentenceRelevanceVotes) {

                            String sentenceIDString = sentenceRelevanceVote.sentenceID;
                            if (sentenceIDString == null || sentenceIDString.isEmpty()) {
                                throw new IllegalStateException("Empty sentence ID for turker "
                                        + mTurkRelevanceVote.turkID + ", HIT: " + mTurkRelevanceVote.hitID
                                        + ", clueWebID: " + rankedResult.clueWebID + ", queryID: "
                                        + queryResultContainer.qID);
                            } else {

                                Integer sentenceIDInt = Integer.valueOf(sentenceIDString);
                                String value = sentenceRelevanceVote.relevant;

                                // add to the list

                                // sanity check first
                                if (sentencesAndRelevanceAnnotations.get(sentenceIDInt)
                                        .containsKey(mTurkRelevanceVote.turkID)) {
                                    System.err.println("Annotations for sentence " + sentenceIDInt
                                            + " for turker " + mTurkRelevanceVote.turkID + " are duplicate");
                                }

                                sentencesAndRelevanceAnnotations.get(sentenceIDInt)
                                        .put(mTurkRelevanceVote.turkID, value);
                            }
                        }
                    }

                    //                    for (Map.Entry<Integer, SortedMap<String, String>> entry : sentencesAndRelevanceAnnotations
                    //                            .entrySet()) {
                    //                        System.out.println(entry.getKey() + ": " + entry.getValue());
                    //                    }

                    // we collect only the "clean" ones
                    Map<Integer, SortedMap<String, String>> cleanSentencesAndRelevanceAnnotations = new HashMap<>();

                    // sanity check -- all sentences are covered with the same number of annotations
                    for (Map.Entry<Integer, SortedMap<String, String>> entry : sentencesAndRelevanceAnnotations
                            .entrySet()) {
                        SortedMap<String, String> singleSentenceAnnotations = entry.getValue();

                        // remove empty sentences
                        if (singleSentenceAnnotations.values().isEmpty()) {
                            //                                throw new IllegalStateException(
                            System.err.println("Empty annotations for sentence, " + "sentenceID: "
                                    + entry.getKey() + ", " + "clueWebID: " + rankedResult.clueWebID
                                    + ", queryID: " + queryResultContainer.qID + "; number of assignments: "
                                    + singleSentenceAnnotations.values().size() + ", expected: "
                                    + NUMBER_OF_TURKERS_PER_HIT + ". Sentence will be skipped in evaluation");
                        } else if (singleSentenceAnnotations.values().size() != NUMBER_OF_TURKERS_PER_HIT) {
                            System.err.println("Inconsistent annotations for sentences, " + "sentenceID: "
                                    + entry.getKey() + ", " + "clueWebID: " + rankedResult.clueWebID
                                    + ", queryID: " + queryResultContainer.qID + "; number of assignments: "
                                    + singleSentenceAnnotations.values().size() + ", expected: "
                                    + NUMBER_OF_TURKERS_PER_HIT + ". Sentence will be skipped in evaluation");
                        } else {
                            cleanSentencesAndRelevanceAnnotations.put(entry.getKey(), entry.getValue());
                        }
                    }

                    // fill the annotation study

                    CodingAnnotationStudy study = new CodingAnnotationStudy(NUMBER_OF_TURKERS_PER_HIT);
                    study.addCategory("true");
                    study.addCategory("false");

                    for (SortedMap<String, String> singleSentenceAnnotations : cleanSentencesAndRelevanceAnnotations
                            .values()) {
                        // only non-empty sentences
                        Collection<String> values = singleSentenceAnnotations.values();
                        if (!values.isEmpty() && values.size() == NUMBER_OF_TURKERS_PER_HIT) {
                            study.addItemAsArray(values.toArray());
                        }

                    }

                    //                    System.out.println(study.getCategories());

                    // Fleiss' multi-pi.
                    FleissKappaAgreement fleissKappaAgreement = new FleissKappaAgreement(study);

                    double percentage;
                    try {
                        percentage = fleissKappaAgreement.calculateObservedAgreement();
                    } catch (InsufficientDataException ex) {
                        // dkpro-statistics feature, see https://github.com/dkpro/dkpro-statistics/issues/24
                        percentage = 1.0;
                    }

                    if (!Double.isNaN(percentage)) {
                        rankedResult.observedAgreement = percentage;
                        //                        System.out.println(sentencesAndRelevanceAnnotations.values());
                    } else {
                        System.err.println("Observed agreement is NaN.");
                    }
                }
            }
        }

        // and save the query to output dir
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }
}