List of usage examples for java.util NavigableSet tailSet
SortedSet<E> tailSet(E fromElement);
Equivalent to tailSet(fromElement, true) .
From source file:uk.org.taverna.platform.report.StatusReport.java
/** * Get an invocation with a given name./* www .j av a 2 s. co m*/ * @param invocationName * @return */ public Invocation getInvocation(String invocationName) { NavigableSet<Invocation> invocs = getInvocations(); // A Comparable Invocation with the desired name SortedSet<Invocation> tailSet = invocs.tailSet(new Invocation(invocationName)); if (!tailSet.isEmpty()) return tailSet.first(); return null; }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.tailSet(Object)' and * '@see java.util.NavigableSet.tailSet(Object, boolean)'. * * @see java.util.SortedSet#tailSet(Object) * @see java.util.NavigableSet#tailSet(Object, boolean) *//* w w w . j ava 2s . com*/ public void testTailSet_entries0() { // test with no entries NavigableSet<E> navigableSet = createNavigableSet(); assertNotNull(navigableSet.tailSet(getKeys()[0])); assertNotNull(navigableSet.tailSet(getKeys()[0], false)); assertNotNull(navigableSet.tailSet(getKeys()[0], true)); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.tailSet(Object)' and * '@see java.util.NavigableSet.tailSet(Object, boolean)'. * * @see java.util.SortedSet#tailSet(Object) * @see java.util.NavigableSet#tailSet(Object, boolean) *///from ww w. ja v a 2 s . c om public void testTailSet_entries0_size() { // test with no entries NavigableSet<E> navigableSet = createNavigableSet(); Set<E> tailSet = navigableSet.tailSet(getKeys()[0]); assertNotNull(tailSet); assertEquals(0, tailSet.size()); Set<E> exclusiveTailSet = navigableSet.tailSet(getKeys()[0], false); assertNotNull(exclusiveTailSet); assertEquals(0, exclusiveTailSet.size()); Set<E> inclusiveTailSet = navigableSet.tailSet(getKeys()[0], true); assertNotNull(inclusiveTailSet); assertEquals(0, inclusiveTailSet.size()); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.tailSet(Object)' and * '@see java.util.NavigableSet.tailSet(Object, boolean)'. * * @see java.util.SortedSet#tailSet(Object) * @see java.util.NavigableSet#tailSet(Object, boolean) */// www . j ava 2 s . co m public void testTailSet_entries1_size_keyValue() { NavigableSet<E> sortedSet = createNavigableSet(); // test with a single entry set sortedSet.add(getKeys()[0]); Set<E> tailSet = sortedSet.tailSet(getKeys()[0]); assertEquals(1, tailSet.size()); assertEquals(getKeys()[0], tailSet.toArray()[0]); Set<E> exclusiveTailSet = sortedSet.tailSet(getKeys()[0], false); assertEquals(0, exclusiveTailSet.size()); assertEquals(0, exclusiveTailSet.size()); Set<E> inclusiveTailSet = sortedSet.tailSet(getKeys()[0], true); assertEquals(1, inclusiveTailSet.size()); assertEquals(getKeys()[0], inclusiveTailSet.toArray()[0]); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.tailSet(Object)' and * '@see java.util.NavigableSet.tailSet(Object, boolean)'. * * @see java.util.SortedSet#tailSet(Object) * @see java.util.NavigableSet#tailSet(Object, boolean) *///from w w w.jav a 2 s.c o m public void testTailSet_entries2_size_keyValue() { NavigableSet<E> sortedSet = createNavigableSet(); // test with two entry set sortedSet.add(getKeys()[0]); Set<E> tailSet = sortedSet.tailSet(getKeys()[0]); assertEquals(1, tailSet.size()); Set<E> exclusiveTailMap = sortedSet.tailSet(getKeys()[0], false); assertEquals(0, exclusiveTailMap.size()); Set<E> inclusiveTailMap = sortedSet.tailSet(getKeys()[0], true); assertEquals(1, inclusiveTailMap.size()); sortedSet.add(getKeys()[1]); tailSet = sortedSet.tailSet(getKeys()[1]); assertEquals(1, tailSet.size()); exclusiveTailMap = sortedSet.tailSet(getKeys()[1], false); assertEquals(0, exclusiveTailMap.size()); inclusiveTailMap = sortedSet.tailSet(getKeys()[1], true); assertEquals(1, inclusiveTailMap.size()); tailSet = sortedSet.tailSet(getKeys()[0]); assertEquals(2, tailSet.size()); assertEquals(getKeys()[0], tailSet.toArray()[0]); assertEquals(getKeys()[1], tailSet.toArray()[1]); exclusiveTailMap = sortedSet.tailSet(getKeys()[0], false); assertEquals(1, exclusiveTailMap.size()); assertEquals(getKeys()[1], exclusiveTailMap.toArray()[0]); inclusiveTailMap = sortedSet.tailSet(getKeys()[0], true); assertEquals(2, inclusiveTailMap.size()); assertEquals(getKeys()[0], inclusiveTailMap.toArray()[0]); assertEquals(getKeys()[1], inclusiveTailMap.toArray()[1]); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.headSet(Object)' and * 'java.util.NavigableSet.headSet(Object, boolean)'. * * @see java.util.SortedSet#headSet(Object) * @see java.util.NavigableSet#headSet(Object, boolean) *///w w w . jav a2s .c o m public void testHeadSet_entries2() { NavigableSet<E> set = createNavigableSet(); // test with two entry set set.add(getKeys()[0]); set.add(getKeys()[1]); assertEquals(0, set.headSet(getKeys()[0]).size()); assertEquals(1, set.headSet(getKeys()[1]).size()); assertEquals(getKeys()[0], set.tailSet(getKeys()[0]).toArray()[0]); assertEquals(0, set.headSet(getKeys()[0], false).size()); assertEquals(1, set.headSet(getKeys()[1], false).size()); assertEquals(getKeys()[0], set.headSet(getKeys()[0], true).toArray()[0]); assertEquals(1, set.headSet(getKeys()[0], true).size()); assertEquals(2, set.headSet(getKeys()[1], true).size()); assertEquals(getKeys()[0], set.headSet(getKeys()[1], false).toArray()[0]); assertEquals(getKeys()[1], set.headSet(getKeys()[1], true).toArray()[1]); assertEquals(0, set.headSet(getKeys()[0], false).size()); assertEquals(getKeys()[1], set.headSet(getKeys()[1], true).toArray()[1]); }
From source file:org.apache.hadoop.hbase.regionserver.AbstractMemStore.java
protected Cell getNextRow(final Cell key, final NavigableSet<Cell> set) { Cell result = null;//from www .j av a 2 s . com SortedSet<Cell> tail = key == null ? set : set.tailSet(key); // Iterate until we fall into the next row; i.e. move off current row for (Cell cell : tail) { if (comparator.compareRows(cell, key) <= 0) { continue; } // Note: Not suppressing deletes or expired cells. Needs to be handled // by higher up functions. result = cell; break; } return result; }
From source file:org.apache.hadoop.hbase.regionserver.DefaultMemStore.java
private KeyValue getNextRow(final KeyValue key, final NavigableSet<KeyValue> set) { KeyValue result = null;//from ww w. j a va2s. c om SortedSet<KeyValue> tail = key == null ? set : set.tailSet(key); // Iterate until we fall into the next row; i.e. move off current row for (KeyValue kv : tail) { if (comparator.compareRows(kv, key) <= 0) continue; // Note: Not suppressing deletes or expired cells. Needs to be handled // by higher up functions. result = kv; break; } return result; }
From source file:org.apache.hadoop.hbase.regionserver.Memcache.java
private KeyValue getNextRow(final KeyValue kv, final NavigableSet<KeyValue> set) { KeyValue result = null;/*from ww w . j av a 2 s . c om*/ SortedSet<KeyValue> tailset = kv == null ? set : set.tailSet(kv); // Iterate until we fall into the next row; i.e. move off current row for (KeyValue i : tailset) { if (comparator.compareRows(i, kv) <= 0) continue; // Note: Not suppressing deletes or expired cells. Needs to be handled // by higher up functions. result = i; break; } return result; }
From source file:org.apache.hadoop.hbase.regionserver.Memcache.java
private void getRowKeyBefore(ConcurrentSkipListSet<KeyValue> set, KeyValue search, NavigableSet<KeyValue> candidates, final NavigableSet<KeyValue> deletes, final long now) { NavigableSet<KeyValue> headSet = set.headSet(search); // If we tried to create a headMap and got an empty map, then there are // no keys at or before the search key, so we're done. if (headSet.isEmpty()) { return;//ww w . j a va 2 s . c o m } // If there aren't any candidate keys at this point, we need to search // backwards until we find at least one candidate or run out of headMap. if (candidates.isEmpty()) { KeyValue lastFound = null; for (Iterator<KeyValue> i = headSet.descendingIterator(); i.hasNext();) { KeyValue found = i.next(); // if the last row we found a candidate key for is different than // the row of the current candidate, we can stop looking -- if its // not a delete record. boolean deleted = found.isDeleteType(); if (lastFound != null && this.comparator.matchingRows(lastFound, found) && !deleted) { break; } // If this isn't a delete, record it as a candidate key. Also // take note of this candidate so that we'll know when // we cross the row boundary into the previous row. if (!deleted) { if (Store.notExpiredAndNotInDeletes(this.ttl, found, now, deletes)) { lastFound = found; candidates.add(found); } else { // Its expired. Store.expiredOrDeleted(set, found); } } else { // We are encountering items in reverse. We may have just added // an item to candidates that this later item deletes. Check. If we // found something in candidates, remove it from the set. if (Store.handleDeletes(found, candidates, deletes)) { remove(set, found); } } } } else { // If there are already some candidate keys, we only need to consider // the very last row's worth of keys in the headMap, because any // smaller acceptable candidate keys would have caused us to start // our search earlier in the list, and we wouldn't be searching here. SortedSet<KeyValue> rowTailMap = headSet.tailSet(headSet.last().cloneRow(HConstants.LATEST_TIMESTAMP)); Iterator<KeyValue> i = rowTailMap.iterator(); do { KeyValue found = i.next(); if (found.isDeleteType()) { Store.handleDeletes(found, candidates, deletes); } else { if (ttl == HConstants.FOREVER || now < found.getTimestamp() + ttl || !deletes.contains(found)) { candidates.add(found); } else { Store.expiredOrDeleted(set, found); } } } while (i.hasNext()); } }