本文整理汇总了Java中java.util.SortedSet.headSet方法的典型用法代码示例。如果您正苦于以下问题:Java SortedSet.headSet方法的具体用法?Java SortedSet.headSet怎么用?Java SortedSet.headSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedSet
的用法示例。
在下文中一共展示了SortedSet.headSet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: last
import java.util.SortedSet; //导入方法依赖的package包/类
@Override
public E last() {
SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
while (true) {
E element = sortedUnfiltered.last();
if (predicate.apply(element)) {
return element;
}
sortedUnfiltered = sortedUnfiltered.headSet(element);
}
}
示例2: createSubSet
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Calls the smallest subSet overload that filters out the extreme values.
*/
SortedSet<E> createSubSet(SortedSet<E> set, E firstExclusive, E lastExclusive) {
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
return set.headSet(lastExclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
return set.tailSet(firstInclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
return set.subSet(firstInclusive, lastExclusive);
} else {
throw new IllegalArgumentException();
}
}
示例3: versions
import java.util.SortedSet; //导入方法依赖的package包/类
public void versions(HttpExchange exchange) throws Exception
{
SortedSet<WebVersion> allVersions = new Version(config).getVersions();
WebVersion deployedVersion = new Version(config).getDeployedVersion();
Set<WebVersion> newer = allVersions.headSet(deployedVersion);
Set<WebVersion> older = allVersions.tailSet(deployedVersion);
older.remove(deployedVersion);
StringTemplate st = templates.getInstanceOf("templates/versions");
st.setAttribute("newer", newer);
st.setAttribute("older", older);
st.setAttribute("current", Collections.singleton(deployedVersion));
HttpExchangeUtils.respondHtmlMessage(exchange, 200, st.toString());
}
示例4: cleanOldLogs
import java.util.SortedSet; //导入方法依赖的package包/类
private void cleanOldLogs(SortedSet<String> wals, String key, String id) {
SortedSet<String> walSet = wals.headSet(key);
LOG.debug("Removing " + walSet.size() + " logs in the list: " + walSet);
for (String wal : walSet) {
this.replicationQueues.removeLog(id, wal);
}
walSet.clear();
}
示例5: execute
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* the command that is run and retried for actually
* obtaining the lock
* @return if the command was successful or not
*/
public boolean execute() throws KeeperException, InterruptedException {
do {
if (id == null) {
long sessionId = zookeeper.getSessionId();
String prefix = "x-" + sessionId + "-";
// lets try look up the current ID if we failed
// in the middle of creating the znode
findPrefixInChildren(prefix, zookeeper, dir);
idName = new ZNodeName(id);
}
if (id != null) {
List<String> names = zookeeper.getChildren(dir, false);
if (names.isEmpty()) {
LOG.warn("No children in: " + dir + " when we've just " +
"created one! Lets recreate it...");
// lets force the recreation of the id
id = null;
} else {
// lets sort them explicitly (though they do seem to come back in order ususally :)
SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
for (String name : names) {
sortedNames.add(new ZNodeName(dir + "/" + name));
}
ownerId = sortedNames.first().getName();
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
if (!lessThanMe.isEmpty()) {
ZNodeName lastChildName = lessThanMe.last();
lastChildId = lastChildName.getName();
if (LOG.isDebugEnabled()) {
LOG.debug("watching less than me node: " + lastChildId);
}
Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
if (stat != null) {
return Boolean.FALSE;
} else {
LOG.warn("Could not find the" +
" stats for less than me: " + lastChildName.getName());
}
} else {
if (isOwner()) {
if (callback != null) {
callback.lockAcquired();
}
return Boolean.TRUE;
}
}
}
}
}
while (id == null);
return Boolean.FALSE;
}
示例6: testCopyOf_headSet
import java.util.SortedSet; //导入方法依赖的package包/类
public void testCopyOf_headSet() {
SortedSet<String> set = of("e", "a", "f", "b", "d", "c");
SortedSet<String> headset = set.headSet("d");
SortedSet<String> copy = copyOf(headset);
assertEquals(headset, copy);
}