java.util.LinkedList.sort()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(449)

本文整理了Java中java.util.LinkedList.sort()方法的一些代码示例,展示了LinkedList.sort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedList.sort()方法的具体详情如下:
包路径:java.util.LinkedList
类名称:LinkedList
方法名:sort

LinkedList.sort介绍

暂无

代码示例

代码示例来源:origin: org.apache.solr/solr-solrj

  1. public void sort() {
  2. tuples.sort(comparator);
  3. }

代码示例来源:origin: org.drools/drools-compiler

  1. nextEventSource.sort(new EventGenerationTimeComparator());

代码示例来源:origin: CoFH/CoFHCore

  1. public static void postInit() {
  2. if (INSTANCE.isPostInitialised) {
  3. return;
  4. }
  5. INSTANCE.isPostInitialised = true;
  6. (INSTANCE.packets).sort((packetClass1, packetClass2) -> {
  7. int com = String.CASE_INSENSITIVE_ORDER.compare(packetClass1.getCanonicalName(), packetClass2.getCanonicalName());
  8. if (com == 0) {
  9. com = packetClass1.getCanonicalName().compareTo(packetClass2.getCanonicalName());
  10. }
  11. return com;
  12. });
  13. }

代码示例来源:origin: com.daioware/collections

  1. @Override
  2. public void sort(Comparator<? super T> c) {
  3. super.sort(c);
  4. runChanges();
  5. }

代码示例来源:origin: org.eclipse.che.core/che-core-ide-ui

  1. /**
  2. * Perform iteration on every node interceptor, passing to ones the list of children to filter
  3. * them before inserting into parent node.
  4. *
  5. * @param parent parent node
  6. * @return instance of {@link org.eclipse.che.api.promises.client.Function} with promise that
  7. * contains list of intercepted children
  8. */
  9. @NotNull
  10. private Operation<List<Node>> interceptChildren(@NotNull final Node parent) {
  11. return children -> {
  12. // In case of nodeInterceptors is empty we still need to call iterate(...)
  13. // in order to call set parent on children and call onLoadSuccess(...)
  14. LinkedList<NodeInterceptor> sortedByPriorityQueue = new LinkedList<>(nodeInterceptors);
  15. sortedByPriorityQueue.sort(priorityComparator);
  16. iterate(sortedByPriorityQueue, parent, children);
  17. };
  18. }

代码示例来源:origin: org.realityforge.replicant/replicant-server

  1. /**
  2. * Add packet to queue.
  3. *
  4. * @param requestId the opaque identifier indicating the request that caused the changes if the owning session initiated the changes.
  5. * @param etag the opaque identifier identifying the version. May be null if packet is not cache-able
  6. * @param changeSet the changeSet to create packet from.
  7. * @return the packet.
  8. */
  9. public synchronized Packet addPacket( @Nullable final Integer requestId,
  10. @Nullable final String etag,
  11. @Nonnull final ChangeSet changeSet )
  12. {
  13. final Packet packet = new Packet( _nextSequence++, requestId, etag, changeSet );
  14. _packets.add( packet );
  15. _packets.sort( null );
  16. return packet;
  17. }

代码示例来源:origin: Dytanic/CloudNet

  1. private LinkedList<String> getProxiesAndServers()
  2. {
  3. LinkedList<String> groups = new LinkedList<>(CloudAPI.getInstance().getProxys().stream()
  4. .map(ProxyInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList()));
  5. groups.addAll(CloudAPI.getInstance().getServers().stream()
  6. .map(ServerInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList()));
  7. groups.sort(Collections.reverseOrder());
  8. return groups;
  9. }
  10. }

代码示例来源:origin: Dytanic/CloudNet

  1. private LinkedList<String> getProxyAndServerGroups()
  2. {
  3. LinkedList<String> groups = new LinkedList<>(CloudAPI.getInstance().getProxyGroupMap().keySet());
  4. groups.addAll(CloudAPI.getInstance().getServerGroupMap().keySet());
  5. groups.sort(Collections.reverseOrder());
  6. return groups;
  7. }

代码示例来源:origin: com.holon-platform.core/holon-core

  1. @SuppressWarnings({ "rawtypes", "unchecked" })
  2. @Override
  3. public <T> Optional<PropertyValuePresenter<T>> getPresenter(Property<T> property) {
  4. ObjectUtils.argumentNotNull(property, "Property must be not null");
  5. LOGGER.debug(() -> "Get PropertyValuePresenter for property [" + property + "]");
  6. final LinkedList<PropertyValuePresenter> candidates = new LinkedList<>();
  7. for (Entry<Predicate, PropertyValuePresenter> entry : presenters.entrySet()) {
  8. if (entry.getKey().test(property)) {
  9. candidates.add(entry.getValue());
  10. }
  11. }
  12. if (!candidates.isEmpty()) {
  13. if (candidates.size() > 1) {
  14. // sort by priority
  15. candidates.sort(PRIORITY_COMPARATOR);
  16. LOGGER.debug(() -> "Get PropertyValuePresenter for property [" + property
  17. + "] - return first of candidates: [" + candidates + "]");
  18. }
  19. return Optional.of(candidates.getFirst());
  20. }
  21. LOGGER.debug(() -> "No PropertyValuePresenter available for property [" + property + "]");
  22. return Optional.empty();
  23. }

代码示例来源:origin: com.github.wslotkin/itinerator-generator

  1. public ItineraryBuilder(LocalDateTime startTime,
  2. LocalDateTime endTime,
  3. RoundingTravelTimeCalculator travelTimeCalculator,
  4. List<Event> fixedEvents) {
  5. this.startTime = startTime;
  6. this.endTime = endTime;
  7. this.travelTimeCalculator = travelTimeCalculator;
  8. this.fixedEvents = newLinkedList(fixedEvents);
  9. activities = TreeMultimap.create(natural(), ARBITRARY_BUT_PREDICTABLE_ORDERING);
  10. foods = TreeMultimap.create(natural(), ARBITRARY_BUT_PREDICTABLE_ORDERING);
  11. hotels = TreeMultimap.create(natural(), ARBITRARY_BUT_PREDICTABLE_ORDERING);
  12. this.fixedEvents.sort(comparing(event -> event.getEventTime().getStart()));
  13. }

代码示例来源:origin: com.holon-platform.core/holon-core

  1. @SuppressWarnings({ "rawtypes", "unchecked" })
  2. @Override
  3. public <R, T> Optional<PropertyRenderer<R, T>> getRenderer(Class<R> renderingType, Property<? extends T> property) {
  4. ObjectUtils.argumentNotNull(property, "Property must be not null");
  5. ObjectUtils.argumentNotNull(renderingType, "Rendering type must be not null");
  6. LOGGER.debug(() -> "Get PropertyRenderer for property [" + property + "] and type [" + renderingType + "]");
  7. final Map<Predicate, PropertyRenderer> renderersForType = renderers.getOrDefault(renderingType,
  8. Collections.emptyMap());
  9. final LinkedList<PropertyRenderer> candidates = new LinkedList<>();
  10. for (Entry<Predicate, PropertyRenderer> entry : renderersForType.entrySet()) {
  11. if (entry.getKey().test(property)) {
  12. candidates.add(entry.getValue());
  13. }
  14. }
  15. if (!candidates.isEmpty()) {
  16. if (candidates.size() > 1) {
  17. // sort by priority
  18. candidates.sort(PRIORITY_COMPARATOR);
  19. LOGGER.debug(() -> "Get PropertyRenderer for property [" + property + "] and type [" + renderingType
  20. + "] - return first of candidates: [" + candidates + "]");
  21. }
  22. return Optional.of(candidates.getFirst());
  23. }
  24. LOGGER.debug(
  25. () -> "No PropertyRenderer available for property [" + property + "] and type [" + renderingType + "]");
  26. return Optional.empty();
  27. }

代码示例来源:origin: Discord4J/Discord4J

  1. @Override
  2. public List<IChannel> getChannels() {
  3. LinkedList<IChannel> list = new LinkedList<>(channels.values());
  4. list.sort((c1, c2) -> {
  5. int originalPos1 = ((Channel) c1).position;
  6. int originalPos2 = ((Channel) c2).position;
  7. if (originalPos1 == originalPos2) {
  8. return c2.getCreationDate().compareTo(c1.getCreationDate());
  9. } else {
  10. return originalPos1 - originalPos2;
  11. }
  12. });
  13. return list;
  14. }

代码示例来源:origin: Discord4J/Discord4J

  1. @Override
  2. public List<IVoiceChannel> getVoiceChannels() {
  3. LinkedList<IVoiceChannel> list = new LinkedList<>(voiceChannels.values());
  4. list.sort((c1, c2) -> {
  5. int originalPos1 = ((Channel) c1).position;
  6. int originalPos2 = ((Channel) c2).position;
  7. if (originalPos1 == originalPos2) {
  8. return c2.getCreationDate().compareTo(c1.getCreationDate());
  9. } else {
  10. return originalPos1 - originalPos2;
  11. }
  12. });
  13. return list;
  14. }

代码示例来源:origin: Discord4J/Discord4J

  1. @Override
  2. public List<IRole> getRoles() {
  3. LinkedList<IRole> list = new LinkedList<>(roles.values());
  4. list.sort((r1, r2) -> {
  5. int originalPos1 = ((Role) r1).position;
  6. int originalPos2 = ((Role) r2).position;
  7. if (originalPos1 == originalPos2) {
  8. return r2.getCreationDate().compareTo(r1.getCreationDate());
  9. } else {
  10. return originalPos1 - originalPos2;
  11. }
  12. });
  13. return list;
  14. }

代码示例来源:origin: Discord4J/Discord4J

  1. @Override
  2. public List<ICategory> getCategories() {
  3. LinkedList<ICategory> list = new LinkedList<>(categories.values());
  4. list.sort((c1, c2) -> {
  5. int originalPos1 = ((Category) c1).position;
  6. int originalPos2 = ((Category) c2).position;
  7. if (originalPos1 == originalPos2) {
  8. return c2.getCreationDate().compareTo(c1.getCreationDate());
  9. } else {
  10. return originalPos1 - originalPos2;
  11. }
  12. });
  13. return list;
  14. }

代码示例来源:origin: ldtteam/minecolonies

  1. /**
  2. * Searches all logs that belong to the tree.
  3. *
  4. * @param world The world where the blocks are in.
  5. */
  6. public void findLogs(@NotNull final World world)
  7. {
  8. addAndSearch(world, location);
  9. woodBlocks.sort((c1, c2) -> (int) (c1.distanceSq(location) - c2.distanceSq(location)));
  10. if (getStumpLocations().isEmpty())
  11. {
  12. fillTreeStumps(location.getY());
  13. }
  14. }

代码示例来源:origin: alien4cloud/alien4cloud

  1. private void flattenWorkflow(TopologyContext topologyContext, SubGraph subGraph) {
  2. ComputeNodesWeightsGraphConsumer consumer = new ComputeNodesWeightsGraphConsumer();
  3. subGraph.browse(consumer);
  4. if (consumer.getAllNodes().isEmpty()) {
  5. // This is really strange as we have a node template without any workflow step
  6. return;
  7. }
  8. Map<String, WorkflowStep> allNodes = consumer.getAllNodes();
  9. LinkedList<WorkflowStep> sortedByWeightsSteps = new LinkedList<>(allNodes.values());
  10. sortedByWeightsSteps.sort(new WorkflowStepWeightComparator(consumer.getAllNodeWeights(), topologyContext.getTopology()));
  11. Set<String> allSubGraphNodeIds = allNodes.keySet();
  12. sortedByWeightsSteps.forEach(workflowStep -> {
  13. // Remove all old links between the steps in the graph
  14. workflowStep.removeAllPrecedings(allSubGraphNodeIds);
  15. workflowStep.removeAllFollowings(allSubGraphNodeIds);
  16. });
  17. // Create a sequence with sorted sub graph steps
  18. for (int i = 0; i < sortedByWeightsSteps.size() - 1; i++) {
  19. sortedByWeightsSteps.get(i).addFollowing(sortedByWeightsSteps.get(i + 1).getName());
  20. sortedByWeightsSteps.get(i + 1).addPreceding(sortedByWeightsSteps.get(i).getName());
  21. }
  22. }
  23. }

代码示例来源:origin: PegaSysEng/pantheon

  1. /**
  2. * This creates a list of validators, with the a number of validators above and below the local
  3. * address. The returned list is sorted.
  4. *
  5. * @param localAddr The address of the node which signed the parent block
  6. * @param countLower The number of validators which have a higher address than localAddr
  7. * @param countHigher The number of validators which have a lower address than localAddr
  8. * @return A sorted list of validators which matches parameters (including the localAddr).
  9. */
  10. private LinkedList<Address> createValidatorList(
  11. final Address localAddr, final int countLower, final int countHigher) {
  12. final LinkedList<Address> result = Lists.newLinkedList();
  13. // Note: Order of this list is irrelevant, is sorted by value later.
  14. result.add(localAddr);
  15. for (int i = 0; i < countLower; i++) {
  16. result.add(AddressHelpers.calculateAddressWithRespectTo(localAddr, i - countLower));
  17. }
  18. for (int i = 0; i < countHigher; i++) {
  19. result.add(AddressHelpers.calculateAddressWithRespectTo(localAddr, i + 1));
  20. }
  21. result.sort(null);
  22. return result;
  23. }

代码示例来源:origin: broadinstitute/picard

  1. public void writeAsVcf(final File output, final File refFile) throws FileNotFoundException {
  2. ReferenceSequenceFile ref = new IndexedFastaSequenceFile(refFile);
  3. try (VariantContextWriter writer = new VariantContextWriterBuilder()
  4. .setOutputFile(output)
  5. .setReferenceDictionary(ref.getSequenceDictionary())
  6. .build()) {
  7. final VCFHeader vcfHeader = new VCFHeader(
  8. VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false),
  9. Collections.singleton(HET_GENOTYPE_FOR_PHASING));
  10. VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false);
  11. vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeaderVersion.VCF4_2.getFormatString(), VCFHeaderVersion.VCF4_2.getVersionString()));
  12. vcfHeader.addMetaDataLine(new VCFInfoHeaderLine(VCFConstants.ALLELE_FREQUENCY_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Allele Frequency, for each ALT allele, in the same order as listed"));
  13. vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_KEY, 1, VCFHeaderLineType.String, "Genotype"));
  14. vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.PHASE_SET_KEY, 1, VCFHeaderLineType.String, "Phase-set identifier for phased genotypes."));
  15. vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeader.SOURCE_KEY,"HaplotypeMap::writeAsVcf"));
  16. vcfHeader.addMetaDataLine(new VCFHeaderLine("reference","HaplotypeMap::writeAsVcf"));
  17. // vcfHeader.addMetaDataLine(new VCFHeaderLine());
  18. writer.writeHeader(vcfHeader);
  19. final LinkedList<VariantContext> variants = new LinkedList<>(this.asVcf(ref));
  20. variants.sort(vcfHeader.getVCFRecordComparator());
  21. variants.forEach(writer::add);
  22. }
  23. }

代码示例来源:origin: com.github.broadinstitute/picard

  1. public void writeAsVcf(final File output, final File refFile) throws FileNotFoundException {
  2. ReferenceSequenceFile ref = new IndexedFastaSequenceFile(refFile);
  3. try (VariantContextWriter writer = new VariantContextWriterBuilder()
  4. .setOutputFile(output)
  5. .setReferenceDictionary(ref.getSequenceDictionary())
  6. .build()) {
  7. final VCFHeader vcfHeader = new VCFHeader(
  8. VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false),
  9. Collections.singleton(HET_GENOTYPE_FOR_PHASING));
  10. VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false);
  11. vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeaderVersion.VCF4_2.getFormatString(), VCFHeaderVersion.VCF4_2.getVersionString()));
  12. vcfHeader.addMetaDataLine(new VCFInfoHeaderLine(VCFConstants.ALLELE_FREQUENCY_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Allele Frequency, for each ALT allele, in the same order as listed"));
  13. vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_KEY, 1, VCFHeaderLineType.String, "Genotype"));
  14. vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.PHASE_SET_KEY, 1, VCFHeaderLineType.String, "Phase-set identifier for phased genotypes."));
  15. vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeader.SOURCE_KEY,"HaplotypeMap::writeAsVcf"));
  16. vcfHeader.addMetaDataLine(new VCFHeaderLine("reference","HaplotypeMap::writeAsVcf"));
  17. // vcfHeader.addMetaDataLine(new VCFHeaderLine());
  18. writer.writeHeader(vcfHeader);
  19. final LinkedList<VariantContext> variants = new LinkedList<>(this.asVcf(ref));
  20. variants.sort(vcfHeader.getVCFRecordComparator());
  21. variants.forEach(writer::add);
  22. }
  23. }

相关文章