Example usage for java.util NavigableMap firstEntry

List of usage examples for java.util NavigableMap firstEntry

Introduction

In this page you can find the example usage for java.util NavigableMap firstEntry.

Prototype

Map.Entry<K, V> firstEntry();

Source Link

Document

Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

Usage

From source file:org.noroomattheinn.visibletesla.TripController.java

private void updateStartEndProps(String statType, long startTime, long endTime, GenericProperty prop,
        double conversionFactor) {
    NavigableMap<Long, Row> rows = vtData.getRangeOfLoadedRows(startTime, endTime);

    double startValue = rows.firstEntry().getValue().get(VTData.schema, statType);
    double endValue = rows.lastEntry().getValue().get(VTData.schema, statType);
    prop.setValue(String.format("%.1f", startValue * conversionFactor));
    prop.setUnits(String.format("%.1f", endValue * conversionFactor));
}

From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java

public List<Interval> checkDistribution(PDRTAState s, int alphIdx, DistributionCheckType type,
        StateColoring sc) {/* w w w .  j a  va 2 s .  c  o m*/

    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.
 * /*from  ww  w.j  a v  a 2s. c o  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);
        }
    }
}