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:com.symbian.utils.config.ConfigUtils.java

/**
 * Print the Configuration setting/*from www. j  ava  2 s . c om*/
 * 
 * @param aLogger
 *            If <code>true</code> then prints to logger, else if
 *            <code>false</code> then prints to STDOUT.
 * @throws IOException
 */
public void printConfig(final boolean aLogger) throws IOException {
    try {

        StringBuffer lOutput = new StringBuffer();

        lOutput.append("\n");

        TreeSet<String> sortedKeys = new TreeSet<String>();
        sortedKeys.addAll(iSavedConfig.keySet());

        //sortedKeys.addAll(Arrays.asList(iPrefrences.keys()));

        for (Iterator lConfigIter = sortedKeys.iterator(); lConfigIter.hasNext();) {
            String lKey = (String) lConfigIter.next();
            //for lite version enhancement. Depreciate "sysbin", instead use "statLite"
            if (lKey.equalsIgnoreCase("platsec")) //PlatSec will not be used and should not be displayed to user
                continue;
            String lKeyDisplayName = lKey.equalsIgnoreCase("sysbin") ? "statlite" : lKey;
            String lMessage = "Preference " + lKeyDisplayName + ":"
                    + (lKeyDisplayName.length() < 12 ? "\t\t" : "\t") + iSavedConfig.get(lKey);
            if (aLogger) {
                lOutput.append(lMessage + "\n");
            } else {
                System.out.println(lMessage);
            }
        }

        if (aLogger) {
            LOGGER.info(lOutput.toString());
        }

    } catch (SecurityException lSecurityException) {
        throw new IOException("Security exception: " + lSecurityException.getMessage());
    }
}

From source file:org.jboss.dashboard.ui.config.components.sections.SectionCopyFormatter.java

public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException {

    try {/*from  www . jav  a 2s  . co m*/
        WorkspaceImpl workspace = (WorkspaceImpl) getSectionsPropertiesHandler().getWorkspace();
        setAttribute("sectionTitle", getLocalizedValue(workspace
                .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId())).getTitle()));
        renderFragment("outputStart");

        WorkspacePermission sectionPerm = WorkspacePermission.newInstance(workspace,
                WorkspacePermission.ACTION_CREATE_PAGE);
        if (UserStatus.lookup().hasPermission(sectionPerm)) {
            Panel[] panels = workspace
                    .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId()))
                    .getAllPanels();
            TreeSet panelInstances = new TreeSet();
            for (int i = 0; i < panels.length; i++) {
                Panel panel = panels[i];
                panelInstances.add(panel.getInstanceId());
            }
            if (!panelInstances.isEmpty()) {
                setAttribute("sectionTitle",
                        LocaleManager.lookup().localize(workspace
                                .getSection(Long.decode(getSectionsPropertiesHandler().getSelectedSectionId()))
                                .getTitle()));
                renderFragment("outputMode");

                renderFragment("outputHeaders");
                Iterator it = panelInstances.iterator();
                int counter = 0;
                while (it.hasNext()) {
                    String instanceId = it.next().toString();
                    PanelInstance instance = workspace.getPanelInstance(instanceId);
                    setAttribute("instanceId", instanceId);
                    setAttribute("group", instance.getResource(instance.getProvider().getGroup(), getLocale()));
                    setAttribute("description",
                            instance.getResource(instance.getProvider().getDescription(), getLocale()));
                    setAttribute("title", getLocalizedValue(instance.getTitle()));
                    setAttribute("counter", counter);
                    counter++;
                    renderFragment("outputOpt");
                }
                renderFragment("outputOptEnd");
                renderFragment("outputHeadersEnd");
            } else {
                renderFragment("outputEmpty");
                getSectionsPropertiesHandler().setDuplicateSection(Boolean.FALSE);
            }
        }
        renderFragment("outputEnd");
    } catch (Exception e) {
        log.error("Error rendering section copy form: ", e);
    }
}

From source file:com.idega.block.cal.renderer.AbstractCompactScheduleRenderer.java

/**
 * <p>/*from   www . j  a  v  a2s  .c om*/
 * Draw the schedule entries in the specified day cell
 * </p>
 * 
 * @param context
 *            the FacesContext
 * @param schedule
 *            the schedule
 * @param day
 *            the day
 * @param writer
 *            the ResponseWriter
 * 
 * @throws IOException
 *             when the entries could not be drawn
 */
protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer)
        throws IOException {
    //final String clientId = schedule.getClientId(context);
    //final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    //final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
    final TreeSet entrySet = new TreeSet(comparator);

    for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) {
        ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
        entrySet.add(entry);
    }

    for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) {
        ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
        writer.startElement(HTML.DIV_ELEM, schedule);
        writer.startElement(HTML.DIV_ELEM, schedule);

        if (isSelected(schedule, entry)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "selected"), null);
        }

        //compose the CSS style for the entry box
        StringBuffer entryStyle = new StringBuffer();
        entryStyle.append("width: 100%;");
        String entryColor = getEntryRenderer(schedule).getColor(context, schedule, entry,
                isSelected(schedule, entry));
        if (isSelected(schedule, entry) && entryColor != null) {
            entryStyle.append(" background-color: ");
            entryStyle.append(entryColor);
            entryStyle.append(";");
            entryStyle.append(" border-color: ");
            entryStyle.append(entryColor);
            entryStyle.append(";");
        }

        writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null);

        // draw the tooltip
        if (showTooltip(schedule)) {
            getEntryRenderer(schedule).renderToolTip(context, writer, schedule, entry,
                    isSelected(schedule, entry));
        }

        if (!isSelected(schedule, entry) && !schedule.isReadonly()) {
            writer.startElement("a", schedule);
            writer.writeAttribute(HTML.CLASS_ATTR, CalendarConstants.SCHEDULE_ENTRY_STYLE_CLASS, null);
            writer.writeAttribute(HTML.HREF_ATTR, "javascript:void(0)", null);
            writer.writeAttribute("entryid", entry.getId(), null);

            DateFormat format;
            String pattern = null;

            if ((pattern != null) && (pattern.length() > 0)) {
                format = new SimpleDateFormat(pattern);
            } else {
                if (context.getApplication().getDefaultLocale() != null) {
                    format = DateFormat.getDateInstance(DateFormat.MEDIUM,
                            context.getApplication().getDefaultLocale());
                } else {
                    format = DateFormat.getDateInstance(DateFormat.MEDIUM);
                }
            }

            String startTime = format.format(entry.getStartTime());
            startTime += " ";
            startTime += entry.getStartTime().getHours();
            startTime += ":";
            if (entry.getStartTime().getMinutes() < 10) {
                startTime += "0";
                startTime += entry.getStartTime().getMinutes();
            } else {
                startTime += entry.getStartTime().getMinutes();
            }

            String endTime = "";
            endTime += entry.getEndTime().getHours();
            endTime += ":";
            if (entry.getEndTime().getMinutes() < 10) {
                endTime += "0";
                endTime += entry.getEndTime().getMinutes();
            } else {
                endTime += entry.getEndTime().getMinutes();
            }
        }

        // draw the content
        getEntryRenderer(schedule).renderContent(context, writer, schedule, day, entry, true,
                isSelected(schedule, entry));

        if (!isSelected(schedule, entry) && !schedule.isReadonly()) {
            writer.endElement("a");
        }

        writer.endElement(HTML.DIV_ELEM);
        writer.endElement(HTML.DIV_ELEM);
    }
}

From source file:org.parosproxy.paros.network.HttpRequestHeader.java

/**
 * Gets a list of the http cookies from this request Header.
 *
 * @return the http cookies//from  ww  w . java 2 s.  co  m
 * @throws IllegalArgumentException if a problem is encountered while
 * processing the "Cookie: " header line.
 */
public List<HttpCookie> getHttpCookies() {
    List<HttpCookie> cookies = new LinkedList<>();
    // Use getCookieParams to reduce the places we parse cookies
    TreeSet<HtmlParameter> ts = getCookieParams();
    Iterator<HtmlParameter> it = ts.iterator();
    while (it.hasNext()) {
        HtmlParameter htmlParameter = it.next();
        if (!htmlParameter.getName().isEmpty()) {
            try {
                cookies.add(new HttpCookie(htmlParameter.getName(), htmlParameter.getValue()));

            } catch (IllegalArgumentException e) {
                // Occurs while scanning ;)
                log.debug(e.getMessage() + " " + htmlParameter.getName());
            }
        }
    }

    return cookies;
}

From source file:com.dianping.resource.io.util.MimeType.java

/**
 * Compares this {@code MediaType} to another alphabetically.
 * @param other media type to compare to
 * @see MimeTypeUtils#sortBySpecificity(java.util.List)
 *//*from   w w  w.  j a  v  a  2  s  .  c om*/
@Override
public int compareTo(MimeType other) {
    int comp = getType().compareToIgnoreCase(other.getType());
    if (comp != 0) {
        return comp;
    }
    comp = getSubtype().compareToIgnoreCase(other.getSubtype());
    if (comp != 0) {
        return comp;
    }
    comp = getParameters().size() - other.getParameters().size();
    if (comp != 0) {
        return comp;
    }
    TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    thisAttributes.addAll(getParameters().keySet());
    TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    otherAttributes.addAll(other.getParameters().keySet());
    Iterator<String> thisAttributesIterator = thisAttributes.iterator();
    Iterator<String> otherAttributesIterator = otherAttributes.iterator();
    while (thisAttributesIterator.hasNext()) {
        String thisAttribute = thisAttributesIterator.next();
        String otherAttribute = otherAttributesIterator.next();
        comp = thisAttribute.compareToIgnoreCase(otherAttribute);
        if (comp != 0) {
            return comp;
        }
        String thisValue = getParameters().get(thisAttribute);
        String otherValue = other.getParameters().get(otherAttribute);
        if (otherValue == null) {
            otherValue = "";
        }
        comp = thisValue.compareTo(otherValue);
        if (comp != 0) {
            return comp;
        }
    }
    return 0;
}

From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java

/**
 * @param c//from   w ww.j a  v a2 s.  co  m
 * @param ann
 * @return
 */
private String getAuthor(Comment c, ISVNAnnotations ann) {
    String author = "unknown";
    if (ann != null) {
        TreeSet authors = new TreeSet();
        int i = c.START_LINE;
        for (i = c.START_LINE; i <= c.END_LINE; i++) {
            String a = ann.getAuthor(i);
            if (a == null)
                a = "";
            authors.add(a);
        }
        author = "";
        for (Iterator it = authors.iterator(); it.hasNext();) {
            String a = (String) it.next();
            author += a + ",";
        }
    }
    return author;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

public Paint getLastPointColor() {
    logger.debug("IN");
    Color colorToReturn = null;//from   w w w  .j av a  2 s. c o  m

    try {
        final int last = lastIndexMonth;
        TimeSeriesDataItem item = timeSeries.getDataItem(new Month(last, Integer.valueOf(lastYear).intValue()));
        if (item == null || item.getValue() == null) {
            return Color.WHITE;
        }
        Double currentValue = (Double) item.getValue();
        // get the color of the last element
        TreeSet<Double> orderedThresholds = new TreeSet<Double>(thresholds.keySet());
        Double thresholdGiveColor = null;
        // if dealing with targets, begin from first target and go to on till the current value is major
        if (useTargets) {
            boolean stop = false;
            for (Iterator iterator = orderedThresholds.iterator(); iterator.hasNext() && stop == false;) {
                Double currentThres = (Double) iterator.next();
                if (currentValue >= currentThres) {
                    thresholdGiveColor = currentThres;
                } else {
                    stop = true;
                }
            }
            //previous threshold is the right threshold that has been passed, if it is null means that we are in the bottom case
        } else if (!useTargets) {
            // if dealing with baseline, begin from first baseline and go to the last; 
            // opposite case than targets, it gets the next baseline
            boolean stop = false;
            for (Iterator iterator = orderedThresholds.iterator(); iterator.hasNext() && stop == false;) {
                Double currentThres = (Double) iterator.next();
                if (currentValue > currentThres) {
                } else {
                    stop = true;
                    thresholdGiveColor = currentThres;
                }
            }
            if (stop == false) { // means that current value was > than last baselines, so we are in the bottom case
                thresholdGiveColor = null;
            }
        }

        // ******* Get the color *************
        if (thresholdGiveColor == null) { //bottom case
            if (bottomThreshold != null && bottomThreshold.getColor() != null)
                colorToReturn = bottomThreshold.getColor();
            else
                colorToReturn = Color.GREEN;

        } else {
            TargetThreshold currThreshold = thresholds.get(thresholdGiveColor);
            colorToReturn = currThreshold.getColor();
            if (colorToReturn == null) {
                colorToReturn = Color.BLACK;
            }
        }
    } catch (Exception e) {
        logger.error("Exception while deifning last ponter color: set default green", e);
        return Color.GREEN;
    }
    logger.debug("OUT");
    return colorToReturn;
}

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

private Offering loadOffering(InstructionalOffering io, Hashtable courseTable, Hashtable classTable) {
    sLog.debug("Loading offering " + io.getCourseName());
    if (!io.hasClasses()) {
        sLog.debug("  -- offering " + io.getCourseName() + " has no class");
        return null;
    }//  w  w  w  . ja v a 2s.  com
    Offering offering = new Offering(io.getUniqueId().longValue(), io.getCourseName());
    boolean unlimited = false;
    for (Iterator i = io.getInstrOfferingConfigs().iterator(); i.hasNext();) {
        InstrOfferingConfig ioc = (InstrOfferingConfig) i.next();
        if (ioc.isUnlimitedEnrollment().booleanValue())
            unlimited = true;
    }
    for (Iterator i = io.getCourseOfferings().iterator(); i.hasNext();) {
        CourseOffering co = (CourseOffering) i.next();
        int projected = (co.getProjectedDemand() == null ? 0 : co.getProjectedDemand().intValue());
        int limit = co.getInstructionalOffering().getLimit().intValue();
        if (unlimited)
            limit = -1;
        if (co.getReservation() != null)
            limit = co.getReservation();
        Course course = new Course(co.getUniqueId().longValue(), co.getSubjectAreaAbbv(), co.getCourseNbr(),
                offering, limit, projected);
        courseTable.put(co.getUniqueId(), course);
        sLog.debug("  -- created course " + course);
    }
    Hashtable class2section = new Hashtable();
    Hashtable ss2subpart = new Hashtable();
    for (Iterator i = io.getInstrOfferingConfigs().iterator(); i.hasNext();) {
        InstrOfferingConfig ioc = (InstrOfferingConfig) i.next();
        if (!ioc.hasClasses()) {
            sLog.debug("  -- config " + ioc.getName() + " has no class");
            continue;
        }
        Config config = new Config(ioc.getUniqueId().longValue(),
                (ioc.isUnlimitedEnrollment() ? -1 : ioc.getLimit()),
                ioc.getCourseName() + " [" + ioc.getName() + "]", offering);
        sLog.debug("  -- created config " + config);
        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()));
            if (ss.getParentSubpart() != null && parentSubpart == null) {
                sLog.error("    -- subpart " + ss.getSchedulingSubpartLabel() + " has parent "
                        + ss.getParentSubpart().getSchedulingSubpartLabel()
                        + ", but the appropriate parent subpart is not loaded.");
            }
            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);
            sLog.debug("    -- created subpart " + subpart);
            for (Iterator k = ss.getClasses().iterator(); k.hasNext();) {
                Class_ c = (Class_) k.next();
                int limit = c.getClassLimit();
                if (ioc.isUnlimitedEnrollment().booleanValue())
                    limit = -1;
                if (!c.isEnabledForStudentScheduling())
                    limit = 0;
                Section parentSection = (c.getParentClass() == null ? null
                        : (Section) class2section.get(c.getParentClass()));
                if (c.getParentClass() != null && parentSection == null) {
                    sLog.error("    -- class " + c.getClassLabel() + " has parent "
                            + c.getParentClass().getClassLabel()
                            + ", but the appropriate parent section is not loaded.");
                }
                Section section = loadSection(subpart, parentSection, c, limit);
                class2section.put(c, section);
                classTable.put(c.getUniqueId(), section);
                sLog.debug("      -- created section " + section);
            }
        }
    }
    return offering;
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java

/**
 * The contextPackages may declare overrides.  
 * Example://from   ww w. j  a  v  a 2  s.  co m
 *    "com.A"
 *    "com.B"
 *    "com.C"
 *    "@com.A"   <-- Indicates a reference to a class (versus ns 2 pkg conversion)
 *    "com.A > com.B"   <-- This says com.A overrides com.B
 *    
 * This method prunes the overrides and overriden packages.
 * Example return:
 *    "com.A"
 *    "com.C"
 * @param contextPackages
 * @return List<String> class references
 */
protected static List<String> pruneDirectives(TreeSet<String> contextPackages) {
    List<String> removePkgsList = new ArrayList<String>();
    List<String> strongPkgsList = new ArrayList<String>();
    List<String> classRefs = new ArrayList<String>();

    // Walk the contextPackages looking for entries representing directives
    Iterator<String> it = contextPackages.iterator();
    while (it.hasNext()) {
        String entry = it.next();
        // If the entry contains an override character
        if (entry.contains(">")) {
            if (log.isDebugEnabled()) {
                log.debug("Override found:" + entry);
            }
            // Remove the entry using an iterator remove()
            it.remove();

            // Store the overridden package
            String removePkg = entry.substring(entry.indexOf(">") + 1);
            removePkg = removePkg.trim();
            removePkgsList.add(removePkg);
        }
        if (entry.startsWith("@")) {
            if (log.isDebugEnabled()) {
                log.debug("Strong (class) reference found:" + entry);
            }
            // Remove the entry using an iterator remove()
            it.remove();

            // Store the overridden package
            String strongPkg = entry.substring(1);
            strongPkg = strongPkg.trim();
            strongPkgsList.add(strongPkg);
        }
        if (entry.startsWith("[")) {
            if (log.isDebugEnabled()) {
                log.debug("Class Reference found:" + entry);
            }
            // Remove the entry using an iterator remove()
            it.remove();

            // Store the class
            String cls = entry.substring(1, entry.length() - 1);
            classRefs.add(cls);
        }
    }

    // Now walk the contextPackages and remove the overriden packages
    it = contextPackages.iterator();
    while (it.hasNext()) {
        String entry = it.next();
        // If the entry contains an override character
        if (removePkgsList.contains(entry)) {
            if (log.isDebugEnabled()) {
                log.debug("Removing override package:" + entry);
            }
            // Remove the overridden package using an iterator remove()
            it.remove();
        }
    }

    // Now add back all of the strong packages
    contextPackages.addAll(strongPkgsList);
    return classRefs;
}

From source file:org.jboss.dashboard.ui.components.BeanHandler.java

protected void calculateActionShortcuts() {
    Method[] allMethods = this.getClass().getMethods();
    TreeSet actionNames = new TreeSet();
    for (int i = 0; i < allMethods.length; i++) {
        Method method = allMethods[i];
        if (method.getName().startsWith("action")) {
            Class[] classes = method.getParameterTypes();
            if (classes != null && classes.length == 1) {
                Class paramClass = classes[0];
                if (paramClass.equals(CommandRequest.class)) {
                    String actionName = method.getName().substring("action".length());
                    actionNames.add(actionName);
                }/*from  w ww  .ja v  a 2s. c om*/
            }
        }
    }
    int index = 0;
    for (Iterator iterator = actionNames.iterator(); iterator.hasNext(); index++) {
        String action = (String) iterator.next();
        actionsShortcuts.put(action, String.valueOf(index));
        reverseActionsShortcuts.put(String.valueOf(index), action);
    }
}