Tabnine Logo
List.sort
Code IndexAdd Tabnine to your IDE (free)

How to use
sort
method
in
java.util.List

Best Java code snippets using java.util.List.sort (Showing top 20 results out of 12,627)

Refine searchRefine arrow

  • List.add
  • List.size
  • List.get
  • List.isEmpty
  • Comparator.comparing
origin: spring-projects/spring-framework

/**
 * Sort the given List with a default OrderComparator.
 * <p>Optimized to skip sorting for lists with size 0 or 1,
 * in order to avoid unnecessary array extraction.
 * @param list the List to sort
 * @see java.util.List#sort(java.util.Comparator)
 */
public static void sort(List<?> list) {
  if (list.size() > 1) {
    list.sort(INSTANCE);
  }
}
origin: GoogleContainerTools/jib

 private List<TarArchiveEntry> getSortedEntries() {
  List<TarArchiveEntry> sortedEntries = new ArrayList<>(entries);
  sortedEntries.sort(Comparator.comparing(TarArchiveEntry::getName));
  return sortedEntries;
 }
}
origin: spring-projects/spring-framework

/**
 * Obtain the closest match from the given exception types for the given target exception.
 * @param exceptionTypes the collection of exception types
 * @param targetException the target exception to find a match for
 * @return the closest matching exception type from the given collection
 */
public static Class<? extends Throwable> findClosestMatch(
    Collection<Class<? extends Throwable>> exceptionTypes, Throwable targetException) {
  Assert.notEmpty(exceptionTypes, "Exception types must not be empty");
  if (exceptionTypes.size() == 1) {
    return exceptionTypes.iterator().next();
  }
  List<Class<? extends Throwable>> handledExceptions = new ArrayList<>(exceptionTypes);
  handledExceptions.sort(new ExceptionDepthComparator(targetException));
  return handledExceptions.get(0);
}
origin: spring-projects/spring-framework

/**
 * Return the {@link Method} mapped to the given exception type, or {@code null} if none.
 */
@Nullable
private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
  List<Class<? extends Throwable>> matches = new ArrayList<>();
  for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
    if (mappedException.isAssignableFrom(exceptionType)) {
      matches.add(mappedException);
    }
  }
  if (!matches.isEmpty()) {
    matches.sort(new ExceptionDepthComparator(exceptionType));
    return this.mappedMethods.get(matches.get(0));
  }
  else {
    return null;
  }
}
origin: AxonFramework/AxonFramework

private static HandlerEnhancerDefinition[] flatten(List<HandlerEnhancerDefinition> factories) {
  List<HandlerEnhancerDefinition> flattened = new ArrayList<>(factories.size());
  for (HandlerEnhancerDefinition handlerEnhancer : factories) {
    if (handlerEnhancer instanceof MultiHandlerEnhancerDefinition) {
      flattened.addAll(((MultiHandlerEnhancerDefinition) handlerEnhancer).getDelegates());
    } else {
      flattened.add(handlerEnhancer);
    }
  }
  flattened.sort(PriorityAnnotationComparator.getInstance());
  return flattened.toArray(new HandlerEnhancerDefinition[flattened.size()]);
}
origin: blynkkk/blynk-server

@SuppressWarnings("unchecked")
public static List<?> sortStringAsInt(List<?> list, String field, String order) {
  if (list.size() == 0) {
    return list;
  }
  Comparator c = new GenericStringAsIntComparator(list.get(0).getClass(), field);
  list.sort("asc".equalsIgnoreCase(order) ? c : Collections.reverseOrder(c));
  return list;
}
origin: spring-projects/spring-framework

private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
  List<Method> matches = new ArrayList<>();
  for (MethodDescriptor methodDescriptor : methodDescriptors) {
    Method method = methodDescriptor.getMethod();
    if (isCandidateWriteMethod(method)) {
      matches.add(method);
    }
  }
  // Sort non-void returning write methods to guard against the ill effects of
  // non-deterministic sorting of methods returned from Class#getDeclaredMethods
  // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
  matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
  return matches;
}
origin: line/armeria

/**
 * Attaches a given {@code value} to the value list. If the list is not empty
 * the {@code value} is added, and sorted by the given {@link Comparator}.
 */
private void addValue(V value, @Nullable Comparator<V> comparator) {
  if (values == null) {
    values = new ArrayList<>();
  }
  values.add(value);
  // Sort the values using the given comparator.
  if (comparator != null && values.size() > 1) {
    values.sort(comparator);
  }
}
origin: robolectric/robolectric

@Nonnull
private <T> List<Class<? extends T>> prioritize(Iterable<Class<? extends T>> iterable) {
 List<Class<? extends T>> serviceClasses = new ArrayList<>();
 for (Class<? extends T> serviceClass : iterable) {
  serviceClasses.add(serviceClass);
 }
 Comparator<Class<? extends T>> c = reverseOrder(comparing(PluginFinder::priority));
 c = c.thenComparing(Class::getName);
 serviceClasses.sort(c);
 return serviceClasses;
}
origin: spring-projects/spring-framework

for (String pattern : this.patterns) {
  if (pattern.equals(destination) || this.pathMatcher.match(pattern, destination)) {
    matches.add(pattern);
if (matches.isEmpty()) {
  return null;
matches.sort(this.pathMatcher.getPatternComparator(destination));
return new DestinationPatternsMessageCondition(matches, this.pathMatcher);
origin: skylot/jadx

public List<JavaPackage> getPackages() {
  List<JavaClass> classList = getClasses();
  if (classList.isEmpty()) {
    return Collections.emptyList();
  }
  Map<String, List<JavaClass>> map = new HashMap<>();
  for (JavaClass javaClass : classList) {
    String pkg = javaClass.getPackage();
    List<JavaClass> clsList = map.computeIfAbsent(pkg, k -> new ArrayList<>());
    clsList.add(javaClass);
  }
  List<JavaPackage> packages = new ArrayList<>(map.size());
  for (Map.Entry<String, List<JavaClass>> entry : map.entrySet()) {
    packages.add(new JavaPackage(entry.getKey(), entry.getValue()));
  }
  Collections.sort(packages);
  for (JavaPackage pkg : packages) {
    pkg.getClasses().sort(Comparator.comparing(JavaClass::getName));
  }
  return Collections.unmodifiableList(packages);
}
origin: stanfordnlp/CoreNLP

private static final List<List<ArgumentSequence>> getFullConjunctArgumentsHelper(SemanticGraph sg, IndexedWord conjGov, IndexedWord orphanGov) {
  List<List<ArgumentSequence>> arguments = new LinkedList<>();
  for (SemanticGraphEdge edge : sg.outgoingEdgeIterable(conjGov)) {
    if (isArgument(sg, edge) && edge.getDependent().pseudoPosition() < orphanGov.pseudoPosition()) {
      List<ArgumentSequence> argumentVariants = new LinkedList<>();
      ArgumentSequence seq = new ArgumentSequence(edge.getDependent(), sg.yield(edge.getDependent()));
      argumentVariants.add(seq);
      getArgumentSubsequences(sg, edge.getDependent(), argumentVariants);
      arguments.add(argumentVariants);
    }
  }
  arguments.sort((arg1, arg2) -> arg1.get(0).head.index() - arg2.get(0).head.index());
  return arguments;
}
origin: graphhopper/graphhopper

private void parseSolutionsAndAddToResponse(List<List<Label.Transition>> solutions, PointList waypoints) {
  for (List<Label.Transition> solution : solutions) {
    final List<Trip.Leg> legs = tripFromLabel.getTrip(translation, graphExplorer, accessEgressWeighting, solution);
    final PathWrapper pathWrapper = tripFromLabel.createPathWrapper(translation, waypoints, legs);
    pathWrapper.setImpossible(solution.stream().anyMatch(t -> t.label.impossible));
    pathWrapper.setTime((solution.get(solution.size()-1).label.currentTime - solution.get(0).label.currentTime));
    response.add(pathWrapper);
  }
  Comparator<PathWrapper> c = Comparator.comparingInt(p -> (p.isImpossible() ? 1 : 0));
  Comparator<PathWrapper> d = Comparator.comparingDouble(PathWrapper::getTime);
  response.getAll().sort(c.thenComparing(d));
}
origin: hs-web/hsweb-framework

  @Override
  public List<ActivityImpl> getUserTasksByProcDefKey(String procDefKey) {
    ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(procDefKey).orderByProcessDefinitionVersion().desc().list().get(0);
    String procDefId = definition.getId();
    List<ActivityImpl> activities = findActivities(procDefId, activity -> "userTask".equals(activity.getProperty("type")));
//
    if (null != activities) {
      activities.sort(Comparator.comparing(ProcessElementImpl::getId));
    }
    return activities;
  }

origin: line/armeria

private static ImmutableList<Tag> sort(List<Tag> tags) {
  if (tags.isEmpty()) {
    return ImmutableList.of();
  }
  tags.sort(comparing(Tag::getKey));
  return ImmutableList.copyOf(tags);
}
origin: oblac/jodd

/**
 * Collects all interceptors.
 */
protected void collectActionInterceptors() {
  final Collection<? extends ActionInterceptor> interceptorValues = interceptorsManager.getAllInterceptors();
  interceptors = new ArrayList<>();
  interceptors.addAll(interceptorValues);
  interceptors.sort(Comparator.comparing(a -> a.getClass().getSimpleName()));
}
origin: spring-projects/spring-framework

public void stop() {
  if (this.members.isEmpty()) {
    return;
    logger.debug("Stopping beans in phase " + this.phase);
  this.members.sort(Collections.reverseOrder());
  CountDownLatch latch = new CountDownLatch(this.smartMemberCount);
  Set<String> countDownBeanNames = Collections.synchronizedSet(new LinkedHashSet<>());
origin: spring-projects/spring-framework

/**
 * Return the {@link Method} mapped to the given exception type, or {@code null} if none.
 */
@Nullable
private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
  List<Class<? extends Throwable>> matches = new ArrayList<>();
  for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
    if (mappedException.isAssignableFrom(exceptionType)) {
      matches.add(mappedException);
    }
  }
  if (!matches.isEmpty()) {
    matches.sort(new ExceptionDepthComparator(exceptionType));
    return this.mappedMethods.get(matches.get(0));
  }
  else {
    return null;
  }
}
origin: AxonFramework/AxonFramework

private static ParameterResolverFactory[] flatten(List<ParameterResolverFactory> factories) {
  List<ParameterResolverFactory> flattened = new ArrayList<>(factories.size());
  for (ParameterResolverFactory parameterResolverFactory : factories) {
    if (parameterResolverFactory instanceof MultiParameterResolverFactory) {
      flattened.addAll(((MultiParameterResolverFactory) parameterResolverFactory).getDelegates());
    } else {
      flattened.add(parameterResolverFactory);
    }
  }
  flattened.sort(PriorityAnnotationComparator.getInstance());
  return flattened.toArray(new ParameterResolverFactory[0]);
}
origin: blynkkk/blynk-server

@SuppressWarnings("unchecked")
public static List<?> sort(List<?> list, String field, String order) {
  if (list.size() == 0) {
    return list;
  }
  Comparator c = new GenericComparator(list.get(0).getClass(), field);
  list.sort("asc".equalsIgnoreCase(order) ? c : Collections.reverseOrder(c));
  return list;
}
java.utilListsort

Popular methods of List

  • add
  • size
    Returns the number of elements in this List.
  • get
    Returns the element at the specified location in this List.
  • isEmpty
    Returns whether this List contains no elements.
  • addAll
  • toArray
    Returns an array containing all elements contained in this List. If the specified array is large eno
  • contains
    Tests whether this List contains the specified object.
  • remove
    Removes the first occurrence of the specified object from this List.
  • iterator
    Returns an iterator on the elements of this List. The elements are iterated in the same order as the
  • clear
  • stream
  • forEach
  • stream,
  • forEach,
  • set,
  • subList,
  • indexOf,
  • equals,
  • hashCode,
  • removeAll,
  • listIterator

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now