Example usage for java.util SortedMap lastKey

List of usage examples for java.util SortedMap lastKey

Introduction

In this page you can find the example usage for java.util SortedMap lastKey.

Prototype

K lastKey();

Source Link

Document

Returns the last (highest) key currently in this map.

Usage

From source file:eu.trentorise.opendata.josman.Josmans.java

public static SemVersion latestVersion(String repoName, List<RepositoryTag> tags) {
    TodUtils.checkNotEmpty(tags, "Invalid repository tags!");
    SortedMap<String, RepositoryTag> filteredTags = Josmans.versionTags(repoName, tags);
    if (filteredTags.isEmpty()) {
        throw new NotFoundException("Couldn't find any released version!");
    }//w w  w .  j  a va  2s .c  om
    return Josmans.version(repoName, filteredTags.lastKey());
}

From source file:org.fede.util.Util.java

private static MoneyAmountSeries read(String name) {

    try (InputStream is = Util.class.getResourceAsStream("/" + name)) {

        final JSONSeries series = CONSULTATIO_SERIES.contains(name) ? readConsultatioSeries(is, OM)
                : OM.readValue(is, JSONSeries.class);

        final SortedMap<YearMonth, MoneyAmount> interpolatedData = new TreeMap<>();
        final String currency = series.getCurrency();
        for (JSONDataPoint dp : series.getData()) {
            if (interpolatedData.put(new YearMonth(dp.getYear(), dp.getMonth()),
                    new MoneyAmount(dp.getValue(), currency)) != null) {
                throw new IllegalArgumentException("Series " + name + " has two values for year " + dp.getYear()
                        + " and month " + dp.getMonth());
            }/* ww w  .  ja  va 2 s. c  o m*/
        }

        final InterpolationStrategy strategy = InterpolationStrategy.valueOf(series.getInterpolation());

        YearMonth ym = interpolatedData.firstKey();
        final YearMonth last = interpolatedData.lastKey();
        while (ym.monthsUntil(last) > 0) {
            YearMonth next = ym.next();
            if (!interpolatedData.containsKey(next)) {
                interpolatedData.put(next, strategy.interpolate(interpolatedData.get(ym), ym, currency));
            }
            ym = ym.next();
        }
        return new SortedMapMoneyAmountSeries(currency, interpolatedData);

    } catch (IOException ioEx) {
        throw new IllegalArgumentException("Could not read series named " + name, ioEx);
    }

}

From source file:FocusTraversalExample.java

public Component getLastComponent(Container focusCycleRoot) {
    SortedMap buttons = getSortedButtons(focusCycleRoot);
    if (buttons.isEmpty()) {
        return null;
    }//  ww w  .j ava2 s  . co  m
    return (Component) buttons.get(buttons.lastKey());
}

From source file:org.sakuli.services.forwarder.gearman.model.NagiosCheckResultTest.java

@Test
public void testGetPayload() throws Exception {

    NagiosCheckResult checkResult = testling.build();

    SortedMap<PayLoadFields, String> map = checkResult.getPayload();
    Assert.assertEquals(map.firstKey(), PayLoadFields.TYPE);
    Assert.assertEquals(map.lastKey(), PayLoadFields.OUTPUT);
}

From source file:org.apache.hadoop.io.compress.CompressionCodecFactory.java

/**
 * Find the relevant compression codec for the given file based on its
 * filename suffix./*from w  w  w .j ava2  s.  com*/
 * @param file the filename to check
 * @return the codec object
 */
public CompressionCodec getCodec(Path file) {
    CompressionCodec result = null;
    if (codecs != null) {
        String filename = file.getName();
        String reversedFilename = new StringBuffer(filename).reverse().toString();
        SortedMap<String, CompressionCodec> subMap = codecs.headMap(reversedFilename);
        if (!subMap.isEmpty()) {
            String potentialSuffix = subMap.lastKey();
            if (reversedFilename.startsWith(potentialSuffix)) {
                result = codecs.get(potentialSuffix);
            }
        }
    }
    return result;
}

From source file:FocusTraversalExample.java

public Component getComponentBefore(Container focusCycleRoot, Component aComponent) {
    if (!(aComponent instanceof JButton)) {
        return null;
    }//  w w w.  j  a va2 s . c  o  m

    SortedMap buttons = getSortedButtons(focusCycleRoot);
    SortedMap prevButtons = // Find all buttons before this one.
            buttons.headMap(((JButton) aComponent).getText());
    if (prevButtons.isEmpty()) { // Wrapped back to end.
        if (!buttons.isEmpty()) {
            return (Component) buttons.get(buttons.lastKey());
        }
        return null; // Degenerate case of no buttons.
    }
    return (Component) prevButtons.get(prevButtons.lastKey());
}

From source file:no.ssb.jsonstat.v2.deser.DatasetDeserializer.java

List<Number> parseValues(JsonParser p, DeserializationContext ctxt) throws IOException {
    List<Number> result = Collections.emptyList();
    switch (p.getCurrentToken()) {
    case START_OBJECT:
        SortedMap<Integer, Number> map = p.readValueAs(VALUES_MAP);
        result = new AbstractList<Number>() {

            @Override/*  www. jav  a2 s.  com*/
            public int size() {
                return map.lastKey() + 1;
            }

            @Override
            public Number get(int index) {
                return map.get(index);
            }
        };
        break;
    case START_ARRAY:
        result = p.readValueAs(VALUES_LIST);
        break;
    default:
        ctxt.handleUnexpectedToken(this._valueClass, p.getCurrentToken(), p, "msg");
    }
    return result;
}

From source file:org.languagetool.rules.spelling.suggestions.SuggestionsChanges.java

private List<Map<String, Object>> gridsearch(SortedMap<String, List<Object>> grid,
        List<Map<String, Object>> current) {
    if (grid.isEmpty()) { // recursion exit
        return current;
    }//w  w w .  ja va  2  s .  co  m

    String name = grid.lastKey();
    List<Object> params = grid.get(name);
    List<Map<String, Object>> result = new LinkedList<>();

    if (current.isEmpty()) {
        for (Object value : params) {
            result.add(Collections.singletonMap(name, value));
        }
    } else {
        for (Map<String, Object> entry : current) {
            for (Object value : params) {
                Map<String, Object> modified = new HashMap<>(entry);
                modified.put(name, value);
                result.add(modified);
            }
        }
    }

    return gridsearch(grid.headMap(name), result);
}

From source file:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java

private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) {
    final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap();

    final Date base = ptr.getTime();

    final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base);
    final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base);

    if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base))
        return getDataSet(headMap.get(headMap.lastKey()), type);
    else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base))
        return getDataSet(tailMap.get(tailMap.firstKey()), type);

    return null;//ww  w.ja  v a  2s  .c  om
}

From source file:org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender.java

private void updateMessageDetails(String message, Long eventTimeSeconds,
        Map<String, SortedMap<Long, Integer>> map, SortedMap<Long, Integer> timestampsCount,
        SortedSet<PurgeElement> purgeInformation) {
    synchronized (lock) {
        if (map.containsKey(message)) {
            SortedMap<Long, Integer> tmp = map.get(message);
            Long lastMessageTime = tmp.lastKey();
            int value = 1;
            if (tmp.containsKey(eventTimeSeconds)) {
                value = tmp.get(eventTimeSeconds) + 1;
            }//from   w  w  w.jav a2s. c o  m
            tmp.put(eventTimeSeconds, value);
            purgeInformation.remove(new PurgeElement(message, lastMessageTime));
        } else {
            SortedMap<Long, Integer> value = new TreeMap<>();
            value.put(eventTimeSeconds, 1);
            map.put(message, value);
            if (map.size() > maxUniqueMessages * 2) {
                cleanupTimer.cancel();
                cleanupTimer = new Timer();
                cleanupTimer.schedule(new ErrorAndWarningsCleanup(), 0);
            }
        }
        purgeInformation.add(new PurgeElement(message, eventTimeSeconds));
        int newValue = 1;
        if (timestampsCount.containsKey(eventTimeSeconds)) {
            newValue = timestampsCount.get(eventTimeSeconds) + 1;
        }
        timestampsCount.put(eventTimeSeconds, newValue);
    }
}