本文整理匯總了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);
}
}
示例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();
}
示例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();
}
示例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()));
}