List of usage examples for java.util NavigableSet first
E first();
From source file:org.apache.hadoop.hbase.regionserver.Memcache.java
private void getRowKeyAtOrBefore(final ConcurrentSkipListSet<KeyValue> set, final KeyValue kv, final NavigableSet<KeyValue> candidates, final NavigableSet<KeyValue> deletes, final long now) { if (set.isEmpty()) { return;/*from w w w. j av a2 s .c om*/ } // We want the earliest possible to start searching from. Start before // the candidate key in case it turns out a delete came in later. KeyValue search = candidates.isEmpty() ? kv : candidates.first(); // Get all the entries that come equal or after our search key SortedSet<KeyValue> tailset = set.tailSet(search); // if there are items in the tail map, there's either a direct match to // the search key, or a range of values between the first candidate key // and the ultimate search key (or the end of the cache) if (!tailset.isEmpty() && this.comparator.compareRows(tailset.first(), search) <= 0) { // Keep looking at cells as long as they are no greater than the // ultimate search key and there's still records left in the map. KeyValue deleted = null; KeyValue found = null; for (Iterator<KeyValue> iterator = tailset.iterator(); iterator.hasNext() && (found == null || this.comparator.compareRows(found, kv) <= 0);) { found = iterator.next(); if (this.comparator.compareRows(found, kv) <= 0) { if (found.isDeleteType()) { Store.handleDeletes(found, candidates, deletes); if (deleted == null) { deleted = found; } } else { if (Store.notExpiredAndNotInDeletes(this.ttl, found, now, deletes)) { candidates.add(found); } else { if (deleted == null) { deleted = found; } // TODO: Check this removes the right key. // Its expired. Remove it. iterator.remove(); } } } } if (candidates.isEmpty() && deleted != null) { getRowKeyBefore(set, deleted, candidates, deletes, now); } } else { // The tail didn't contain any keys that matched our criteria, or was // empty. Examine all the keys that proceed our splitting point. getRowKeyBefore(set, search, candidates, deletes, now); } }
From source file:org.thelq.pircbotx.commands.NewYearsCommand.java
@Override public void onMessage(MessageEvent event) throws Exception { String[] commandParts = event.getMessage().split(" ", 2); if (commandParts.length != 2 || !ListenerUtils.isCommand(commandParts[0], "newyears")) return;/* w ww . j a v a2s . c o m*/ if (commandParts[1].equals("start")) start(); else if (commandParts[1].equals("year")) event.respond("Next year is " + NEW_YEAR); else if (commandParts[1].equals("next")) { ListenerUtils.incrimentCommands(event); String prefix = null; DateTime nextNewYear = null; if (waitingNewYear != null) { prefix = "Waiting for next New Years "; nextNewYear = waitingNewYear; } else { prefix = "Next New Years is "; nextNewYear = getNextNewYears(); if (nextNewYear == null) { event.respond("No more New Years :-("); return; } } NavigableSet<DateTimeZone> timezones = getNyTimes().get(nextNewYear); event.respond(prefix + "in " + Alarm.FORMATTER_REMAIN.print(new Period(getNow(), nextNewYear)) + "for " + getUTCOffset(timezones.first()) + " - " + getExtendedNames(timezones)); } }