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

x33g5p2x  于2022-01-15 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(218)

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

ArrayList.sort介绍

暂无

代码示例

代码示例来源:origin: eclipse/eclipse-collections

/**
 * @since 10.0 - Override for correctness
 */
@Override
public void sort(Comparator<? super T> comparator)
{
  this.delegate.sort(comparator);
}

代码示例来源:origin: eclipse/eclipse-collections

/**
 * Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList.
 */
public static <T> ArrayList<T> sortThis(ArrayList<T> list, Comparator<? super T> comparator)
{
  list.sort(comparator);
  return list;
}

代码示例来源:origin: eclipse/eclipse-collections

/**
 * Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList.
 */
public static <T> ArrayList<T> sortThis(ArrayList<T> list, Comparator<? super T> comparator)
{
  list.sort(comparator);
  return list;
}

代码示例来源:origin: eclipse/eclipse-collections

/**
 * @since 10.0 - Override for correctness
 */
@Override
public void sort(Comparator<? super T> comparator)
{
  this.delegate.sort(comparator);
}

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

private StageIdFaninScmMaterialPair getSmallestScmRevision(Collection<StageIdFaninScmMaterialPair> scmWithDiffVersions) {
  ArrayList<StageIdFaninScmMaterialPair> materialPairList = new ArrayList<>(scmWithDiffVersions);
  materialPairList.sort((pair1, pair2) -> {
    final PipelineTimelineEntry.Revision rev1 = pair1.faninScmMaterial.revision;
    final PipelineTimelineEntry.Revision rev2 = pair2.faninScmMaterial.revision;
    return rev1.date.compareTo(rev2.date);
  });
  return materialPairList.get(0);
}

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

public String usage()
{
  StringBuilder sb = new StringBuilder();
  if ( !namedArgs.isEmpty() )
  {
    sb.append( namedArgs.values().stream().map( NamedArgument::usage ).collect( Collectors.joining( " " ) ) );
  }
  if ( !positionalArgs.isEmpty() )
  {
    sb.append( " " );
    positionalArgs.sort( Comparator.comparingInt( PositionalArgument::position ) );
    sb.append( positionalArgs.stream().map( PositionalArgument::usage ).collect( Collectors.joining( " " ) ) );
  }
  return sb.toString().trim();
}

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

@Override
public List<Revision> revisions() {
  ArrayList<Revision> revisions = new ArrayList<>(this.revisions);
  revisions.sort((o1, o2) -> ((PipelineRevision) o1).compareTo((PipelineRevision) o2));
  return revisions;
}

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

@Override
public List<Revision> revisions() {
  ArrayList<Revision> revisions = new ArrayList<>(this.revisions);
  for(MaterialRevision revision : materialRevisions) {
    for(Modification modification : revision.getModifications()) {
      revisions.add(new SCMRevision(modification));
    }
  }
  revisions.sort(Comparator.comparing(o -> ((SCMRevision) o)));
  return revisions;
}

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

private Transfer findMostSpecificRule(List<Transfer> transfers, String fromRouteId, String toRouteId) {
  final ArrayList<Transfer> transfersBySpecificity = new ArrayList<>(transfers);
  transfersBySpecificity.sort(Comparator.comparingInt(t -> {
    int score = 0;
    if (fromRouteId.equals(t.from_route_id)) {
      score++;
    }
    if (toRouteId.equals(t.to_route_id)) {
      score++;
    }
    return -score;
  }));
  if (transfersBySpecificity.isEmpty()) {
    throw new RuntimeException();
  }
  return transfersBySpecificity.get(0);
}

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

long send()
{
  // Sort in reverse, so the elements we want to send first are at the end.
  batches.sort( TICKETED_BATCH_COMPARATOR );
  long idleTimeSum = 0;
  long batchesDone = 0;
  for ( int i = batches.size() - 1; i >= 0 ; i-- )
  {
    TicketedBatch batch = batches.get( i );
    if ( batch.ticket == lastSendTicket + 1 )
    {
      batches.remove( i );
      lastSendTicket = batch.ticket;
      idleTimeSum += downstream.receive( batch.ticket, batch.batch );
      batchesDone++;
    }
    else
    {
      break;
    }
  }
  doneBatches.getAndAdd( batchesDone );
  return idleTimeSum;
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Returns an ordered list of edges in the graph.
 * This creates and sorts a list, so prefer edgeIterable().
 *
 * @return A ordered list of edges in the graph.
 */
public List<SemanticGraphEdge> edgeListSorted() {
 ArrayList<SemanticGraphEdge> edgeList = new ArrayList<>();
 for (SemanticGraphEdge edge : edgeIterable()) {
  edgeList.add(edge);
 }
 edgeList.sort(SemanticGraphEdge.orderByTargetComparator());
 return edgeList;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Gets all the users.
 */
public static @Nonnull
Collection<User> getAll() {
  final IdStrategy strategy = idStrategy();
  ArrayList<User> users = new ArrayList<>(AllUsers.values());
  users.sort((o1, o2) -> strategy.compare(o1.getId(), o2.getId()));
  return users;
}

代码示例来源:origin: JetBrains/ideavim

@NotNull
public List<Mark> getMarks(@NotNull Editor editor) {
 HashSet<Mark> res = new HashSet<>();
 final FileMarks<Character, Mark> marks = getFileMarks(editor.getDocument());
 if (marks != null) {
  res.addAll(marks.values());
 }
 res.addAll(globalMarks.values());
 ArrayList<Mark> list = new ArrayList<>(res);
 list.sort(new Mark.KeySorter<>());
 return list;
}

代码示例来源:origin: cbeust/testng

@SuppressWarnings("unchecked")
private void addAllTestResults(Set<ITestResult> testResults, IResultMap resultMap) {
 if (resultMap != null) {
  // Sort the results chronologically before adding them
  List<ITestResult> allResults = new ArrayList<>(resultMap.getAllResults());
  new ArrayList(allResults)
    .sort(
      (Comparator<ITestResult>)
        (o1, o2) -> (int) (o1.getStartMillis() - o2.getStartMillis()));
  testResults.addAll(allResults);
 }
}

代码示例来源:origin: spring-projects/spring-framework

methods.sort((m1, m2) -> {
  int m1pl = m1.getParameterCount();
  int m2pl = m2.getParameterCount();

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

out.sort( Comparator.comparing( a -> a.signature().name().toString() ) );
return out;

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

out.sort( Comparator.comparing( a -> a.signature().name().toString() ) );
return out;

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

out.sort( Comparator.comparing( a -> a.signature().name().toString() ) );
return out;

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

public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) {
    ArrayList<JobInstanceModel> models = new ArrayList<>();
    for (JobInstance jobInstance : jobInstances) {
      AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null;
      JobInstanceModel model;
      if (null != agentInstance && !agentInstance.isNullAgent()) {
        model = new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance);
      } else if (jobInstance.getAgentUuid() != null) {
        Agent agent = agentService.findAgentObjectByUuid(jobInstance.getAgentUuid());
        model = new JobInstanceModel(jobInstance, jobDurationStrategy, agent);
      } else {
        model = new JobInstanceModel(jobInstance, jobDurationStrategy);
      }
      models.add(model);
    }
    models.sort(JobInstanceModel.JOB_MODEL_COMPARATOR);
    return models;
  }
}

代码示例来源:origin: prestodb/presto

list.sort(Integer::compare);
assertEquals(list, ImmutableList.of(1, 2, 3, 4, 5));
assertTrue(queue.isFinished());

相关文章