本文整理匯總了Java中java.util.stream.Stream.sorted方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.sorted方法的具體用法?Java Stream.sorted怎麽用?Java Stream.sorted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.sorted方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyOrderByToResults
import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<MemgraphCypherScope.Item> applyOrderByToResults(
MemgraphCypherQueryContext ctx,
Stream<MemgraphCypherScope.Item> results,
CypherOrderBy orderByClause
) {
List<CypherSortItem> sortItems = orderByClause.getSortItems();
return results.sorted((o1, o2) -> {
for (CypherSortItem sortItem : sortItems) {
Object v1 = getOrderByValue(ctx, sortItem, o1);
Object v2 = getOrderByValue(ctx, sortItem, o2);
int i = ObjectUtils.compare(v1, v2);
if (i != 0) {
return i;
}
}
return 0;
});
}
示例2: retrieve
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public List<Movie> retrieve(Query query) throws PersistException {
List<Movie> movies = getMovies();
Stream<Movie> stream = movies.stream();
// filter
if (query.hasFilters() || query.getSearch() != null) {
stream = stream.filter(movie -> query.match(new JsonMatcher(movie.toJson())));
}
// sort
if ((query.getSort() != null && !"title".equals(query.getSort())) || query.isDescending()) {
stream = stream.sorted(new JsonableComparator(query, (j1, j2) -> {
return getSortTitle(j1).compareToIgnoreCase(getSortTitle(j2));
}));
}
// paginate
if (query.getStart() > 0)
stream = stream.skip(query.getStart());
if (query.getMax() != Query.MAX_ALL)
stream = stream.limit(query.getMax());
return stream.collect(Collectors.toList());
}
示例3: getElements
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public Object[] getElements(Object inputElement) {
Stream<PgObjLocation> stream = sqlEditor.getParser().getObjsForEditor(
sqlEditor.getEditorInput()).stream().filter(
e -> e.getAction() != StatementActions.NONE);
if (filterDangerous) {
stream = stream.filter(PgObjLocation::isDanger);
}
if (sortStatements) {
stream = stream.sorted((a,b) -> a.getObjName().compareTo(b.getObjName()));
}
return stream.map(Segments::new).toArray();
}
示例4: skillTargetReconsider
import java.util.stream.Stream; //導入方法依賴的package包/類
private L2Character skillTargetReconsider(Skill skill, boolean insideCastRange)
{
// Check if skill can be casted.
final L2Attackable npc = getActiveChar();
if (!SkillCaster.checkUseConditions(npc, skill))
{
return null;
}
// Check current target first.
final int range = insideCastRange ? skill.getCastRange() + getActiveChar().getTemplate().getCollisionRadius() : 2000; // TODO need some forget range
Stream<L2Character> stream;
if (skill.isBad())
{
//@formatter:off
stream = npc.getAggroList().values().stream()
.map(AggroInfo::getAttacker)
.filter(c -> checkSkillTarget(skill, c))
.sorted(Comparator.<L2Character>comparingInt(npc::getHating).reversed());
//@formatter:on
}
else
{
stream = L2World.getInstance().getVisibleObjects(npc, L2Character.class, range, c -> checkSkillTarget(skill, c)).stream();
// Maybe add self to the list of targets since getVisibleObjects doesn't return yourself.
if (checkSkillTarget(skill, npc))
{
stream = Stream.concat(stream, Stream.of(npc));
}
// For heal skills sort by hp missing.
if (skill.hasEffectType(L2EffectType.HEAL))
{
stream = stream.sorted(Comparator.comparingInt(L2Character::getCurrentHpPercent));
}
}
// Return any target.
return stream.findFirst().orElse(null);
}
示例5: sortJavaNames
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Sorts the stream of java names.
*
* @param stream
* Stream of names.
* @return The stream, sorted.
*/
private static Stream<String> sortJavaNames(Stream<String> stream) {
return stream.sorted(new JavaNameSorter());
}