List of usage examples for java.util NavigableMap firstKey
K firstKey();
From source file:org.opennms.netmgt.snmp.mock.PropertyOidContainer.java
public SnmpObjId findNextOidForOid(final SnmpObjId oid) { final NavigableMap<SnmpObjId, SnmpValue> next = m_tree.tailMap(oid, false); if (next.size() == 0) { return null; } else {/*w w w . j a v a2s . c om*/ return next.firstKey(); } }
From source file:org.wisdom.raml.visitor.RamlControllerVisitor.java
/** * Navigate through the Controller routes, and create {@link org.raml.model.Resource} from them. * If the <code>parent</code> is not null, then the created route will be added has children of the parent, otherwise * a new Resource is created and will be added directly to the <code>raml</code> model. * * @param routes The @{link ControllerRoute} * @param parent The parent {@link Resource} * @param raml The {@link Raml} model//from w ww .jav a2 s. c o m */ private void navigateTheRoutes(NavigableMap<String, Collection<ControllerRouteModel<Raml>>> routes, Resource parent, Raml raml) { //nothing to see here if (routes == null || routes.isEmpty()) { return; } String headUri = routes.firstKey(); LOGGER.debug("Routes " + routes.toString()); LOGGER.debug("Parent " + parent); Collection<ControllerRouteModel<Raml>> siblings = routes.get(headUri); String relativeUri; Resource res = new Resource(); if (parent != null) { res.setParentResource(parent); res.setParentUri(parent.getUri()); //Get the relative part of the url relativeUri = normalizeActionPath(parent, headUri); res.setRelativeUri(relativeUri); parent.getResources().put(res.getRelativeUri(), res); } else { // We don't have a parent, check whether we should create one. if (headUri.endsWith("/")) { // We have to create a 'fake' parent when we have such kind of url: /foo/ // We create a parent /foo and a sub-resource /, this is because /foo and /foo/ are different // Create a parent - this parent doest not have any action attached. String parentUri = normalizeParentPath(headUri); // However we do have a tricky case here, if parentURi == "/", we are the parent. if (!parentUri.equals("/")) { parent = new Resource(); parent.setParentUri(""); parent.setRelativeUri(parentUri); raml.getResources().put(parentUri, parent); // Now manage the current resource, it's uri is necessarily / relativeUri = "/"; res.setParentUri(parent.getUri()); res.setRelativeUri(relativeUri); parent.getResources().put(relativeUri, res); } else { // We are the root. res.setParentUri(""); relativeUri = normalizeParentPath(headUri); res.setRelativeUri(relativeUri); raml.getResources().put(res.getRelativeUri(), res); } } else { // No parent res.setParentUri(""); relativeUri = normalizeParentPath(headUri); res.setRelativeUri(relativeUri); raml.getResources().put(res.getRelativeUri(), res); } } //Add the action from the brother routes for (ControllerRouteModel<Raml> bro : siblings) { addActionFromRouteElem(bro, res); } //visit the children route NavigableMap<String, Collection<ControllerRouteModel<Raml>>> child = routes.tailMap(headUri, false); //no more route element if (child.isEmpty()) { return; } final String next = child.firstKey(); final Resource maybeParent = findParent(next, raml); navigateTheRoutes(child, maybeParent, raml); }
From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java
public List<Interval> checkDistribution(PDRTAState s, int alphIdx, DistributionCheckType type, StateColoring sc) {/*from w w w.ja va2 s .c om*/ final NavigableMap<Integer, Interval> ins = s.getIntervals(alphIdx); if (ins.size() != 1) { return Collections.emptyList(); } final Interval in = ins.firstEntry().getValue(); if (in.isEmpty()) { return Collections.emptyList(); } int tolerance; if (type.equals(DistributionCheckType.DISABLED)) { return Collections.emptyList(); } else if (type.equals(DistributionCheckType.STRICT_BORDER) || type.equals(DistributionCheckType.STRICT)) { tolerance = 0; } else if (type.equals(DistributionCheckType.MAD_BORDER) || type.equals(DistributionCheckType.MAD)) { tolerance = getToleranceMAD(in, PDRTA.getMinData()); } else if (type.equals(DistributionCheckType.OUTLIER_BORDER) || type.equals(DistributionCheckType.OUTLIER)) { tolerance = getToleranceOutliers(in, PDRTA.getMinData()); } else { throw new IllegalArgumentException("Nonexistent type used!"); } final NavigableMap<Integer, Collection<TimedTail>> tails = in.getTails().asMap(); final List<Integer> splits = new ArrayList<>(); if ((type.ordinal() - 1) % 2 != 0) { // The types without border final Iterator<Entry<Integer, Collection<TimedTail>>> it = tails.entrySet().iterator(); if (it.hasNext()) { Entry<Integer, Collection<TimedTail>> ePrev = it.next(); int t = ePrev.getKey().intValue(); if (in.getBegin() <= t - tolerance - 1) { splits.add(new Integer(t - tolerance - 1)); } while (it.hasNext()) { final Entry<Integer, Collection<TimedTail>> eCurr = it.next(); t = ePrev.getKey().intValue(); final int t2 = eCurr.getKey().intValue(); final int diff = t2 - t - 1; if (diff > 2 * tolerance) { splits.add(new Integer(t + tolerance)); splits.add(new Integer(t2 - tolerance - 1)); } ePrev = eCurr; } t = ePrev.getKey().intValue(); if (in.getEnd() > t + tolerance) { splits.add(new Integer(t + tolerance)); } } } else { int t = tails.firstKey().intValue(); if (in.getBegin() <= t - tolerance - 1) { splits.add(new Integer(t - tolerance - 1)); } t = tails.lastKey().intValue(); if (in.getEnd() > t + tolerance) { splits.add(new Integer(t + tolerance)); } } // Interval cIn = new Interval(in); // for (int i = 0; i < splits.size(); i++) { // cIn.split(splits.get(i)); // // TODO test resulting intervals for containing more than minData // // tails otherwise remove split // } if (splits.size() == 0) { return Collections.emptyList(); } final List<Interval> resultingIns = new ArrayList<>(splits.size() + 1); Pair<Interval, Interval> splittedIns = null; for (int i = 0; i < splits.size(); i++) { splittedIns = OperationUtil.split(s, alphIdx, splits.get(i).intValue(), sc); if (!splittedIns.getLeft().isEmpty()) { resultingIns.add(splittedIns.getLeft()); } } if (splittedIns != null && !splittedIns.getRight().isEmpty()) { resultingIns.add(splittedIns.getRight()); } return resultingIns; }
From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java
/** * Calculates the maximum allowed size for an empty interval part when only few {@link TimedTail}s use this interval. The allowed size depends on the * parameter for the minimum amount of {@link TimedTail}s and the distance between the occupied slots. * /* w ww .ja v a2 s . co m*/ * @param minData * The minimum amount of {@link TimedTail}s * @return The maximum allowed size for an empty interval part */ private int getToleranceFewSlots(Interval in, int minData) { final NavigableMap<Integer, Collection<TimedTail>> tails = in.getTails().asMap(); final int slots = tails.size(); assert (slots > 0 && slots <= 2); if (slots == 1) { final int size = tails.firstEntry().getValue().size(); if (size < (minData / 2.0)) { return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.05); } else { return 0; } } else { final Integer t1Int = tails.firstKey(); final int s1 = tails.get(t1Int).size(); final Integer t2Int = tails.lastKey(); final int s2 = tails.get(t2Int).size(); final int t1 = t1Int.intValue(); final int t2 = t2Int.intValue(); final double perc = (double) (t2 - t1 - 1) / (double) (in.getEnd() - in.getBegin() - 1); if (s1 >= minData && s2 >= minData && perc >= 0.2) { return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.05); } else if ((s1 >= minData || s2 >= minData) && perc >= 0.2) { return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.075); } else { return (int) Math.ceil((t2 - t1 - 1) / 2.0); } } }
From source file:umich.ms.batmass.gui.viewers.map2d.components.BaseMap2D.java
/** * Fills the map given a scan collection. * @param scans//from ww w .j a v a2 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; }