Example usage for java.util TreeMap subMap

List of usage examples for java.util TreeMap subMap

Introduction

In this page you can find the example usage for java.util TreeMap subMap.

Prototype

public NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    System.out.println("Getting a portion of the map");
    NavigableMap<Integer, String> treemapincl = treemap.subMap(1, true, 3, true);
    System.out.println("Sub map values: " + treemapincl);
}

From source file:ch.algotrader.service.algo.VWAPOrderService.java

VWAPOrderStateVO createAlgoOrderState(final VWAPOrder algoOrder, final Date dateTime)
        throws OrderValidationException {

    Validate.notNull(algoOrder, "vwapOrder missing");

    Security security = algoOrder.getSecurity();
    SecurityFamily family = security.getSecurityFamily();
    Exchange exchange = family.getExchange();

    HistoricalDataService historicalDataService = this.applicationContext.getBean(HistoricalDataService.class);

    List<Bar> bars = historicalDataService.getHistoricalBars(security.getId(), //
            DateUtils.truncate(new Date(), Calendar.DATE), //
            algoOrder.getLookbackPeriod(), //
            TimePeriod.DAY, //
            algoOrder.getBucketSize(), //
            MarketDataEventType.TRADES, //
            Collections.emptyMap());

    TreeMap<LocalTime, Long> buckets = new TreeMap<>();
    Set<LocalDate> tradingDays = new HashSet<>();
    for (Bar bar : bars) {
        int vol = bar.getVol();
        LocalTime time = DateTimeLegacy.toLocalTime(bar.getDateTime());
        tradingDays.add(DateTimeLegacy.toLocalDate(bar.getDateTime()));
        if (buckets.containsKey(time)) {
            buckets.put(time, buckets.get(time) + vol);
        } else {/* w  w w .  j a  va  2s. c  o  m*/
            buckets.put(time, (long) vol);
        }
    }

    // verify start and end time
    if (algoOrder.getStartTime() == null) {
        if (this.calendarService.isOpen(exchange.getId())) {
            algoOrder.setStartTime(dateTime);
        } else {
            Date nextOpenTime = this.calendarService.getNextOpenTime(exchange.getId());
            algoOrder.setStartTime(nextOpenTime);
        }
    }

    Date closeTime = this.calendarService.getNextCloseTime(exchange.getId());
    if (algoOrder.getEndTime() == null) {
        algoOrder.setEndTime(closeTime);
    }

    if (algoOrder.getStartTime().compareTo(dateTime) < 0) {
        throw new OrderValidationException("startTime needs to be in the future " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(dateTime) <= 0) {
        throw new OrderValidationException("endTime needs to be in the future " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(closeTime) > 0) {
        throw new OrderValidationException("endTime needs to be before next market closeTime for " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(algoOrder.getStartTime()) <= 0) {
        throw new OrderValidationException("endTime needs to be after startTime for " + algoOrder);
    }

    int historicalVolume = 0;
    LocalTime startTime = DateTimeLegacy.toLocalTime(algoOrder.getStartTime());
    LocalTime endTime = DateTimeLegacy.toLocalTime(algoOrder.getEndTime());
    LocalTime firstBucketStart = buckets.floorKey(startTime);
    LocalTime lastBucketStart = buckets.floorKey(endTime);

    SortedMap<LocalTime, Long> subBuckets = buckets.subMap(firstBucketStart, true, lastBucketStart, true);
    for (Map.Entry<LocalTime, Long> bucket : subBuckets.entrySet()) {

        long vol = bucket.getValue() / tradingDays.size();
        bucket.setValue(vol);

        if (bucket.getKey().equals(firstBucketStart)) {
            LocalTime firstBucketEnd = firstBucketStart.plus(algoOrder.getBucketSize().getValue(),
                    ChronoUnit.MILLIS);
            double fraction = (double) ChronoUnit.MILLIS.between(startTime, firstBucketEnd)
                    / algoOrder.getBucketSize().getValue();
            historicalVolume += vol * fraction;
        } else if (bucket.getKey().equals(lastBucketStart)) {
            double fraction = (double) ChronoUnit.MILLIS.between(lastBucketStart, endTime)
                    / algoOrder.getBucketSize().getValue();
            historicalVolume += vol * fraction;
        } else {
            historicalVolume += vol;
        }
    }

    double participation = algoOrder.getQuantity() / (double) historicalVolume;

    if (participation > MAX_PARTICIPATION) {
        throw new OrderValidationException("participation rate " + twoDigitFormat.format(participation * 100.0)
                + "% is above 50% of historical market volume for " + algoOrder);
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.debug("participation of {} is {}%", algoOrder.getDescription(),
                twoDigitFormat.format(participation * 100.0));
    }

    return new VWAPOrderStateVO(participation, buckets);
}

From source file:org.apache.bookkeeper.metastore.TestMetaStore.java

/**
 * Test usage of (scan) operation on (full and partial) fields.
 *///w w  w.  jav  a 2  s .  c o m
@Test(timeout = 60000)
public void testOpenCursor() throws Exception {

    TreeMap<String, Value> allValues = Maps.newTreeMap();
    TreeMap<String, Value> partialValues = Maps.newTreeMap();
    TreeMap<String, Value> nonValues = Maps.newTreeMap();

    Set<String> counterFields = Sets.newHashSet(FIELD_COUNTER);

    for (int i = 5; i < 24; i++) {
        char c = (char) ('a' + i);
        String key = String.valueOf(c);
        Value v = makeValue("value" + i, i);
        Value cv = v.project(counterFields);
        Value nv = v.project(NON_FIELDS);

        myTable.put(key, new Value(v), Version.NEW);
        allValues.put(key, v);
        partialValues.put(key, cv);
        nonValues.put(key, nv);
    }

    // test open cursor
    MetastoreCursor cursor = myTable.openCursor(ALL_FIELDS);
    openCursorTest(cursor, allValues, 7);

    cursor = myTable.openCursor(counterFields);
    openCursorTest(cursor, partialValues, 7);

    cursor = myTable.openCursor(NON_FIELDS);
    openCursorTest(cursor, nonValues, 7);

    // test order inclusive exclusive
    Iterator<Map.Entry<String, Value>> expectedIterator;

    expectedIterator = allValues.subMap("l", true, "u", true).entrySet().iterator();
    openRangeCursorTest("l", true, "u", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.descendingMap().subMap("u", true, "l", true).entrySet().iterator();
    openRangeCursorTest("u", true, "l", true, Order.DESC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.subMap("l", false, "u", false).entrySet().iterator();
    openRangeCursorTest("l", false, "u", false, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.descendingMap().subMap("u", false, "l", false).entrySet().iterator();
    openRangeCursorTest("u", false, "l", false, Order.DESC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.subMap("l", true, "u", false).entrySet().iterator();
    openRangeCursorTest("l", true, "u", false, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.descendingMap().subMap("u", true, "l", false).entrySet().iterator();
    openRangeCursorTest("u", true, "l", false, Order.DESC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.subMap("l", false, "u", true).entrySet().iterator();
    openRangeCursorTest("l", false, "u", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.descendingMap().subMap("u", false, "l", true).entrySet().iterator();
    openRangeCursorTest("u", false, "l", true, Order.DESC, ALL_FIELDS, expectedIterator, 7);

    // test out of range
    String firstKey = "f";
    String lastKey = "x";
    expectedIterator = allValues.subMap(firstKey, true, lastKey, true).entrySet().iterator();
    openRangeCursorTest("a", true, "z", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.subMap("l", true, lastKey, true).entrySet().iterator();
    openRangeCursorTest("l", true, "z", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.subMap(firstKey, true, "u", true).entrySet().iterator();
    openRangeCursorTest("a", true, "u", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    // test EMPTY_START_KEY and EMPTY_END_KEY
    expectedIterator = allValues.subMap(firstKey, true, "u", true).entrySet().iterator();
    openRangeCursorTest(EMPTY_START_KEY, true, "u", true, Order.ASC, ALL_FIELDS, expectedIterator, 7);

    expectedIterator = allValues.descendingMap().subMap(lastKey, true, "l", true).entrySet().iterator();
    openRangeCursorTest(EMPTY_END_KEY, true, "l", true, Order.DESC, ALL_FIELDS, expectedIterator, 7);

    // test illegal arguments
    try {
        myTable.openCursor("a", true, "z", true, Order.DESC, ALL_FIELDS);
        fail("Should fail with wrong range");
    } catch (MSException.IllegalOpException ioe) {
    }
    try {
        myTable.openCursor("z", true, "a", true, Order.ASC, ALL_FIELDS);
        fail("Should fail with wrong range");
    } catch (MSException.IllegalOpException ioe) {
    }
    try {
        myTable.openCursor("a", true, "z", true, null, ALL_FIELDS);
        fail("Should fail with null order");
    } catch (MSException.IllegalOpException ioe) {
    }
}

From source file:org.dataconservancy.packaging.tool.impl.generator.DomainObjectResourceBuilder.java

private static void remap(String oldBaseURI, String newBaseURI, TreeMap<String, Resource> resources,
        Map<String, String> renameMap) {

    Map<String, Resource> toReplace = new HashMap<>();

    /* Consider the the URI plus any hash fragments */
    toReplace.putAll(resources.subMap(oldBaseURI, true, oldBaseURI, true));
    toReplace.putAll(resources.subMap(oldBaseURI + "#", oldBaseURI + "#" + Character.MAX_VALUE));

    /* Swap out the base URI for each matching resource */
    toReplace.entrySet().forEach(res -> {
        String newURI = res.getKey().replaceFirst(oldBaseURI, Matcher.quoteReplacement(newBaseURI));
        renameMap.put(res.getValue().toString(), newURI);
        ResourceUtils.renameResource(res.getValue(), newURI);
    });//from ww w.  j a va 2 s .c o m
}

From source file:org.mahasen.util.SearchUtil.java

/**
 * @param propertyTreeId//from  w w  w .j a  va2s.  c  o  m
 * @param initialValue
 * @param lastValue
 * @return
 * @throws InterruptedException
 * @throws MahasenException
 */
private Vector<Id> getResourceIdVector(Id propertyTreeId, String initialValue, String lastValue)
        throws InterruptedException, MahasenException {

    Vector<Id> resultantIds = new Vector<Id>();
    TreeMap propertyTree = mahasenManager.lookupPropertyTreeDHT(propertyTreeId);

    if (propertyTree == null) {
        throw new MahasenException("Property not found");
    } else {

        if (propertyTree.firstKey() instanceof String) {

            System.out.println("this is the property tree " + propertyTree);
            NavigableMap<String, Vector<Id>> resultMap = propertyTree.subMap(initialValue.toLowerCase(), true,
                    lastValue.toLowerCase(), true);

            Iterator keys = resultMap.keySet().iterator();

            while (keys.hasNext()) {
                resultantIds.addAll(resultMap.get(keys.next()));
            }

        } else if (propertyTree.firstKey() instanceof Integer) {

            System.out.println("this is the property tree " + propertyTree);
            NavigableMap<Integer, Vector<Id>> resultMap = propertyTree.subMap(Integer.valueOf(initialValue),
                    true, Integer.valueOf(lastValue), true);

            Iterator keys = resultMap.keySet().iterator();

            while (keys.hasNext()) {
                resultantIds.addAll(resultMap.get(keys.next()));
            }
        }
    }

    return resultantIds;
}

From source file:org.structr.rest.resource.LogResource.java

private Result aggregate(final LogState state) throws FrameworkException {

    // sort entries before aggregation
    state.sortEntries();/*from   ww w  .  j  a  v a  2  s  .c om*/

    final long startTimestamp = state.beginTimestamp();
    final long endTimestamp = state.endTimestamp();
    final GraphObjectMap result = new GraphObjectMap();
    final long interval = findInterval(state.aggregate());
    final long start = alignDateOnFormat(state.aggregate(), startTimestamp);
    final TreeMap<Long, Map<String, Object>> countMap = toAggregatedCountMap(state);
    final Set<String> countProperties = getCountProperties(countMap);

    for (long current = start; current <= endTimestamp; current += interval) {

        final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
        final GraphObjectMap sum = new GraphObjectMap();

        // initialize interval sums with 0 (so each
        // interval contains all keys regardless of
        // whether there are actual values or not)
        for (final String key : countProperties) {
            sum.put(new IntProperty(key), 0);
        }

        // evaluate counts
        for (final Map<String, Object> count : counts.values()) {

            for (final String key : countProperties) {

                final IntProperty prop = new IntProperty(key);
                Integer sumValue = sum.get(prop);
                if (sumValue == null) {
                    sumValue = 0;
                }

                Integer entryValue = (Integer) count.get(key);
                if (entryValue == null) {
                    entryValue = 0;
                }

                sum.put(prop, sumValue + entryValue);
            }
        }

        result.put(new GenericProperty(Long.toString(current)), sum);
    }

    return new Result(result, false);
}

From source file:org.structr.rest.resource.LogResource.java

private Result histogram(final LogState state) throws FrameworkException {

    // sort entries before creating the histogram
    state.sortEntries();/*from w w  w  . j a v  a2 s.  c o  m*/

    final String dateFormat = state.aggregate();
    final long startTimestamp = state.beginTimestamp();
    final long endTimestamp = state.endTimestamp();
    final GraphObjectMap result = new GraphObjectMap();
    final long interval = findInterval(dateFormat);
    final long start = alignDateOnFormat(dateFormat, startTimestamp);
    final TreeMap<Long, Map<String, Object>> countMap = toHistogramCountMap(state);
    final Set<String> countProperties = getCountProperties(countMap);

    for (long current = start; current <= endTimestamp; current += interval) {

        final Map<Long, Map<String, Object>> counts = countMap.subMap(current, true, current + interval, false);
        final GraphObjectMap sum = new GraphObjectMap();

        // initialize interval sums with 0 (so each
        // interval contains all keys regardless of
        // whether there are actual values or not)
        for (final String key : countProperties) {
            sum.put(new IntProperty(key), 0);
        }

        // evaluate counts
        for (final Map<String, Object> count : counts.values()) {

            for (final String key : countProperties) {

                final IntProperty prop = new IntProperty(key);
                Integer sumValue = sum.get(prop);
                if (sumValue == null) {
                    sumValue = 0;
                }

                Integer entryValue = (Integer) count.get(key);
                if (entryValue == null) {
                    entryValue = 0;
                }

                sum.put(prop, sumValue + entryValue);
            }
        }

        result.put(new GenericProperty(Long.toString(current)), sum);
    }

    return new Result(result, false);
}

From source file:umich.ms.batmass.gui.viewers.map2d.components.BaseMap2D.java

/**
 * Fills the map given a scan collection.
 * @param scans/* w ww.  java  2 s  .  co m*/
 * @return True, if filling was done successfully.
 *         False if something bad happened, e.g. scanCollection didn't contain any scans between rtStart & rtEnd
 */
public boolean fillMapFromScans(IScanCollection scans) {
    int pixelsVertical = availableHeight;
    height = pixelsVertical;
    width = availableWidth;

    NavigableMap<Integer, IScan> scansByRtSpanAtMsLevel = scans.getScansByRtSpanAtMsLevel(rtLo, rtHi, msLevel);
    ;
    if (!precursorMzRange.equals(Map2DPanel.OPT_DISPLAY_ALL_MZ_REGIONS)) {
        // if only scans from specific precursor m/z window were requested
        IntervalST<Double, TreeMap<Integer, IScan>> precursorRanges = scans.getMapMsLevel2rangeGroups()
                .get(msLevel);
        if (precursorRanges != null) {
            IntervalST.Node<Double, TreeMap<Integer, IScan>> node = precursorRanges.get(precursorMzRange);
            if (node != null) {
                // these are all the scans at proper MS level and in proper precursor m/z range
                TreeMap<Integer, IScan> scansInMzRange = node.getValue();
                // now filter this TreeMap to only leave scans that are in our RT range
                Integer numLo = scansByRtSpanAtMsLevel.firstKey();
                Integer numHi = scansByRtSpanAtMsLevel.lastKey();
                numLo = scansInMzRange.ceilingKey(numLo);
                numHi = scansInMzRange.floorKey(numHi);
                scansByRtSpanAtMsLevel = scansInMzRange.subMap(numLo, true, numHi, true);
            }
        }
    }
    if (scansByRtSpanAtMsLevel == null || scansByRtSpanAtMsLevel.size() == 0) {
        initErrorFillingState();
        return false;
    }
    scanNumLo = scansByRtSpanAtMsLevel.firstKey();
    scanNumHi = scansByRtSpanAtMsLevel.lastKey();

    // compare the number of scans to available vertical pixels
    int scanCount = scansByRtSpanAtMsLevel.size();
    this.map = new double[height][width];
    this.mapRaw = new double[height][width];
    this.maxValInFullRow = new double[height];

    IScan scan;
    TreeMap<Integer, IScan> mapNum2scan = scans.getMapNum2scan();
    IScan[] scansToAverage = new IScan[4];
    ISpectrum spectrum;
    Integer mzIdxLo, mzIdxHi;
    int x, y;
    boolean hasProfile = true;
    double[] masses, intensities;
    filledRowIds = new int[scansByRtSpanAtMsLevel.size()];
    int idx = 0;
    double denoisingTimeCounter = 0;
    for (Map.Entry<Integer, IScan> num2scan : scansByRtSpanAtMsLevel.entrySet()) {
        scan = num2scan.getValue();
        if (doProfileModeGapFilling && !scan.isCentroided()) {
            hasProfile = true;
        }
        spectrum = null;
        try {
            spectrum = scan.fetchSpectrum();
        } catch (FileParsingException ex) {
            Exceptions.printStackTrace(ex);
        }
        if (spectrum == null) {
            continue;
        }

        y = extrapolateRtToY(scan.getRt());
        filledRowIds[idx] = y;
        idx++;
        if (y > this.map.length - 1) {
            OutputWndPrinter.printErr("DEBUG", String.format(
                    "BaseMap2D: (y > this.map.length-1) for scan #%d.\n" + "\ty=%d, len-1=%d, height=%d\n"
                            + "\trt=%.20f, rtStart=%.20f, rtEnd=%.20f, rtSpan=%.20f",
                    scan.getNum(), y, this.map.length - 1, height, scan.getRt(), rtLo, rtHi, rtSpan));
        }
        masses = spectrum.getMZs();
        intensities = spectrum.getIntensities();

        mzIdxLo = spectrum.findMzIdxCeiling(mzLo);
        mzIdxHi = spectrum.findMzIdxFloor(mzHi);
        if (mzIdxLo == null || mzIdxHi == null) {
            OutputWndPrinter.printErr("DEBUG", String.format(
                    "BaseMap2D: mzIdxLo or mzIdxHi were null for scan #%d. " + "Not filling the map from them.",
                    scan.getNum()));
            continue;
        }
        if (mzIdxLo < 0 || mzIdxLo > masses.length - 1) {
            OutputWndPrinter.printErr("DEBUG", String.format(
                    "BaseMap2D: (mzIdxLo < 0 || mzIdxLo > masses.length-1) for scan #%d", scan.getNum()));
        }
        if (mzIdxHi < 0 || mzIdxHi > masses.length - 1) {
            OutputWndPrinter.printErr("DEBUG", String.format(
                    "BaseMap2D: (mzIdxHi < 0 || mzIdxHi > masses.length-1) for scan #%d", scan.getNum()));
        }

        double denoiseThreshold = Double.NaN;
        boolean applyDenoise = isDoDenoise();
        if (applyDenoise) {
            long start = System.nanoTime();
            denoiseThreshold = findDenoiseThreshold(masses, intensities);
            double denoisingTime = (System.nanoTime() - start) / 1e6;
            denoisingTimeCounter = denoisingTimeCounter + denoisingTime;
            if (Double.isNaN(denoiseThreshold)) {
                applyDenoise = false;
            }
        }

        double maxInt = spectrum.getMaxInt();
        for (int i = mzIdxLo; i <= mzIdxHi; i++) {

            x = extrapolateMzToX(masses[i]);
            addPeakRaw(x, y, intensities[i]);

            if (applyDenoise && intensities[i] < denoiseThreshold) {
                continue;
            }
            if (x > this.map[0].length - 1) {
                OutputWndPrinter.printErr("DEBUG", String.format(
                        "BaseMap2D: (x > this.map[0].length-1) for scan #%d.\n"
                                + "\tx=%d, len-1=%d, width=%d,\n"
                                + "\ti=%d, masses[i]=%.20f, mzStart=%.20f, mzEnd=%.20f, mzSpan=%.20f",
                        scan.getNum(), x, this.map[0].length - 1, width, i, masses[i], mzLo, mzHi, mzSpan));
            }

            // boost if present in previous/next scan
            // boost if present in previous/next scan// boost if present in previous/next scan// boost if present in previous/next scan// boost if present in previous/next scan// boost if present in previous/next scan
            //                double curIntensity = intensities[i];
            //                final int maxScanSpan = 2000;
            //                int numScansDisplayed = scansByRtSpanAtMsLevel.size();
            //                if (false && numScansDisplayed <= maxScanSpan) {
            //                    double maxIntInVicinity;
            //                    double intensityUpdateFactor = 1;
            //                    double dm, dmPpm, dmUpdateFactor;
            //                    int maxIntIdx;
            //                    double[] curInts, curMzs;
            //
            //                    final int scanNumShift = 1;
            //                    final double ppmTolerance = 15d;
            //
            //                    if (scan.getNum() % 1000 == 0) {
            //                        System.out.printf("Averaging for scan %d\n", scan.getNum());
            //                    }
            //                    scansToAverage[0] = mapNum2scan.get(scan.getNum() - scanNumShift*2);
            //                    scansToAverage[1] = mapNum2scan.get(scan.getNum() - scanNumShift);
            //                    scansToAverage[2] = mapNum2scan.get(scan.getNum() + scanNumShift);
            //                    scansToAverage[3] = mapNum2scan.get(scan.getNum() + scanNumShift*2);
            //                    double curMass = masses[i];
            //
            //                    for (IScan avgScan : scansToAverage) {                        
            //                        if (avgScan == null) {
            //                            continue;
            //                        }
            //                        ISpectrum s = avgScan.getSpectrum();
            //                        if (s == null) {
            //                            continue;
            //                        }
            //                        int[] mzIdxs = s.findMzIdxsWithinPpm(curMass, ppmTolerance);
            //                        dm = Double.NEGATIVE_INFINITY;
            //                        dmUpdateFactor = 1;
            //                        intensityUpdateFactor = 1;
            //                        if (mzIdxs != null) {
            //                            curInts = s.getIntensities();
            //                            curMzs = s.getMZs();
            //                            maxIntIdx = -1;
            //                            maxIntInVicinity = Double.NEGATIVE_INFINITY;
            //                            for (int j = mzIdxs[0]; j <= mzIdxs[1]; j++) {
            //                                if (curInts[j] > maxIntInVicinity) {
            //                                    maxIntIdx = j;
            //                                }
            //                            }
            //                            if (maxIntIdx != -1) {
            //                                intensityUpdateFactor = curInts[maxIntIdx];
            //                                dm = Math.abs(curMass - curMzs[maxIntIdx]);
            //
            //                                dmPpm = dm / (curMass / 1e6d);
            //                                if (dmPpm > ppmTolerance) {
            //                                    dmUpdateFactor = 0d;
            //                                    throw new IllegalStateException("dmUpdateFactor set to zero, should not happen");
            //                                } else {
            //                                    dmUpdateFactor = (1 - Math.pow(dmPpm / ppmTolerance, 2d));
            //                                }
            //                            } else {
            //                                throw new IllegalStateException("Strange condition, should never be triggered");
            //                            }
            //                        } else {
            //                            // if masses in the vicinity not found, then penalize
            //                            // TODO: this should be dependent on the chosen distribution for mass deviations
            //                            //       see dmFactor
            //                            intensityUpdateFactor = 1;
            //                            dmUpdateFactor = (1 - Math.pow(0.5d, 2d));
            //                        }
            //                        
            //                        curIntensity = curIntensity * (intensityUpdateFactor * dmUpdateFactor);
            //                    }
            //                }

            //                addPeak(x, y, curIntensity);
            addPeak(x, y, intensities[i]);
            maxValInFullRow[y] = maxInt;
            //                if (curIntensity > 1e6) {
            //                    addPeak(x, y, curIntensity);
            //                }

        }

        if (hasProfile && doProfileModeGapFilling) {
            double pixelSizeMz = getMzSpan() / availableWidth;
            if (pixelSizeMz < 0.05) {
                fillProfileGaps(0, y, pixelSizeMz);
            }
        }
    }
    if (isDoDenoise()) {
        OutputWndPrinter.printErr("DEBUG", String.format("Denoising took on average: %.2fms (%d scans)\n",
                (denoisingTimeCounter) / scansByRtSpanAtMsLevel.size(), scansByRtSpanAtMsLevel.size()));
    }

    if (hasProfile) { // profile mode spectrum
        if (!doProfileModeGapFilling && doMzCloseZoomGapFilling) {
            applySavitzkyGolay(map);
        }
    } else { // !hasProfile => centroided spectrum
        if (doMzCloseZoomGapFilling) {
            applySavitzkyGolay(map);
        }
    }

    findMinMaxIntensities();

    // if we created the full-sized version of the map, then a lot of rows might
    // be zero, because no scan actually mapped to this row of pixels
    // so we just fill it with the same pixels as in the previous filled row.
    if (doInterpRt) {
        for (int filledRowIdx = 0; filledRowIdx < filledRowIds.length - 1; filledRowIdx++) {
            int rowLo = filledRowIds[filledRowIdx];
            int rowHi = filledRowIds[filledRowIdx + 1];
            for (int rowToFillIdx = rowLo + 1; rowToFillIdx < rowHi; rowToFillIdx++) {
                System.arraycopy(map[rowLo], 0, map[rowToFillIdx], 0, width);
                maxValInFullRow[rowToFillIdx] = maxValInFullRow[rowLo];
            }
        }
    }

    // add a tiny bit to the total intensity, allows not to care about
    // edge values when mapping intensities to colors.
    // Adding MIN_NORMAL, as totalIntensity shoule be a value > 1.0
    totalIntensityMax += 1e-8;
    return true;
}