本文整理汇总了Java中org.ethereum.util.Functional.Predicate方法的典型用法代码示例。如果您正苦于以下问题:Java Functional.Predicate方法的具体用法?Java Functional.Predicate怎么用?Java Functional.Predicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.util.Functional
的用法示例。
在下文中一共展示了Functional.Predicate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNodes
import org.ethereum.util.Functional; //导入方法依赖的package包/类
/**
* Returns limited list of nodes matching {@code predicate} criteria<br>
* The nodes are sorted then by their totalDifficulties
*
* @param predicate only those nodes which are satisfied to its condition are included in results
* @param limit max size of returning list
*
* @return list of nodes matching criteria
*/
public List<NodeHandler> getNodes(
Functional.Predicate<NodeHandler> predicate,
int limit ) {
ArrayList<NodeHandler> filtered = new ArrayList<>();
synchronized (this) {
for (NodeHandler handler : nodeHandlerMap.values()) {
if (predicate.test(handler)) {
filtered.add(handler);
}
}
}
Collections.sort(filtered, new Comparator<NodeHandler>() {
@Override
public int compare(NodeHandler o1, NodeHandler o2) {
return o2.getNodeStatistics().getEthTotalDifficulty().compareTo(
o1.getNodeStatistics().getEthTotalDifficulty());
}
});
return CollectionUtils.truncate(filtered, limit);
}
示例2: ListenerHandler
import org.ethereum.util.Functional; //导入方法依赖的package包/类
ListenerHandler(DiscoverListener listener, Functional.Predicate<NodeStatistics> filter) {
this.listener = listener;
this.filter = filter;
}
示例3: setNodesSelector
import org.ethereum.util.Functional; //导入方法依赖的package包/类
public void setNodesSelector(Functional.Predicate<NodeHandler> nodesSelector) {
this.nodesSelector = nodesSelector;
}
示例4: addDiscoverListener
import org.ethereum.util.Functional; //导入方法依赖的package包/类
/**
* Add a listener which is notified when the node statistics starts or stops meeting
* the criteria specified by [filter] param.
*/
public synchronized void addDiscoverListener(DiscoverListener listener, Functional.Predicate<NodeStatistics> filter) {
listeners.put(listener, new ListenerHandler(listener, filter));
}