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:it.eng.spagobi.engines.chart.bo.charttypes.utils.MyBarRendererThresholdPaint.java

public Paint getItemPaint(int row, int column) {
    logger.debug("IN");
    String columnKey = (String) dataset.getColumnKey(column);
    int separator = columnKey.indexOf('-');
    String month = columnKey.substring(0, separator);
    String year = columnKey.substring(separator + 1);
    Number value = dataset.getValue(row, column); // value put in dataset (- 0.5 or 0.5)

    Month currentMonth = new Month(Integer.valueOf(month), Integer.valueOf(year)); // value for that month
    TimeSeriesDataItem item = timeSeries.getDataItem(currentMonth);

    if (nullValues.contains(columnKey)) {
        return background;
    }//from  w w  w .  j av  a2s. co  m
    // If no item is retrieved means that no value was specified for that month in that year
    if (item == null || item.getValue() == null) {
        return background;
    }

    Double currentValue = (Double) item.getValue();

    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 *************
    Color colorToReturn = null;
    if (thresholdGiveColor == null) { //bottom case
        if (bottomThreshold != null && bottomThreshold.getColor() != null) {
            colorToReturn = bottomThreshold.getColor();
        }
        if (colorToReturn == null) {
            colorToReturn = Color.BLACK;
        }
    } else {
        if (thresholds.get(thresholdGiveColor) != null && thresholds.get(thresholdGiveColor).getColor() != null)
            colorToReturn = thresholds.get(thresholdGiveColor).getColor();
        if (colorToReturn == null) {
            colorToReturn = Color.BLACK;
        }

    }
    logger.debug("OUT");
    return colorToReturn;
}

From source file:org.fiware.qa.documentation.measurements.CatalogueComplianceMeasurement.java

public void printAttributes() {
    String out = "";
    TreeSet<String> keys = new TreeSet<String>(attributes.keySet());

    for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
        String n = (String) iterator.next();
        Integer v = attributes.get(n);

        String entry = n + Configuration.CSV_SEPARATOR + v;
        out = out + entry + "\n";

    }/*from ww w .  ja v a2 s .c o  m*/

    // write a file; TODO: make a configuration option or implement further
    // data flow
    try {
        FileUtils.writeStringToFile(new File(Configuration.QA_DOCS_METRICS_FILENAME), out);
    } catch (IOException e) {
        // TODO add log entry
        e.printStackTrace();
    }
}

From source file:massbank.api.ApiParameter.java

/**
 * CGIpp??[^(ID)/*  w  w w .  j  av a2 s. c o  m*/
 */
public String getCgiParamId(String[] ids) {
    // ID?dr??A\?[g
    TreeSet<String> tree = new TreeSet<String>();
    for (int i = 0; i < ids.length; i++) {
        tree.add(ids[i]);
    }

    String id = "ids=";
    Iterator it = tree.iterator();
    while (it.hasNext()) {
        id += it.next() + ",";
    }
    if (!id.equals("")) {
        id = id.substring(0, id.length() - 1);
    }
    return id;
}

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

public void exportSubpartStructure(Element parent, SchedulingSubpart s) {
    Element el = parent.addElement("schedulingSubpart");
    el.addAttribute("uniqueId", s.getUniqueId().toString());
    el.addAttribute("itype", s.getItypeDesc());
    el.addAttribute("suffix", s.getSchedulingSubpartSuffix());
    el.addAttribute("minutesPerWk", s.getMinutesPerWk().toString());
    TreeSet subparts = new TreeSet(subpartCmp);
    subparts.addAll(s.getChildSubparts());
    for (Iterator i = subparts.iterator(); i.hasNext();) {
        exportSubpartStructure(el, (SchedulingSubpart) s);
    }/*w w  w  . j av a2 s .c  o  m*/
    TreeSet classes = new TreeSet(classCmp);
    classes.addAll(s.getClasses());
    for (Iterator i = classes.iterator(); i.hasNext();) {
        Class_ c = (Class_) i.next();
        Element x = el.addElement("class");
        x.addAttribute("uniqueId", c.getUniqueId().toString());
        if (c.getParentClass() != null)
            x.addAttribute("parent", c.getParentClass().getUniqueId().toString());
        x.addAttribute("expectedCapacity", c.getExpectedCapacity().toString());
        x.addAttribute("maxExpectedCapacity", c.getMaxExpectedCapacity().toString());
        x.addAttribute("roomRatio", c.getRoomRatio().toString());
        x.addAttribute("nbrRooms", c.getNbrRooms().toString());
        x.addAttribute("manager", c.getManagingDept().getDeptCode());
        x.addAttribute("sectionNumber", String.valueOf(c.getSectionNumber()));
    }
}

From source file:org.broadinstitute.gatk.tools.walkers.haplotypecaller.LDMerger.java

/**
 * Merge the next pair of events, if possible
 *
 * @param haplotypes a list of haplotypes whose events we want to merge
 * @param ldCalculator calculates R^2 for pairs of events on demand
 * @param startPosKeySet a set of starting positions of all events among the haplotypes
 * @param ref the reference bases/*w w w. j av a 2  s . c  o m*/
 * @param refLoc the span of the reference bases
 * @return true if something was merged, false otherwise
 */
protected boolean mergeConsecutiveEventsBasedOnLDOnce(final List<Haplotype> haplotypes,
        final HaplotypeLDCalculator ldCalculator, final int nSamples, final TreeSet<Integer> startPosKeySet,
        final byte[] ref, final GenomeLoc refLoc) {
    // loop over the set of start locations and consider pairs that start near each other
    final Iterator<Integer> iter = startPosKeySet.iterator();
    int thisStart = iter.next();
    while (iter.hasNext()) {
        final int nextStart = iter.next();
        final LDMergeData toMerge = getPairOfEventsToMerge(haplotypes, thisStart, nextStart);

        if (toMerge.canBeMerged(nSamples)) {
            final double pPhased = ldCalculator.computeProbOfBeingPhased(toMerge.firstVC, toMerge.secondVC);

            if (DEBUG) {
                logger.info("Found consecutive biallelic events with R^2 = " + String.format("%.4f", pPhased));
                logger.info("-- " + toMerge.firstVC);
                logger.info("-- " + toMerge.secondVC);
            }

            if (pPhased > MERGE_EVENTS_PROB_PHASED_THRESHOLD) {
                final VariantContext mergedVC = createMergedVariantContext(toMerge.firstVC, toMerge.secondVC,
                        ref, refLoc);
                // if for some reason the merging resulting in a bad allele, mergedVC will be null, and we will just remove first and second
                replaceVariantContextsInMap(haplotypes, startPosKeySet, mergedVC, toMerge.firstVC,
                        toMerge.secondVC);
                return true; // break out of tree set iteration since it was just updated, start over from the beginning and keep merging events
            }
        }

        thisStart = nextStart;
    }

    return false;
}

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

public void exportInstructionalOffering(Element parent, InstructionalOffering io) throws Exception {
    sLog.info("Exporting " + io.getCourseName());
    Element el = parent.addElement("instructionalOffering");
    el.addAttribute("uniqueId", io.getUniqueId().toString());
    el.addAttribute("subjectArea", io.getControllingCourseOffering().getSubjectAreaAbbv());
    el.addAttribute("courseNbr", io.getControllingCourseOffering().getCourseNbr());
    if (io.getInstrOfferingPermId() != null)
        el.addAttribute("instrOfferingPermId", io.getInstrOfferingPermId().toString());
    for (Iterator i = io.getCourseOfferings().iterator(); i.hasNext();) {
        CourseOffering co = (CourseOffering) i.next();
        Element x = el.addElement("courseOffering");
        x.addAttribute("uniqueId", co.getUniqueId().toString());
        x.addAttribute("subjectArea", co.getSubjectAreaAbbv());
        x.addAttribute("courseNbr", co.getCourseNbr());
        x.addAttribute("projectedDemand", co.getProjectedDemand().toString());
        x.addAttribute("demand", co.getDemand().toString());
        x.addAttribute("isControl", co.getIsControl().toString());
        if (co.getPermId() != null)
            x.addAttribute("permId", co.getPermId());
    }//from  www  .ja v a  2 s  .c o m
    for (Iterator i = io.getInstrOfferingConfigs().iterator(); i.hasNext();) {
        InstrOfferingConfig c = (InstrOfferingConfig) i.next();
        Element x = el.addElement("instrOfferingConfig");
        x.addAttribute("uniqueId", c.getUniqueId().toString());
        x.addAttribute("limit", c.getLimit().toString());
        TreeSet subparts = new TreeSet(subpartCmp);
        subparts.addAll(c.getSchedulingSubparts());
        for (Iterator j = subparts.iterator(); j.hasNext();) {
            SchedulingSubpart s = (SchedulingSubpart) j.next();
            if (s.getParentSubpart() == null)
                exportSubpartStructure(x, s);
        }
    }
}

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

private TreeSet<String> flushDictionary(TreeSet<String> dictionarySet, AbstractDictionary<String> dict)
        throws AnalysisEngineProcessException {

    Iterator<String> it = dictionarySet.iterator();
    String[] split;//from   w w w. j  ava  2s . c  o  m
    while (it.hasNext()) {
        split = it.next().split(SEPARATOR);
        if (split.length != 2) {
            LOGGER.error("readDictionary() - wrong split length: " + split.length);
            throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null);
        }
        dict.addEntry(new DictionaryEntry<String>(split[0], split[1], CHUNK_SCORE));
    }
    it = null;
    dictionarySet.clear();

    return dictionarySet;
}

From source file:com.alfaariss.oa.authentication.remote.AbstractRemoteMethod.java

/**
 * Creates a signature over the supplied attributes in the map.
 * <br>/*from ww  w . j  a  va 2 s .c o m*/
 * Uses a TreeSet to sort the request parameter names.
 * @param mapRequest A map containing the attributes to be signed.
 * @return The signed request attributes.
 * @throws OAException
 */
protected String createSignature(Map<String, String> mapRequest) throws OAException {
    String sSignature = null;
    try {
        Signature oSignature = _cryptoManager.getSignature();
        if (oSignature == null) {
            _logger.warn("No signature object found");
            throw new OAException(SystemErrors.ERROR_INTERNAL);
        }

        StringBuffer sbSignatureData = new StringBuffer();
        TreeSet<String> sortedSet = new TreeSet<String>(mapRequest.keySet());
        for (Iterator<String> iter = sortedSet.iterator(); iter.hasNext();) {
            String sKey = iter.next();
            sbSignatureData.append(mapRequest.get(sKey));
        }

        PrivateKey keyPrivate = _cryptoManager.getPrivateKey();
        if (keyPrivate == null) {
            _logger.error("No private key available");
            throw new OAException(SystemErrors.ERROR_INTERNAL);
        }
        oSignature.initSign(keyPrivate);
        oSignature.update(sbSignatureData.toString().getBytes(CHARSET));

        byte[] baSignature = oSignature.sign();

        byte[] baEncSignature = Base64.encodeBase64(baSignature);
        sSignature = new String(baEncSignature, CHARSET);
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Could not create signature for data: " + mapRequest, e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }

    return sSignature;
}

From source file:org.apache.felix.webconsole.internal.compendium.ComponentsServlet.java

private void listComponentProperties(JSONWriter jsonWriter, Component inputComponent) {
    Dictionary propsBook = inputComponent.getProperties();
    if (propsBook != null) {
        JSONArray myBuf = new JSONArray();
        TreeSet bookKeys = new TreeSet(Collections.list(propsBook.keys()));
        for (Iterator keyIter = bookKeys.iterator(); keyIter.hasNext();) {
            final String key = (String) keyIter.next();
            final StringBuffer strBuffer = new StringBuffer();
            strBuffer.append(key).append(" = ");

            Object prop = propsBook.get(key);
            if (prop.getClass().isArray()) {
                prop = Arrays.asList((Object[]) prop);
            }//from ww  w  .j a  v a2 s  .c om
            strBuffer.append(prop);
            myBuf.put(strBuffer.toString());
        }

        printKeyVal(jsonWriter, "Properties", myBuf);
    }

}