當前位置: 首頁>>代碼示例>>Java>>正文


Java Stream.sorted方法代碼示例

本文整理匯總了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;
    });
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:19,代碼來源:ReturnClauseExecutor.java

示例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());
}
 
開發者ID:limberest,項目名稱:limberest-demo,代碼行數:26,代碼來源:MoviesPersistFile.java

示例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();
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:15,代碼來源:SQLEditorContentOutlinePage.java

示例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);
	
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:44,代碼來源:L2AttackableAI.java

示例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());
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:11,代碼來源:Streams.java


注:本文中的java.util.stream.Stream.sorted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。