APISonar


java.util.ArrayList.sort

> java > util > ArrayList > sort
java APIs util APIs ArrayList APIs sort APIs

Example 1
public void sort(Comparator<T> sortFunction) {
        if (values instanceof List) {
            ((List<T>) values).sort(sortFunction);
        } else {
            ArrayList<T> sortedList = new ArrayList<>(values);
            sortedList.sort(sortFunction);
            values.clear();
            values.addAll(sortedList);
        }
    }
Example 2
public static <T> ArrayList<T> sortThis(ArrayList<T> list, Comparator<? super T> comparator)
    {
        list.sort(comparator);
        return list;
    }
Example 3
ArrayList<Integer> results;

    public void testSolveAll()
        throws InterruptedException, ExecutionException {
        results = null;
        Set<Callable<Integer>> solvers = Set.of(
            () -> null,
            () -> 1,
            () -> 2,
            () -> 3,
            () -> null);
        solveAll(cachedThreadPool, solvers);
        results.sort(Comparator.naturalOrder());
        assertEquals(List.of(1, 2, 3), results);
    }
Example 4
private static List<String> sort(List<String>... theLists) {
		ArrayList<String> retVal = new ArrayList<>();
		for (List<String> next : theLists) {
			retVal.addAll(next);
		}
		retVal.sort((o0, o1) -> {
			long i0 = Long.parseLong(o0.substring(o0.indexOf('/') + 1));
			long i1 = Long.parseLong(o1.substring(o1.indexOf('/') + 1));
			return (int) (i0 - i1);
		});
		return retVal;
	}
Example 5
protected Iterable<InlinePreviewViewController> getAllPreviews(boolean paintOrder) {
    final ArrayList<InlinePreviewViewController> all = new ArrayList<>();
    if (overallPreview != null) {
      all.add(overallPreview);
    }
    all.addAll(previews);
    if (paintOrder) {
      all.sort(Comparator.comparingInt(InlinePreviewViewController::getPriority));
    }
    else {
      all.sort((a, b) -> Integer.compare(b.getPriority(), a.getPriority()));
    }
    return all;
  }
Example 6
private final ArrayList<Entry> entries = new ArrayList<>();

    public List<Entry> getSortedEntries() {
        if (!isSorted) {
            entries.sort(MachOSymtab::compareEntries);
            isSorted = true;
        }
        return entries;
    }
Example 7
private ArrayList<GridToStringFieldDescriptor> fields = new ArrayList<>();

    void sortFields() {
        fields.trimToSize();

        fields.sort(Comparator.comparingInt(GridToStringFieldDescriptor::getOrder));
    }
Example 8
private ArrayList<KV<byte[], byte[]>> records = new ArrayList<>();

  public Iterable<KV<byte[], byte[]>> sort() {
    checkState(!sortCalled, "sort() can only be called once.");

    sortCalled = true;

    Comparator<KV<byte[], byte[]>> kvComparator =
        (o1, o2) -> COMPARATOR.compare(o1.getKey(), o2.getKey());
    records.sort(kvComparator);
    return Collections.unmodifiableList(records);
  }
Example 9
private final ArrayList<String> mSortedEntities = new ArrayList<>();

    private void resetSortedEntitiesFromMap() {
        mSortedEntities.clear();
        mSortedEntities.ensureCapacity(mEntityConfidence.size());
        mSortedEntities.addAll(mEntityConfidence.keySet());
        mSortedEntities.sort((e1, e2) -> {
            float score1 = mEntityConfidence.get(e1);
            float score2 = mEntityConfidence.get(e2);
            return Float.compare(score2, score1);
        });
    }
Example 10
private static List<String> dequeToList(final Deque<String> deque) {
        ArrayList<String> result = new ArrayList<>();
        deque.stream().forEachOrdered(result::add);
        result.sort(String.CASE_INSENSITIVE_ORDER);
        return Collections.unmodifiableList(result);
    }
Example 11
public final List<SModel> getModels() {
    assertCanRead();

    ArrayList<SModel> models = new ArrayList<>(myModels);
    models.sort(MODEL_BY_NAME_COMPARATOR);
    return models;
  }
Example 12
private int getBucketIdx(Collection<String> nodeIds, byte phaseInputId) {
        ArrayList<String> server = new ArrayList<>(nodeIds);
        server.sort(null);
        int nodeId = Math.max(server.indexOf(clusterService.localNode().getId()), 0);
        return nodeId | (phaseInputId << 24);
    }
Example 13
public Collection<ModuleHandle> getCollectedModules() {
    ArrayList<ModuleHandle> rv = new ArrayList<>(myOutcome);
    // sort values so that languages come in front of generators.
    rv.sort(Comparator.comparingInt(v -> v.getDescriptor() instanceof LanguageDescriptor ? 0 : 1));
    return Collections.unmodifiableList(rv);
  }
Example 14
private void print(Map<XconnectKey, Integer> nextStore) {
        ArrayList<XconnectKey> a = new ArrayList<>(nextStore.keySet());
        a.sort(Comparator
                .comparing((XconnectKey o) -> o.deviceId().toString())
                .thenComparing((XconnectKey o) -> o.vlanId().toShort()));

        StringBuilder builder = new StringBuilder();
        a.forEach(k ->
            builder.append("\n")
                    .append(k)
                    .append(" --> ")
                    .append(nextStore.get(k))
        );
        print(builder.toString());
    }
Example 15
private void print(Map<PortNextObjectiveStoreKey, Integer> portNextObjStore) {
        ArrayList<PortNextObjectiveStoreKey> a = new ArrayList<>(portNextObjStore.keySet());
        a.sort(Comparator
                .comparing((PortNextObjectiveStoreKey o) -> o.deviceId().toString())
                .thenComparing((PortNextObjectiveStoreKey o) -> o.portNumber().toLong()));

        StringBuilder builder = new StringBuilder();
        a.forEach(k ->
            builder.append("\n")
                    .append(k)
                    .append(" --> ")
                    .append(portNextObjStore.get(k))
        );
        print(builder.toString());
    }
Example 16
private List<RuleTrace> randomMinionHistory(long start, long finish) {
    ArrayList<RuleTrace> result = new ArrayList<>();

    int lineCount = random.nextInt(24);

    for (int i = 0; i < lineCount; ++i) {
      generateRandomLine(start, finish, result);
    }

    result.sort(Comparator.comparingLong(e -> e.startEpochMillis));

    return result;
  }
Example 17
protected ArrayList<TextPiece> _textPiecesFCOrder = new ArrayList<>();

    public void add(TextPiece piece) {
        _textPieces.add(piece);
        _textPiecesFCOrder.add(piece);
        Collections.sort(_textPieces);
        _textPiecesFCOrder.sort(new FCComparator());
    }
Example 18
public List<StatsEntry> getStats() {
        ArrayList<StatsEntry> entries = new ArrayList<>(myStats.keySet());

        entries.sort(StatsEntry::compareTo);
        return entries;
    }
Example 19
public void sortProperties() {

    ArrayList<DeployBeanProperty> list = new ArrayList<>(propMap.values());
    list.sort(PROP_ORDER);

    propMap = new LinkedHashMap<>(list.size());
    for (DeployBeanProperty aList : list) {
      addBeanProperty(aList);
    }
  }
Example 20
public final List<SModel> getModels() {
    assertCanRead();
    if (myCachedModelsList == null) {
      // I don't care to initialize/sort twice in parallel reads, either list is the same
      final ArrayList<SModelBase> list = new ArrayList<>(myModels);
      list.sort(MODEL_BY_NAME_COMPARATOR);
      myCachedModelsList = Collections.unmodifiableList(list);
    }
    return myCachedModelsList;
  }
Example 21
public void setConfigurerModules(List<ConfigurerModule> configurerModules) {
        ArrayList<ConfigurerModule> modules = new ArrayList<>(configurerModules);
        modules.sort(Comparator.comparingInt(ConfigurerModule::order));
        modules.forEach(c -> c.configureModule(configurer));
    }
Example 22
String tagsToString(final Set<String> tags) {
        final ArrayList<String> sortedTags = new ArrayList<>(tags == null ? Collections.emptySet() : tags);
        // Sort tags for the sake of determinism (e.g., tests)
        sortedTags.sort(Comparator.naturalOrder());
        final String joinedString = StringUtils.join(sortedTags, ',');
        // Escape quotes
        return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\"");
    }
Example 23
public void listByName(PrintStream out) {
      ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
      all.sort(new Comparator<MAPIProperty>() {
          public int compare(MAPIProperty a, MAPIProperty b) {
              return a.name.compareTo(b.name);
          }
      });
      list(all, out);
   }
Example 24
private ArrayList<Weight> weightList;

    ArrayList<Weight> getSortedWeights() {
        if (weightList == null) {
            weightList = new ArrayList<>(pages.values());
            weightList.sort((w0, w1) -> Integer.compare(w1.value, w0.value));
        }
        return weightList;
    }
Example 25
private final ArrayList<Page> pages = new ArrayList<>();

    private void sortPages() {
        pages.sort((p0, p1) -> Integer.compare(p1.relations, p0.relations));
        for (int i = 0; i < pages.size(); i++) {
            pages.get(i).id = i;
        }
    }