本文整理匯總了Java中java.util.TreeSet.headSet方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeSet.headSet方法的具體用法?Java TreeSet.headSet怎麽用?Java TreeSet.headSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TreeSet
的用法示例。
在下文中一共展示了TreeSet.headSet方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testHeadSetContents
import java.util.TreeSet; //導入方法依賴的package包/類
/**
* headSet returns set with keys in requested range
*/
public void testHeadSetContents() {
TreeSet set = set5();
SortedSet sm = set.headSet(four);
assertTrue(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(one, k);
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
sm.clear();
assertTrue(sm.isEmpty());
assertEquals(2, set.size());
assertEquals(four, set.first());
}
示例2: getLockPath
import java.util.TreeSet; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected String getLockPath(String createdZNode, List<String> children) throws IOException {
TreeSet<String> writeChildren =
new TreeSet<String>(ZNodeComparator.COMPARATOR);
for (String child : children) {
if (isChildWriteLock(child)) {
writeChildren.add(child);
}
}
if (writeChildren.isEmpty()) {
return null;
}
SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode);
if (lowerChildren.isEmpty()) {
return null;
}
String pathToWatch = lowerChildren.last();
String nodeHoldingLock = lowerChildren.first();
String znode = ZKUtil.joinZNode(parentLockNode, nodeHoldingLock);
handleLockMetadata(znode);
return pathToWatch;
}
示例3: testOrder2
import java.util.TreeSet; //導入方法依賴的package包/類
@Test
public void testOrder2() {
TreeSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(3);
set.add(4);
set.add(5);
SortedSet<Integer> hs = set.headSet(6);
}
示例4: testHeadSetTreeSet
import java.util.TreeSet; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testHeadSetTreeSet() {
TreeSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(3);
set.add(4);
set.add(5);
SortedSet<Integer> hs = set.headSet(3);
hs.add(0);
assertThat(hs).containsExactly(0, 1, 2);
set.remove(2);
assertThat(hs).containsExactly(0, 1);
set.remove(3);
assertThat(hs).containsExactly(0, 1);
hs.add(7);
}