Example usage for java.util TreeSet iterator

List of usage examples for java.util TreeSet iterator

Introduction

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

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this set in ascending order.

Usage

From source file:org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer.java

protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer)
        throws IOException {
    final String clientId = schedule.getClientId(context);
    FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();

    TreeSet entrySet = new TreeSet();

    for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) {
        entrySet.add(new EntryWrapper((ScheduleEntry) entryIterator.next(), day));
    }//from w  w  w.j  a  v  a2  s.com

    EntryWrapper[] entries = (EntryWrapper[]) entrySet.toArray(new EntryWrapper[entrySet.size()]);

    //determine overlaps
    scanEntries(entries, 0);

    //determine the number of columns within this day
    int maxColumn = 0;

    for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) {
        EntryWrapper wrapper = (EntryWrapper) entryIterator.next();
        maxColumn = Math.max(wrapper.column, maxColumn);
    }

    int numberOfColumns = maxColumn + 1;

    //make sure the entries take up all available space horizontally
    maximizeEntries(entries, numberOfColumns);

    //now determine the width in percent of 1 column
    float columnWidth = 100 / numberOfColumns;

    //and now draw the entries in the columns
    for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) {
        EntryWrapper wrapper = (EntryWrapper) entryIterator.next();
        boolean selected = isSelected(schedule, wrapper);
        //compose the CSS style for the entry box
        StringBuffer entryStyle = new StringBuffer();
        entryStyle.append(wrapper.getBounds(schedule, columnWidth));
        String entryBorderColor = getEntryRenderer(schedule).getColor(context, schedule, wrapper.entry,
                selected);
        if (entryBorderColor != null) {
            entryStyle.append(" border-color: ");
            entryStyle.append(entryBorderColor);
            entryStyle.append(";");
        }

        if (selected) {
            writer.startElement(HTML.DIV_ELEM, schedule);
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry-selected"), null);
            writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null);

            //draw the tooltip
            if (schedule.isTooltip()) {
                getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected);
            }

            //draw the content
            getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false,
                    selected);
            writer.endElement(HTML.DIV_ELEM);
        } else {
            //if the schedule is read-only, the entries should not be
            //hyperlinks
            writer.startElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM, schedule);

            //draw the tooltip
            if (schedule.isTooltip()) {
                getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected);
            }

            if (!schedule.isReadonly()) {
                writer.writeAttribute(HTML.HREF_ATTR, "#", null);

                writer.writeAttribute(HTML.ONCLICK_ATTR, "fireEntrySelected('" + formId + "', '" + clientId
                        + "', '" + wrapper.entry.getId() + "');", null);
            }

            writer.writeAttribute(HTML.CLASS_ATTR,
                    getEntryRenderer(schedule).getEntryClass(schedule, wrapper.entry), null);
            writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null);

            //draw the content
            getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false,
                    selected);

            writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM);
        }
    }
}

From source file:org.zaproxy.zap.extension.ascanrulesBeta.SessionFixation.java

/**
 * finds and returns the cookie matching the specified cookie name from the message response.
 *
 * @param message//  w w w  . j a va2  s .  co  m
 * @param cookieName
 * @return the HtmlParameter representing the cookie, or null if no matching cookie was found
 */
private HtmlParameter getResponseCookie(HttpMessage message, String cookieName) {
    TreeSet<HtmlParameter> cookieBackParams = message.getResponseHeader().getCookieParams();
    if (cookieBackParams.size() == 0) {
        // no cookies
        return null;
    }
    for (Iterator<HtmlParameter> i = cookieBackParams.iterator(); i.hasNext();) {
        HtmlParameter tempparam = i.next();
        if (tempparam.getName().equals(cookieName)) {
            // found it. return it.
            return tempparam;
        }
    }
    // there were cookies, but none matching the name
    return null;
}

From source file:org.catechis.DomartinTest.java

public void testHashMapWithMillisecondIndex() {
    Comparator comparator = new BeanComparator("date");
    // Collections.sort(list, comparator);
    TreeSet list = new TreeSet(comparator);

    Test test0 = new Test();
    test0.setDate("Thu Aug 18 08:09:00 PST 2005");
    test0.setMilliseconds(Domartin.getMilliseconds("Thu Aug 18 08:09:00 PST 2005"));
    test0.setName("4");
    list.add(test0);/*from ww  w .  j a v a2  s  .  com*/

    Test test1 = new Test();
    test1.setDate("Wed Aug 17 08:09:00 PST 2005");
    test1.setMilliseconds(Domartin.getMilliseconds("Wed Aug 17 08:09:00 PST 2005"));
    test1.setName("3");
    list.add(test1);

    Test test2 = new Test();
    test2.setDate("Tue Aug 16 08:09:00 PST 2005");
    test2.setMilliseconds(Domartin.getMilliseconds("Tue Aug 16 08:09:00 PST 2005"));
    test2.setName("2");
    list.add(test2);

    Test test3 = new Test();
    test3.setDate("Mon Aug 15 08:09:00 PST 2005");
    test3.setMilliseconds(Domartin.getMilliseconds("Mon Aug 15 08:09:00 PST 2005"));
    test3.setName("1");
    list.add(test3);

    Test test4 = new Test();
    test4.setDate("Sun Aug 14 08:09:00 PST 2005");
    test4.setMilliseconds(Domartin.getMilliseconds("Sun Aug 14 08:09:00 PST 2005"));
    test4.setName("0");
    list.add(test4);

    //System.out.println("Hashmap with milliseconds keys -----------");
    HashMap hash = new HashMap();
    ArrayList new_list = new ArrayList();
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Test test = (Test) it.next();
        long mill = test.getMilliseconds();
        String mill_str = new String(Long.toString(mill));
        hash.put(Long.valueOf(mill_str), test);
        new_list.add(Long.valueOf(mill_str));
    }
    Collections.sort(new_list);
    StringBuffer name_buffy = new StringBuffer();
    for (int i = 0; i < new_list.size(); i++) {
        Long new_list_long = (Long) new_list.get(i);
        Test this_test = (Test) hash.get(new_list_long);
        //System.out.println(i+" "+new_list_long+" "+this_test.getDate());
        name_buffy.append(this_test.getName());
    }
    String actual_names = new String(name_buffy);
    String expected_names = new String("01234");
    assertEquals(expected_names, actual_names);
}

From source file:org.gvsig.framework.web.service.impl.OGCInfoServiceImpl.java

/**
 * Get the four coordinates that represent the bounding box
 * which includes all the layers indicated for a WMS Server
 *
 * @param urlServer Url of the WMS server to connect and get the data
 * @param crs CRS of the bounding box//  w ww . j  ava2s  . c  om
 * @param layers List of layers to include in the bounding box calculated
 * @return A list of coordinates that represents the bounding box calculated
 *         (minX, minY, maxX, maxY). null if haven't valid bounding box
 */
private List<String> getWMSLayersBoundingBox(String urlServer, String crs, TreeSet<String> layers) {
    List<String> boundingBox = new ArrayList<String>();
    double xMax = 0;
    double xMin = 0;
    double yMin = 0;
    double yMax = 0;
    BoundaryBox bbox = null;
    try {
        WMSClient wms = new WMSClient(urlServer);
        wms.connect(null);
        if (layers != null) {
            Iterator<String> iterLayers = layers.iterator();
            // get the first element
            WMSLayer layer = wms.getLayer(iterLayers.next());
            if (layer != null) {
                bbox = layer.getBbox(crs);
                if (bbox != null) {
                    xMax = bbox.getXmax();
                    yMax = bbox.getYmax();
                    xMin = bbox.getXmin();
                    yMin = bbox.getYmin();
                }
            }
            while (iterLayers.hasNext()) {
                layer = wms.getLayer(iterLayers.next());
                bbox = layer.getBbox(crs);
                if (bbox != null) {
                    // if getXmax is greater than xMax
                    if (Double.compare(xMax, bbox.getXmax()) < 0) {
                        xMax = bbox.getXmax();
                    }
                    // if getYmax is greater than yMax
                    if (Double.compare(yMax, bbox.getYmax()) < 0) {
                        yMax = bbox.getYmax();
                    }
                    // if getXmin is less than xMin
                    if (Double.compare(xMin, bbox.getXmin()) > 0) {
                        xMin = bbox.getXmin();
                    }
                    // if getYmin is less than yMin
                    if (Double.compare(yMin, bbox.getYmin()) > 0) {
                        yMin = bbox.getYmin();
                    }
                }
            }
            if (bbox != null) {
                boundingBox.add(String.valueOf(xMin));
                boundingBox.add(String.valueOf(yMin));
                boundingBox.add(String.valueOf(xMax));
                boundingBox.add(String.valueOf(yMax));
            }
        }
    } catch (Exception exc) {
        // Show exception in log and create ServerGeoException which is
        // captured on controller and puts message to ajax response
        logger.error("Exception on getWMSLayersBoundingBox", exc);
        throw new ServerGeoException();
    }
    return boundingBox;
}

From source file:org.parosproxy.paros.model.Session.java

private List<String> techListToStringList(TreeSet<Tech> techList) {
    List<String> strList = new ArrayList<>();
    Iterator<Tech> iter = techList.iterator();
    while (iter.hasNext()) {
        strList.add(iter.next().toString());
    }//from w w  w.j a v  a  2  s .  c  o  m
    return strList;
}

From source file:de.julielab.jcore.ae.lingpipegazetteer.chunking.ChunkerProviderImpl.java

private void readDictionary(InputStream dictFile) throws IOException, AnalysisEngineProcessException {
    long time = System.currentTimeMillis();
    if (useApproximateMatching) {
        dict = new TrieDictionary<String>();
    } else {// w  w  w. ja v  a  2 s.com
        dict = new MapDictionary<String>();
    }
    // now read from file and add entries
    LOGGER.info("readDictionary() - adding entries from " + dictFile + " to dictionary...");
    try (InputStreamReader isr = new InputStreamReader(dictFile)) {
        BufferedReader bf = new BufferedReader(isr);
        String line = "";
        String variant = "";
        TreeSet<String> termVariants;
        TreeSet<String> dictionary = new TreeSet<String>();

        while ((line = bf.readLine()) != null) {
            String[] values = line.split("\t");
            if (values.length != 2) {
                LOGGER.error("readDictionary() - wrong format of line: " + line);
                throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION,
                        null);
            }

            String term = values[0].trim();
            String label = values[1].trim();
            if (term.length() < MIN_TERM_LENGTH)
                continue;

            if (useApproximateMatching && !caseSensitive)
                term = term.toLowerCase();

            if (generateVariants) {
                LOGGER.debug("readDictionary() - make term variants of (" + term + ", " + label
                        + ") and add them to dictionary (NOTE: this may take a while if dictionary is big!)");
                termVariants = makeTermVariants(term);
                Iterator<String> it = termVariants.iterator();
                while (it.hasNext()) {
                    variant = it.next();
                    if (!stopWords.contains(variant.toLowerCase()) && !variant.equals("")) {
                        // System.err.println("ADDING VARIANT: " + variant + "="
                        // + label);
                        dictionary.add(variant + SEPARATOR + label);
                    }
                    // dict.addEntry(new DictionaryEntry(it.next(), label,
                    // CHUNK_SCORE));
                }
                it = null;
            } else {
                if (!stopWords.contains(term.toLowerCase()))
                    dictionary.add(term + SEPARATOR + label);
                // dict.addEntry(new DictionaryEntry(term, label, CHUNK_SCORE));
            }

            if (dictionary.size() >= 10000) {
                LOGGER.debug("readDictionary() - flushing dictionarySet to map dictionary");
                dictionary = flushDictionary(dictionary, dict);
            }

        }

        dictionary = flushDictionary(dictionary, dict);
        dictionary = null;
        time = System.currentTimeMillis() - time;
        LOGGER.info("Reading dictionary took {}ms ({}s)", time, time / 1000);
    }
}

From source file:org.zaproxy.zap.extension.compare.ExtensionCompare.java

private void compareSessions() {
    JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
    File file = null;/*from  w  ww.  j a v a2 s  .  c  o m*/
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }
            Model cmpModel = new Model();
            Session session = cmpModel.getSession();

            //log.info("opening session file " + file.getAbsolutePath());
            //WaitMessageDialog waitMessageDialog = View.getSingleton().getWaitMessageDialog("Loading session file.  Please wait ...");
            cmpModel.openSession(file, this);

            // TODO support other implementations in the future
            Database db = new ParosDatabase();
            db.open(file.getAbsolutePath());

            Map<String, String> curMap = new HashMap<>();
            Map<String, String> cmpMap = new HashMap<>();

            // Load the 2 sessions into 2 maps
            this.buildHistoryMap(Model.getSingleton().getDb().getTableHistory(), curMap);
            this.buildHistoryMap(db.getTableHistory(), cmpMap);

            File outputFile = this.getOutputFile();

            if (outputFile != null) {
                // Write the result to the specified file
                try {
                    TreeSet<String> sset = new TreeSet<>();
                    // Combine the keys for both maps
                    sset.addAll(curMap.keySet());
                    sset.addAll(cmpMap.keySet());

                    StringBuilder sb = new StringBuilder(500);
                    sb.append("<?xml version=\"1.0\"?>");
                    sb.append(CRLF);
                    sb.append("<report>");
                    sb.append(CRLF);
                    sb.append("<session-names>");
                    sb.append(CRLF);
                    sb.append("<session1>");
                    sb.append(Model.getSingleton().getSession().getSessionName());
                    sb.append("</session1>");
                    sb.append(CRLF);
                    sb.append("<session2>");
                    sb.append(session.getSessionName());
                    sb.append("</session2>");
                    sb.append(CRLF);
                    sb.append("</session-names>");
                    sb.append(CRLF);

                    Iterator<String> iter = sset.iterator();
                    while (iter.hasNext()) {
                        sb.append("<urlrow>");
                        sb.append(CRLF);
                        String key = iter.next();
                        String method = key.substring(0, key.indexOf(" "));
                        String url = key.substring(key.indexOf(" ") + 1);

                        sb.append("<method>");
                        sb.append(method);
                        sb.append("</method>");
                        sb.append(CRLF);

                        sb.append("<url>");
                        sb.append(url);
                        sb.append("</url>");
                        sb.append(CRLF);

                        sb.append("<code1>");
                        if (curMap.containsKey(key)) {
                            sb.append(curMap.get(key));
                        } else {
                            sb.append("---");
                        }
                        sb.append("</code1>");
                        sb.append(CRLF);

                        sb.append("<code2>");
                        if (cmpMap.containsKey(key)) {
                            sb.append(cmpMap.get(key));
                        } else {
                            sb.append("---");
                        }
                        sb.append("</code2>");
                        sb.append(CRLF);

                        sb.append("</urlrow>");
                        sb.append(CRLF);
                    }

                    sb.append("</report>");
                    sb.append(CRLF);

                    ReportGenerator.stringToHtml(sb.toString(), Constant.getZapInstall() + File.separator
                            + "xml" + File.separator + "reportCompare.xsl", outputFile.getAbsolutePath());

                    try {
                        DesktopUtils.openUrlInBrowser(outputFile.toURI());
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        View.getSingleton()
                                .showMessageDialog(MessageFormat.format(
                                        Constant.messages.getString("report.complete.warning"),
                                        new Object[] { outputFile.getAbsolutePath() }));
                    }

                } catch (Exception e1) {
                    log.warn(e1.getMessage(), e1);
                }
            }

            //waitMessageDialog.setVisible(true);

        } catch (Exception e) {
            log.warn(e.getMessage(), e);
        }
    }
}

From source file:com.taobao.common.tfs.impl.LocalKey.java

public int getSegmentForRead(List<SegmentData> segmentDataList, long offset, byte[] data, int start,
        int length) {
    if (offset > segmentHead.getSegmentLength()) {
        log.error("read offset over file length: " + offset + " > " + segmentHead.getSegmentLength());
        return 0;
    }//from   w  ww.j a  va2s.  c  om

    // To read, segment info SHOULD and MUST be adjacent and completed
    // but not check here ...
    SegmentInfo segmentInfo = new SegmentInfo();
    int checkLength = 0;
    int currentLength = 0;
    segmentDataList.clear();

    segmentInfo.setOffset(offset);

    TreeSet<SegmentInfo> tailInfoSet = (TreeSet<SegmentInfo>) segmentInfoSet.tailSet(segmentInfo);

    if (tailInfoSet.size() == 0 || tailInfoSet.first().getOffset() != offset) {
        TreeSet<SegmentInfo> headInfoSet = (TreeSet<SegmentInfo>) segmentInfoSet.headSet(segmentInfo);
        // should NEVER happen: queried offset less than least offset(0) in stored segment info
        if (headInfoSet.size() == 0) {
            log.error("can not find segment for offset: " + offset);
            return TfsConstant.EXIT_GENERAL_ERROR;
        }

        SegmentInfo endInfo = headInfoSet.last();
        // actually SHOULD always occur, cause adjacent and completed read segment info
        if (endInfo.getOffset() + endInfo.getLength() > offset) {
            checkLength = (int) Math.min(length, endInfo.getOffset() + endInfo.getLength() - offset);
            SegmentData segmentData = new SegmentData(endInfo);
            segmentData.setInnerOffset((int) (offset - endInfo.getOffset()));
            segmentData.setData(data, start, checkLength);

            segmentDataList.add(segmentData);
        }
    }

    // get following adjacent segment info
    Iterator it = tailInfoSet.iterator();
    while (segmentDataList.size() < ClientConfig.BATCH_COUNT && checkLength < length && it.hasNext()) {
        segmentInfo = (SegmentInfo) it.next();
        currentLength = Math.min(segmentInfo.getLength(), length - checkLength);

        SegmentData segmentData = new SegmentData(segmentInfo);
        segmentData.setData(data, start + checkLength, currentLength);

        segmentDataList.add(segmentData);
        checkLength += currentLength;
    }
    return checkLength;
}

From source file:org.unitime.timetable.model.Solution.java

public void removeDivSecNumbers(org.hibernate.Session hibSession) {
    HashSet classes = new HashSet();
    for (Iterator i = getAssignments().iterator(); i.hasNext();) {
        Assignment assignment = (Assignment) i.next();
        Class_ clazz = assignment.getClazz();
        if (clazz == null || clazz.getClassSuffix() == null)
            continue;
        classes.add(clazz);//from   w  ww . ja  v  a2 s. c o m
    }

    HashSet subparts2fix = new HashSet();

    for (Iterator i = classes.iterator(); i.hasNext();) {
        Class_ clazz = (Class_) i.next();

        clazz.setClassSuffix(null);

        subparts2fix.add(clazz.getSchedulingSubpart());

        hibSession.update(clazz);
    }

    List otherClasses = new SolutionDAO().getSession()
            .createQuery("select distinct c from Class_ c, Solution s inner join s.owner.departments d "
                    + "where s.uniqueId = :solutionId and c.managingDept=d and "
                    + "c.uniqueId not in (select a.clazz.uniqueId from s.assignments a)")
            .setLong("solutionId", getUniqueId().longValue()).list();
    for (Iterator i = otherClasses.iterator(); i.hasNext();) {
        Class_ clazz = (Class_) i.next();
        if (clazz.getClassSuffix() == null)
            continue;
        clazz.setClassSuffix(null);

        subparts2fix.add(clazz.getSchedulingSubpart());

        hibSession.update(clazz);
    }

    for (Iterator i = subparts2fix.iterator(); i.hasNext();) {
        SchedulingSubpart subpart = (SchedulingSubpart) i.next();

        TreeSet takenDivNums = new TreeSet(takenDivisionNumbers(subpart));
        int dec = 0, lastDiv = 0;

        for (Iterator j = takenDivNums.iterator(); j.hasNext();) {
            int div = ((Integer) j.next()).intValue();
            dec += (div - lastDiv - 1);
            lastDiv = div;
            if (dec > 0) {
                sLog.debug(subpart.getSchedulingSubpartLabel() + ": " + div + "->" + (div - dec));
                InstructionalOffering offering = subpart.getInstrOfferingConfig().getInstructionalOffering();
                ItypeDesc itype = subpart.getItype();
                for (Iterator i1 = offering.getInstrOfferingConfigs().iterator(); i1.hasNext();) {
                    InstrOfferingConfig cfg = (InstrOfferingConfig) i1.next();
                    for (Iterator i2 = cfg.getSchedulingSubparts().iterator(); i2.hasNext();) {
                        SchedulingSubpart s = (SchedulingSubpart) i2.next();
                        if (!s.getItype().equals(itype))
                            continue;
                        for (Iterator i3 = s.getClasses().iterator(); i3.hasNext();) {
                            Class_ clazz = (Class_) i3.next();
                            if (clazz.getClassSuffix() == null || clazz.getClassSuffix().length() != 6)
                                continue;
                            int clazzDivNum = Integer.parseInt(clazz.getClassSuffix().substring(0, 3));
                            int clazzSecNum = Integer.parseInt(clazz.getClassSuffix().substring(3, 6));
                            if (clazzDivNum == div) {
                                clazz.setClassSuffix(sSufixFormat.format(clazzDivNum - dec)
                                        + sSufixFormat.format(clazzSecNum));
                                hibSession.update(clazz);
                            }
                        }
                    }
                }

            }
        }
    }
}

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

public void exportAll(Long solverGroupId, File outFile) throws Exception {
    SolverGroup solverGroup = (new SolverGroupDAO()).get(solverGroupId);
    Session session = solverGroup.getSession();
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("export");
    root.addAttribute("solverGroup", solverGroup.getUniqueId().toString());
    root.addAttribute("solverGroupName", solverGroup.getName());
    root.addAttribute("session", session.getUniqueId().toString());
    root.addAttribute("academicYearTerm", session.getAcademicYearTerm());
    root.addAttribute("academicInitiative", session.getAcademicInitiative());
    for (Iterator i = TimePattern.findAll(session, null).iterator(); i.hasNext();) {
        TimePattern t = (TimePattern) i.next();
        exportTimePattern(root, t);/*from   w w w . j a  va  2 s.c o m*/
    }
    for (Iterator i = DatePattern.findAll(session, true, null, null).iterator(); i.hasNext();) {
        DatePattern d = (DatePattern) i.next();
        exportDatePattern(root, d);
    }
    classCmp = new Comparator() {
        public int compare(Object o1, Object o2) {
            Class_ c1 = (Class_) o1;
            Class_ c2 = (Class_) o2;
            int cmp = c1.getCourseName().compareTo(c2.getCourseName());
            if (cmp != 0)
                return cmp;
            cmp = c1.getSchedulingSubpart().getItype().getItype()
                    .compareTo(c2.getSchedulingSubpart().getItype().getItype());
            if (cmp != 0)
                return cmp;
            cmp = c1.getSchedulingSubpart().getSchedulingSubpartSuffix()
                    .compareTo(c2.getSchedulingSubpart().getSchedulingSubpartSuffix());
            if (cmp != 0)
                return cmp;
            return c1.getUniqueId().compareTo(c2.getUniqueId());
        }
    };
    TreeSet classes = new TreeSet(classCmp);
    subpartCmp = new Comparator() {
        public int compare(Object o1, Object o2) {
            SchedulingSubpart s1 = (SchedulingSubpart) o1;
            SchedulingSubpart s2 = (SchedulingSubpart) o2;
            int cmp = s1.getCourseName().compareTo(s2.getCourseName());
            if (cmp != 0)
                return cmp;
            cmp = s1.getItype().getItype().compareTo(s2.getItype().getItype());
            if (cmp != 0)
                return cmp;
            return s1.getUniqueId().compareTo(s2.getUniqueId());
        }
    };
    TreeSet subparts = new TreeSet(subpartCmp);
    ioCmp = new Comparator() {
        public int compare(Object o1, Object o2) {
            InstructionalOffering i1 = (InstructionalOffering) o1;
            InstructionalOffering i2 = (InstructionalOffering) o2;
            int cmp = i1.getCourseName().compareTo(i2.getCourseName());
            if (cmp != 0)
                return cmp;
            return i1.getUniqueId().compareTo(i2.getUniqueId());
        }
    };
    TreeSet offerings = new TreeSet(ioCmp);
    classes.addAll(solverGroup.getClasses());
    for (Iterator i = classes.iterator(); i.hasNext();) {
        Class_ c = (Class_) i.next();
        exportClass(root, c);
        SchedulingSubpart s = c.getSchedulingSubpart();
        offerings.add(s.getInstrOfferingConfig().getInstructionalOffering());
        if (solverGroup.getDepartments().contains(s.getManagingDept())) {
            subparts.add(s);
        }
    }
    for (Iterator i = subparts.iterator(); i.hasNext();) {
        SchedulingSubpart s = (SchedulingSubpart) i.next();
        exportSchedulingSubpart(root, s);
    }
    for (Iterator i = offerings.iterator(); i.hasNext();) {
        InstructionalOffering io = (InstructionalOffering) i.next();
        exportInstructionalOffering(root, io);
    }
    for (Iterator i = solverGroup.getDepartments().iterator(); i.hasNext();) {
        Department d = (Department) i.next();
        exportInstructors(root, d);
    }
    for (Iterator i = solverGroup.getDistributionPreferences().iterator(); i.hasNext();) {
        DistributionPref d = (DistributionPref) i.next();
        exportDistributionPref(root, d);
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outFile);
        (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document);
        fos.flush();
        fos.close();
        fos = null;
    } finally {
        try {
            if (fos != null)
                fos.close();
        } catch (IOException e) {
        }
    }
}