Example usage for java.util TreeSet addAll

List of usage examples for java.util TreeSet addAll

Introduction

In this page you can find the example usage for java.util TreeSet addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set.

Usage

From source file:org.mda.bcb.tcgagsdata.create.ReadPlatform.java

public void readPlatform(String thePlatform) throws IOException, Exception {
    TcgaGSData.printWithFlag("readPlatform for " + thePlatform + " beginning");
    TcgaGSData.printWithFlag("readPlatform can consume excessive amounts of time and memory");
    mNumberOfGenes = 0;/*from   ww w  .  j a v  a2s .c  o m*/
    TreeMap<String, Integer> geneMap = null;
    {
        ReadPlatform_GeneEq lg = new ReadPlatform_GeneEq(mReadPath);
        lg.getNamesGenes(thePlatform);
        mGenes = lg.mGenes;
        geneMap = TcgaGSData.buildIndexMap(lg.mGenes);
        mNumberOfGenes = lg.mSize;
    }
    mNumberOfSamples = 0;
    boolean found = false;
    long start = System.currentTimeMillis();
    TreeSet<File> dataFileList = new TreeSet<>();
    dataFileList.addAll(FileUtils.listFiles(new File(mReadPath, thePlatform),
            new WildcardFileFilter("matrix_data_*.tsv"), TrueFileFilter.INSTANCE));
    for (File input : dataFileList) {
        try (BufferedReader br = Files.newBufferedReader(Paths.get(input.getAbsolutePath()),
                Charset.availableCharsets().get("ISO-8859-1"))) {
            found = true;
            TcgaGSData.printWithFlag("readPlatform file=" + input.getAbsolutePath());
            // first line samples
            String line = br.readLine();
            TreeMap<String, Integer> sampleMap = TcgaGSData
                    .buildIndexMap(GSStringUtils.afterTab(line).split("\t", -1));
            if (0 == mNumberOfSamples) {
                mSamples = GSStringUtils.afterTab(line).split("\t", -1);
                mNumberOfSamples = mSamples.length;
                mGenesBySamplesValues = new double[mNumberOfGenes][mNumberOfSamples];
            } else {
                if (mNumberOfSamples != GSStringUtils.afterTab(line).split("\t", -1).length) {
                    throw new Exception("Expected sample count of " + mNumberOfSamples + " but found different "
                            + input.getAbsolutePath());
                }
            }
            line = br.readLine();
            while (null != line) {
                String gene = GSStringUtils.beforeTab(line);
                Integer intIndex = geneMap.get(gene);
                if (null != intIndex) {
                    int geneIndex = intIndex;
                    double[] valueList = convertToDouble(GSStringUtils.afterTab(line).split("\t", -1));
                    for (int x = 0; x < valueList.length; x++) {
                        int sampleIndex = sampleMap.get(mSamples[x]);
                        mGenesBySamplesValues[geneIndex][sampleIndex] = valueList[x];
                    }
                } else {
                    throw new Exception(
                            "readPlatform for " + thePlatform + " found unexpected 'gene' = " + gene);
                }
                line = br.readLine();
            }
        }
    }
    long finish = System.currentTimeMillis();
    TcgaGSData.printWithFlag(
            "readPlatform for " + thePlatform + " retrieved in " + ((finish - start) / 1000.0) + " seconds");
    if (false == found) {
        throw new Exception("readPlatform for " + thePlatform + " not found");
    } else {
        TcgaGSData.printWithFlag("write " + thePlatform + " to " + mWriteFile);
        writeFile();
    }
}

From source file:org.unitime.timetable.test.StudentSectioningTest.java

private static Course loadCourse(CourseOffering co, long studentId) {
    sLog.debug("  -- loading " + co.getCourseName());
    Offering offering = new Offering(co.getInstructionalOffering().getUniqueId().longValue(),
            co.getInstructionalOffering().getCourseName());
    int projected = (co.getProjectedDemand() == null ? 0 : co.getProjectedDemand().intValue());
    int courseLimit = co.getInstructionalOffering().getLimit().intValue();
    if (co.getReservation() != null)
        courseLimit = co.getReservation();
    Course course = new Course(co.getUniqueId().longValue(), co.getSubjectAreaAbbv(), co.getCourseNbr(),
            offering, courseLimit, projected);
    Hashtable class2section = new Hashtable();
    Hashtable ss2subpart = new Hashtable();
    for (Iterator i = co.getInstructionalOffering().getInstrOfferingConfigs().iterator(); i.hasNext();) {
        InstrOfferingConfig ioc = (InstrOfferingConfig) i.next();
        Config config = new Config(ioc.getUniqueId().longValue(),
                (ioc.isUnlimitedEnrollment() ? -1 : ioc.getLimit()),
                ioc.getCourseName() + " [" + ioc.getName() + "]", offering);
        TreeSet subparts = new TreeSet(new SchedulingSubpartComparator());
        subparts.addAll(ioc.getSchedulingSubparts());
        for (Iterator j = subparts.iterator(); j.hasNext();) {
            SchedulingSubpart ss = (SchedulingSubpart) j.next();
            String sufix = ss.getSchedulingSubpartSuffix();
            Subpart parentSubpart = (ss.getParentSubpart() == null ? null
                    : (Subpart) ss2subpart.get(ss.getParentSubpart()));
            Subpart subpart = new Subpart(ss.getUniqueId().longValue(),
                    ss.getItype().getItype().toString() + sufix,
                    ss.getItypeDesc().trim() + (sufix == null || sufix.length() == 0 ? "" : " (" + sufix + ")"),
                    config, parentSubpart);
            subpart.setAllowOverlap(ss.isStudentAllowOverlap());
            ss2subpart.put(ss, subpart);
            for (Iterator k = ss.getClasses().iterator(); k.hasNext();) {
                Class_ c = (Class_) k.next();
                Assignment a = c.getCommittedAssignment();
                int usedSpace = 0;
                if (studentId >= 0)
                    for (Iterator l = c.getStudentEnrollments().iterator(); l.hasNext();) {
                        StudentClassEnrollment sce = (StudentClassEnrollment) l.next();
                        if (Long.parseLong(sce.getStudent().getExternalUniqueId()) != studentId)
                            usedSpace++;
                    }//from  ww w .  ja va  2 s  .co  m
                /*
                Number usedSpace = (Number)new Class_DAO().getSession().createQuery(
                    "select count(sce) from StudentClassEnrollment sce where " +
                    "sce.clazz.uniqueId=:classId and sce.student.externalUniqueId!=:studentId").
                    setLong("classId", c.getUniqueId()).
                    setLong("studentId", studentId).uniqueResult();
                if (studentId<0) usedSpace = new Integer(0);
                */
                int limit = c.getClassLimit() - usedSpace;
                if (ioc.isUnlimitedEnrollment().booleanValue())
                    limit = -1;
                Section parentSection = (c.getParentClass() == null ? null
                        : (Section) class2section.get(c.getParentClass()));
                Section section = new Section(c.getUniqueId().longValue(), limit, c.getClassLabel(), subpart,
                        (a == null ? null : a.getPlacement()), getInstructorIds(c), getInstructorNames(c),
                        parentSection);
                if (c.getSectioningInfo() != null) {
                    section.setSpaceExpected(c.getSectioningInfo().getNbrExpectedStudents().doubleValue());
                    section.setSpaceHeld(c.getSectioningInfo().getNbrHoldingStudents().doubleValue());
                    section.setPenalty(getPenalty(section, c, studentId));
                }
                class2section.put(c, section);
                sLog.debug("    -- section " + section);
            }
        }
    }
    return course;
}

From source file:controllerTas.actions.gnuplot.ThroughputPlotter.java

public void produceDataFile(PlottableData data, String name, String extension) {
    try {//from   w ww  .  ja  v a  2  s  . co  m
        PrintWriter pw = new PrintWriter(
                new FileWriter(new File(slashedPath(dataPath) + name + "." + extension)));
        String header = header(data.getHeader());
        pw.println(header);
        TreeSet<PlottableDataLine> set = new TreeSet<PlottableDataLine>(new LineComparator());
        set.addAll(data.getLines());
        int lastNodes = -1, newNodes;
        for (PlottableDataLine l : set) {
            newNodes = l.getScale().getNumNodes();
            if (newNodes(lastNodes, newNodes))
                pw.println("");
            lastNodes = newNodes;
            log.trace("Writing " + l.toString());
            pw.println(line(l));
        }
        pw.flush();
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.alfresco.web.forms.xforms.SchemaUtil.java

private static void buildTypeTree(final XSTypeDefinition type, final TreeSet<XSTypeDefinition> descendents,
        final TreeMap<String, TreeSet<XSTypeDefinition>> typeTree) {
    if (type == null) {
        return;/*from  ww  w  .  j  av  a 2  s .  co m*/
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("buildTypeTree(" + type.getName() + ", " + descendents.size() + " descendents)");
    if (descendents.size() > 0) {
        TreeSet<XSTypeDefinition> compatibleTypes = typeTree.get(type.getName());

        if (compatibleTypes == null) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("no compatible types found for " + type.getName() + ", creating a new set");
            compatibleTypes = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER);
            typeTree.put(type.getName(), compatibleTypes);
        }
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("adding " + descendents.size() + " descendents to " + type.getName());
        compatibleTypes.addAll(descendents);
    }

    final XSTypeDefinition parentType = type.getBaseType();
    if (parentType == null || type.getTypeCategory() != parentType.getTypeCategory()) {
        return;
    }

    if (type != parentType && parentType.getName() != null && !parentType.getName().equals("anyType")) {
        TreeSet<XSTypeDefinition> newDescendents = typeTree.get(parentType.getName());
        if (newDescendents == null) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("type tree doesn't contain " + parentType.getName()
                        + ", creating a new descendant set");
            newDescendents = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER);
        }
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("adding " + descendents.size() + " descendants to existing " + newDescendents.size()
                    + " descendants of " + parentType.getName());
        newDescendents.addAll(descendents);

        //extension (we only add it to "newDescendants" because we don't want
        //to have a type descendant to itself, but to consider it for the parent
        if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition) type;
            if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION
                    && !complexType.getAbstract() && !descendents.contains(type)) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("adding " + type.getName() + " to existing " + newDescendents.size()
                            + " descendents of " + parentType.getName());
                newDescendents.add(type);
            }
        }

        //note: extensions are impossible on simpleTypes !
        SchemaUtil.buildTypeTree(parentType, newDescendents, typeTree);
    }
}

From source file:com.webbfontaine.valuewebb.navigation.RetrievedDocuments.java

/**
 * Orders conversations, the last element is the oldest.
 *
 * @return ordered Set where last element is oldest conversation
 * @see org.jboss.seam.faces.Switcher#createSelectItems()
 *///from ww w . java  2 s  . c o  m
public TreeSet<ConversationEntry> order() {
    ConversationEntries conversationEntries = ConversationEntries.getInstance();
    if (conversationEntries == null) {
        return null;
    }

    TreeSet<ConversationEntry> orderedEntries = new TreeSet<ConversationEntry>();
    orderedEntries.addAll(conversationEntries.getConversationEntries());
    return orderedEntries;
}

From source file:net.krautchan.data.KCThread.java

public synchronized Set<KCPosting> getSortedPostings() {
    TreeSet<KCPosting> s = new TreeSet<KCPosting>();
    s.addAll(postings.values());
    return s;/*www  . ja  va 2s .c  om*/
}

From source file:com.samples.platform.service.common.GetServiceStatusOperation.java

/**
 * @param message/*  w w  w .j a v a2 s .  com*/
 *            the {@link JAXBElement} containing a
 *            {@link GetServiceStatusRequestType}.
 * @return the {@link JAXBElement} with a
 *         {@link GetServiceStatusResponseType}.
 */
@InsightEndPoint
@ServiceActivator
public final JAXBElement<GetServiceStatusResponseType> getServiceStatus(
        final JAXBElement<GetServiceStatusRequestType> message) {
    this.logger.debug("+getServiceStatus");
    GetServiceStatusResponseType response = this.of.createGetServiceStatusResponseType();
    try {
        PropertyType p;
        ClassLoader cl;
        URL[] urls;
        ClassLoader sysCl = ClassLoader.getSystemClassLoader();

        response.setStatus("Service is available");

        /* System properties */
        p = new PropertyType();
        p.setName("System Properties");
        response.getDetails().add(p);
        TreeSet<String> propertyNames = new TreeSet<String>();
        propertyNames.addAll(System.getProperties().stringPropertyNames());
        for (String propertyName : propertyNames) {
            p.getValue().add(new StringBuffer(64).append(propertyName).append("=")
                    .append(System.getProperty(propertyName)).toString());
        }

        /* Application properties. */
        p = new PropertyType();
        p.setName("Application loaded properties");
        response.getDetails().add(p);
        propertyNames.clear();
        propertyNames.addAll(this.properties.stringPropertyNames());
        for (String propertyName : propertyNames) {
            p.getValue().add(new StringBuffer(64).append(propertyName).append("=")
                    .append(this.properties.getProperty(propertyName)).toString());
        }

        /* Current lass loader */
        cl = this.getClass().getClassLoader();
        p = new PropertyType();
        p.setName("This ClassLoader");
        response.getDetails().add(p);
        p.getValue().add(cl.getClass().getName());
        if (URLClassLoader.class.isInstance(cl)) {
            urls = ((URLClassLoader) cl).getURLs();
            p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString());
            for (URL url : urls) {
                p.getValue().add(url.toString());
            }
        }
        cl = cl.getParent();
        while (cl != sysCl) {
            p = new PropertyType();
            p.setName("Parent Classloader");
            response.getDetails().add(p);
            p.getValue().add(cl.getClass().getName());
            if (URLClassLoader.class.isInstance(cl)) {
                urls = ((URLClassLoader) cl).getURLs();
                p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString());
                for (URL url : urls) {
                    p.getValue().add(url.toString());
                }
            }
            cl = cl.getParent();
        }

        /* System class loader */
        cl = sysCl;
        p = new PropertyType();
        p.setName("SystemClassLoader");
        response.getDetails().add(p);
        p.getValue().add(cl.getClass().getName());
        if (URLClassLoader.class.isInstance(cl)) {
            urls = ((URLClassLoader) cl).getURLs();
            p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString());
            for (URL url : urls) {
                p.getValue().add(url.toString());
            }
        }
    } catch (Throwable e) {
        this.logger.error(e.getMessage(), e);
    } finally {
        this.logger.debug("-getServiceStatus #{}, #f{}", response/* .get() */ != null ? 1 : 0,
                response.getFailure().size());
    }
    return this.of.createGetServiceStatusResponse(response);
}

From source file:org.jamocha.dn.ConflictSet.java

private TreeSet<RuleAndToken> correctStrategy(final Integer salience, final TreeSet<RuleAndToken> ratSet) {
    if (this.conflictResolutionStrategy == ratSet.comparator())
        return ratSet;
    // if wrong comparator was used, create new set and copy the values
    final TreeSet<RuleAndToken> newRatSet = new TreeSet<>(this.conflictResolutionStrategy);
    newRatSet.addAll(ratSet);
    this.rulesAndTokensBySalience.put(salience, newRatSet);
    return newRatSet;
}

From source file:org.apache.asterix.common.config.ConfigUsageTest.java

protected Set<Section> getSections(ConfigManager configManager) {
    TreeSet<Section> sections = new TreeSet<>(Comparator.comparing(Section::sectionName));
    sections.addAll(configManager.getSections());
    sections.remove(Section.LOCALNC);//from   ww  w  . j  ava 2  s. com
    return sections;
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java

/**
 * @param serviceDescription ServiceDescription
 * @return Set of Packages// w  w w .  j  a va  2 s  .com
 */
public static TreeSet<String> getPackagesFromAnnotations(ServiceDescription serviceDesc,
        MarshalServiceRuntimeDescription msrd) {
    if (log.isDebugEnabled()) {
        log.debug("start getPackagesFromAnnotations");
        log.debug("ServiceDescription = " + serviceDesc.toString());
        log.debug("MarshalServiceRuntimeDescription = " + msrd.toString());
    }
    TreeSet<String> set = new TreeSet<String>();
    Collection<EndpointDescription> endpointDescs = serviceDesc.getEndpointDescriptions_AsCollection();

    // Build a set of packages from all of the endpoints
    if (endpointDescs != null) {
        for (EndpointDescription endpointDesc : endpointDescs) {
            set.addAll(getPackagesFromAnnotations(endpointDesc, msrd));
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("end getPackagesFromAnnotations");
    }
    return set;
}