本文整理汇总了Java中java.util.SortedMap.tailMap方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.tailMap方法的具体用法?Java SortedMap.tailMap怎么用?Java SortedMap.tailMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedMap
的用法示例。
在下文中一共展示了SortedMap.tailMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTailMapWriteThrough
import java.util.SortedMap; //导入方法依赖的package包/类
public void testTailMapWriteThrough() {
final SortedMap<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
}
if (map.size() < 2 || !supportsPut) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
subMap.put(key, value);
assertEquals(secondEntry.getValue(), value);
assertEquals(map.get(key), value);
try {
subMap.put(firstEntry.getKey(), value);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
示例2: testTailMapRemoveThrough
import java.util.SortedMap; //导入方法依赖的package包/类
public void testTailMapRemoveThrough() {
final SortedMap<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
}
int oldSize = map.size();
if (map.size() < 2 || !supportsRemove) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
subMap.remove(key);
assertNull(subMap.remove(firstEntry.getKey()));
assertEquals(map.size(), oldSize - 1);
assertFalse(map.containsKey(key));
assertEquals(subMap.size(), oldSize - 2);
}
示例3: testTailMapClearThrough
import java.util.SortedMap; //导入方法依赖的package包/类
public void testTailMapClearThrough() {
final SortedMap<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
}
int oldSize = map.size();
if (map.size() < 2 || !supportsClear) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
iterator.next(); // advance
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
int subMapSize = subMap.size();
subMap.clear();
assertEquals(map.size(), oldSize - subMapSize);
assertTrue(subMap.isEmpty());
}
示例4: testTailMap
import java.util.SortedMap; //导入方法依赖的package包/类
@Test
public void testTailMap() throws Exception {
for (int i = 0; i < 100; i++) {
map.put(i, String.valueOf(i));
}
SortedMap<Integer, String> tailMap = map.tailMap(21);
Assert.assertEquals(79, tailMap.size());
for (int i = 21; i < 100; i++) {
Assert.assertTrue(tailMap.containsKey(i));
}
SortedMap<Integer, String> tailTailMap = tailMap.tailMap(59);
Assert.assertEquals(41, tailTailMap.size());
for (int i = 59; i < 100; i++) {
Assert.assertTrue(tailTailMap.containsKey(i));
}
}
示例5: getRangeMap
import java.util.SortedMap; //导入方法依赖的package包/类
public static SortedMap<IMKey, RegionEntry> getRangeMap(
final SortedMap<IMKey, RegionEntry> rowMap, final IMKey startRow, final IMKey stopRow,
final boolean includeStartRow) {
SortedMap<IMKey, RegionEntry> result;
if (startRow == null && stopRow == null) {
result = rowMap;
} else if (startRow == null) {
// result = rowMap.headMap(stopRow, false);
result = rowMap instanceof NavigableMap
? ((NavigableMap<IMKey, RegionEntry>) rowMap).headMap(stopRow, false)
: rowMap.headMap(stopRow);
} else if (stopRow == null) {
// result = rowMap.tailMap(startRow, includeStartRow);
result = rowMap instanceof NavigableMap
? ((NavigableMap<IMKey, RegionEntry>) rowMap).tailMap(startRow, includeStartRow)
: rowMap.tailMap(startRow);
} else {
// result = rowMap.subMap(startRow, includeStartRow, stopRow, false);
result = subMap(rowMap, startRow, includeStartRow, stopRow, false);
}
return result;
}
示例6: findNextUsedLine
import java.util.SortedMap; //导入方法依赖的package包/类
static int findNextUsedLine(int from, SortedMap<Integer, List<Mark>> marks) {
SortedMap<Integer, List<Mark>> next = marks.tailMap(from + 1);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("AnnotationView.findNextUsedLine from: " + from + "; marks: " + marks + "; next: " + next); //NOI18N
}
if (next.isEmpty()) {
return Integer.MAX_VALUE;
}
return next.firstKey().intValue();
}
示例7: computeBackingRowMap
import java.util.SortedMap; //导入方法依赖的package包/类
@Override
SortedMap<C, V> computeBackingRowMap() {
SortedMap<C, V> map = wholeRow();
if (map != null) {
if (lowerBound != null) {
map = map.tailMap(lowerBound);
}
if (upperBound != null) {
map = map.headMap(upperBound);
}
return map;
}
return null;
}
示例8: createSubMap
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Calls the smallest subMap overload that filters out the extreme values. This method is
* overridden in NavigableMapTestSuiteBuilder.
*/
SortedMap<K, V> createSubMap(SortedMap<K, V> map, K firstExclusive, K lastExclusive) {
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
return map.headMap(lastExclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
return map.tailMap(firstInclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
return map.subMap(firstInclusive, lastExclusive);
} else {
throw new IllegalArgumentException();
}
}
示例9: getNextVertexOnDest
import java.util.SortedMap; //导入方法依赖的package包/类
public Vertex getNextVertexOnDest() {
SortedMap<Long, Vertex> map = graph.getIndexedVertices().get(name);
SortedMap<Long, Vertex> tailMap = map.tailMap(timestamp + 1);
if (tailMap.isEmpty()) {
return null;
} else {
return tailMap.get(tailMap.firstKey());
}
}
示例10: testLowestString
import java.util.SortedMap; //导入方法依赖的package包/类
@Test
public void testLowestString() {
SortedMap map = new TreeMap();
map.put("ab", "value");
map.put("z", "value");
map.put("v", "value");
SortedMap returnMap = map.tailMap(CompiledLike.LOWEST_STRING);
assertEquals(3, returnMap.size());
}
示例11: getErrorsGE
import java.util.SortedMap; //导入方法依赖的package包/类
public synchronized List<ErrorDescription> getErrorsGE(int offset) {
try {
int index = findPositionGE(Utilities.getRowStart(doc, offset));
if (index < 0) return Collections.emptyList();
while (index < knownPositions.size()) {
Position current = knownPositions.get(index++).get();
if (current == null) {
continue;
}
List<ErrorDescription> errors = line2Errors.get(current);
if (errors != null) {
SortedMap<Integer, List<ErrorDescription>> sortedErrors = new TreeMap<Integer, List<ErrorDescription>>();
for (ErrorDescription ed : errors) {
List<ErrorDescription> errs = sortedErrors.get(ed.getRange().getBegin().getOffset());
if (errs == null) {
sortedErrors.put(ed.getRange().getBegin().getOffset(), errs = new LinkedList<ErrorDescription>());
}
errs.add(ed);
}
SortedMap<Integer, List<ErrorDescription>> tail = sortedErrors.tailMap(offset);
if (!tail.isEmpty()) {
Integer k = tail.firstKey();
return new ArrayList<ErrorDescription>(sortedErrors.get(k));
}
}
}
return Collections.emptyList();
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
return Collections.emptyList();
}
}
示例12: testTailMapContents
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* headMap returns map with keys in requested range
*/
public void testTailMapContents() {
ConcurrentNavigableMap map = map5();
SortedMap sm = map.tailMap(two);
assertFalse(sm.containsKey(one));
assertTrue(sm.containsKey(two));
assertTrue(sm.containsKey(three));
assertTrue(sm.containsKey(four));
assertTrue(sm.containsKey(five));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
k = (Integer)(i.next());
assertEquals(four, k);
k = (Integer)(i.next());
assertEquals(five, k);
assertFalse(i.hasNext());
Iterator ei = sm.entrySet().iterator();
Map.Entry e;
e = (Map.Entry)(ei.next());
assertEquals(two, e.getKey());
assertEquals("B", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(three, e.getKey());
assertEquals("C", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(four, e.getKey());
assertEquals("D", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(five, e.getKey());
assertEquals("E", e.getValue());
assertFalse(i.hasNext());
SortedMap ssm = sm.tailMap(four);
assertEquals(four, ssm.firstKey());
assertEquals(five, ssm.lastKey());
assertEquals("D", ssm.remove(four));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, map.size());
}
示例13: testDescendingTailMapContents
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* headMap returns map with keys in requested range
*/
public void testDescendingTailMapContents() {
ConcurrentNavigableMap map = dmap5();
SortedMap sm = map.tailMap(m2);
assertFalse(sm.containsKey(m1));
assertTrue(sm.containsKey(m2));
assertTrue(sm.containsKey(m3));
assertTrue(sm.containsKey(m4));
assertTrue(sm.containsKey(m5));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer)(i.next());
assertEquals(m2, k);
k = (Integer)(i.next());
assertEquals(m3, k);
k = (Integer)(i.next());
assertEquals(m4, k);
k = (Integer)(i.next());
assertEquals(m5, k);
assertFalse(i.hasNext());
Iterator ei = sm.entrySet().iterator();
Map.Entry e;
e = (Map.Entry)(ei.next());
assertEquals(m2, e.getKey());
assertEquals("B", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m3, e.getKey());
assertEquals("C", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m4, e.getKey());
assertEquals("D", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m5, e.getKey());
assertEquals("E", e.getValue());
assertFalse(i.hasNext());
SortedMap ssm = sm.tailMap(m4);
assertEquals(m4, ssm.firstKey());
assertEquals(m5, ssm.lastKey());
assertEquals("D", ssm.remove(m4));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, map.size());
}
示例14: testTailMapContents
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* headMap returns map with keys in requested range
*/
public void testTailMapContents() {
NavigableMap map = map5();
SortedMap sm = map.tailMap(two);
assertFalse(sm.containsKey(one));
assertTrue(sm.containsKey(two));
assertTrue(sm.containsKey(three));
assertTrue(sm.containsKey(four));
assertTrue(sm.containsKey(five));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
k = (Integer)(i.next());
assertEquals(four, k);
k = (Integer)(i.next());
assertEquals(five, k);
assertFalse(i.hasNext());
Iterator ei = sm.entrySet().iterator();
Map.Entry e;
e = (Map.Entry)(ei.next());
assertEquals(two, e.getKey());
assertEquals("B", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(three, e.getKey());
assertEquals("C", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(four, e.getKey());
assertEquals("D", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(five, e.getKey());
assertEquals("E", e.getValue());
assertFalse(i.hasNext());
SortedMap ssm = sm.tailMap(four);
assertEquals(four, ssm.firstKey());
assertEquals(five, ssm.lastKey());
assertEquals("D", ssm.remove(four));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, map.size());
}
示例15: testDescendingTailMapContents
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* headMap returns map with keys in requested range
*/
public void testDescendingTailMapContents() {
NavigableMap map = dmap5();
SortedMap sm = map.tailMap(m2);
assertFalse(sm.containsKey(m1));
assertTrue(sm.containsKey(m2));
assertTrue(sm.containsKey(m3));
assertTrue(sm.containsKey(m4));
assertTrue(sm.containsKey(m5));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer)(i.next());
assertEquals(m2, k);
k = (Integer)(i.next());
assertEquals(m3, k);
k = (Integer)(i.next());
assertEquals(m4, k);
k = (Integer)(i.next());
assertEquals(m5, k);
assertFalse(i.hasNext());
Iterator ei = sm.entrySet().iterator();
Map.Entry e;
e = (Map.Entry)(ei.next());
assertEquals(m2, e.getKey());
assertEquals("B", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m3, e.getKey());
assertEquals("C", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m4, e.getKey());
assertEquals("D", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(m5, e.getKey());
assertEquals("E", e.getValue());
assertFalse(i.hasNext());
SortedMap ssm = sm.tailMap(m4);
assertEquals(m4, ssm.firstKey());
assertEquals(m5, ssm.lastKey());
assertEquals("D", ssm.remove(m4));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, map.size());
}