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


Java LinkedList.sort方法代碼示例

本文整理匯總了Java中java.util.LinkedList.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedList.sort方法的具體用法?Java LinkedList.sort怎麽用?Java LinkedList.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.LinkedList的用法示例。


在下文中一共展示了LinkedList.sort方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bufferedAndSortedReadAllForwards

import java.util.LinkedList; //導入方法依賴的package包/類
private Stream<ResolvedEvent> bufferedAndSortedReadAllForwards(Position positionExclusive) {
    try(Stream<ResolvedEvent> allForwards = underlying.readAllForwards()) {

        Iterator<ResolvedEvent> remainder = allForwards.iterator();
        PeekingIterator<EventWithSortKey<T>> sortCandidates = Iterators.peekingIterator(
                Iterators.transform(remainder, re -> new EventWithSortKey<>(re, sortKeyExtractor.apply(re)))
        );

        final LinkedList<EventWithSortKey<T>> buffer = new LinkedList<>();

        while (sortCandidates.hasNext() && sortCandidates.peek().sortKey.compareTo(cutoffSortKey) < 0) {
            buffer.add(sortCandidates.next());
        }

        if (!sortCandidates.hasNext()) {
            return Stream.empty();
        }

        buffer.sort(Comparator.naturalOrder());

        if (!positionExclusive.equals(underlying.emptyStorePosition())) {
            Iterator<EventWithSortKey<T>> bufferIterator = buffer.iterator();
            while (!bufferIterator.next().event.position().equals(positionExclusive)) {
                bufferIterator.remove();
            }
            bufferIterator.remove();
        }

        Stream<EventWithSortKey<T>> reorderedEvents = buffer.stream().onClose(buffer::clear);
        Stream<EventWithSortKey<T>> eventInTheGap = Stream.of(sortCandidates.peek());
        Stream<ResolvedEvent> remainingEvents = stream(spliteratorUnknownSize(remainder, ORDERED), false);

        return concat(concat(reorderedEvents, eventInTheGap).map(EventWithSortKey::toResolvedEvent), remainingEvents).onClose(allForwards::close);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:36,代碼來源:ReorderingEventReader.java

示例2: getPresenter

import java.util.LinkedList; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T> Optional<PropertyValuePresenter<T>> getPresenter(Property<T> property) {
	ObjectUtils.argumentNotNull(property, "Property must be not null");

	LOGGER.debug(() -> "Get PropertyValuePresenter for property [" + property + "]");

	final LinkedList<PropertyValuePresenter> candidates = new LinkedList<>();

	for (Entry<Predicate, PropertyValuePresenter> entry : presenters.entrySet()) {
		if (entry.getKey().test(property)) {
			candidates.add(entry.getValue());
		}
	}

	if (!candidates.isEmpty()) {
		if (candidates.size() > 1) {
			// sort by priority
			candidates.sort(PRIORITY_COMPARATOR);

			LOGGER.debug(() -> "Get PropertyValuePresenter for property [" + property
					+ "] - return first of candidates: [" + candidates + "]");
		}
		return Optional.of(candidates.getFirst());
	}

	LOGGER.debug(() -> "No PropertyValuePresenter available for property [" + property + "]");

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:31,代碼來源:DefaultPropertyValuePresenterRegistry.java

示例3: getRenderer

import java.util.LinkedList; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <R, T> Optional<PropertyRenderer<R, T>> getRenderer(Class<R> renderingType, Property<T> property) {
	ObjectUtils.argumentNotNull(property, "Property must be not null");
	ObjectUtils.argumentNotNull(renderingType, "Rendering type must be not null");

	LOGGER.debug(() -> "Get PropertyRenderer for property [" + property + "] and type [" + renderingType + "]");

	final Map<Predicate, PropertyRenderer> renderersForType = renderers.getOrDefault(renderingType,
			Collections.emptyMap());

	final LinkedList<PropertyRenderer> candidates = new LinkedList<>();

	for (Entry<Predicate, PropertyRenderer> entry : renderersForType.entrySet()) {
		if (entry.getKey().test(property)) {
			candidates.add(entry.getValue());
		}
	}

	if (!candidates.isEmpty()) {
		if (candidates.size() > 1) {
			// sort by priority
			candidates.sort(PRIORITY_COMPARATOR);

			LOGGER.debug(() -> "Get PropertyRenderer for property [" + property + "] and type [" + renderingType
					+ "] - return first of candidates: [" + candidates + "]");
		}
		return Optional.of(candidates.getFirst());
	}

	LOGGER.debug(
			() -> "No PropertyRenderer available for property [" + property + "] and type [" + renderingType + "]");

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:36,代碼來源:DefaultPropertyRendererRegistry.java

示例4: sort

import java.util.LinkedList; //導入方法依賴的package包/類
protected void sort(LinkedList<Edge> edges, boolean isAscending) {
	
	if(isAscending)
		edges.sort((a, b) -> compare(a.getToVertex(), b.getToVertex()));
	else
		edges.sort((a, b) -> compare(b.getToVertex(), a.getToVertex()));
}
 
開發者ID:xeyez,項目名稱:StationGraph,代碼行數:8,代碼來源:AbstractGraph.java


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