Skip to content

Commit

Permalink
7418: Stop using Collections sort method
Browse files Browse the repository at this point in the history
Reviewed-by: aptmac, hdafgard
  • Loading branch information
thegreystone committed Oct 26, 2021
1 parent ef36b79 commit 77580fe
Show file tree
Hide file tree
Showing 42 changed files with 90 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -35,7 +35,6 @@
import java.io.PrintStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -172,7 +171,7 @@ public List<String> getCategories() {
categories.add(c.getCategory());
}
List<String> list = new ArrayList<>(categories);
Collections.sort(list);
list.sort(null);
return list;
}

Expand All @@ -188,7 +187,7 @@ public List<Command> getCommands(String category) {
list.add(c);
}
}
Collections.sort(list);
list.sort(null);
return list;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -34,7 +34,6 @@

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.openjdk.jmc.commands.IExecute;
Expand All @@ -53,7 +52,7 @@ public boolean execute(Statement statement, PrintStream out) {
keys.add((String) key);
}
}
Collections.sort(keys);
keys.sort(null);
for (String key : keys) {
out.println(key + "=" + System.getProperties().get(key)); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -37,7 +37,6 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand All @@ -62,7 +61,6 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.part.EditorPart;

import org.openjdk.jmc.common.unit.KindOfQuantity;
import org.openjdk.jmc.common.unit.UnitLookup;
import org.openjdk.jmc.console.persistence.PersistencePlugin;
Expand Down Expand Up @@ -198,8 +196,7 @@ private static void addDefaultCharts(SectionPartManager spm, PersistenceReader p
}
// Order by size descending and add charts
List<Entry<KindOfQuantity<?>, List<MRI>>> allAttributes = new ArrayList<>(mrisByKind.entrySet());
Collections.sort(allAttributes, new Comparator<Entry<KindOfQuantity<?>, List<MRI>>>() {

allAttributes.sort(new Comparator<Entry<KindOfQuantity<?>, List<MRI>>>() {
@Override
public int compare(Entry<KindOfQuantity<?>, List<MRI>> e1, Entry<KindOfQuantity<?>, List<MRI>> e2) {
return e2.getValue().size() - e1.getValue().size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -32,7 +32,6 @@
*/
package org.openjdk.jmc.console.ui.notification.tab;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -68,7 +67,6 @@
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

import org.openjdk.jmc.alert.AlertPlugin;
import org.openjdk.jmc.console.ui.actions.MBeanAutomaticRefreshAction;
import org.openjdk.jmc.console.ui.notification.NotificationPlugin;
Expand Down Expand Up @@ -415,7 +413,7 @@ private boolean askConfirmation(Shell shell, TriggerRule ... rules) {
for (TriggerRule rule : rules) {
names.add(rule.getName());
}
Collections.sort(names);
names.sort(null);

StringBuilder namesBuilder = new StringBuilder();
int index = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.console.ui.editor.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -93,7 +92,7 @@ public static List<IConfigurationElement> getContributionsFor(IWorkbenchPart edi
}
}
}
Collections.sort(pageElements, PAGE_COMPARATOR);
pageElements.sort(PAGE_COMPARATOR);
return pageElements;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -39,7 +39,6 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -242,7 +241,7 @@ public static Set<String> createQualifiedVariableSet(
}
}
}
Collections.sort(variables);
variables.sort(null);
return new LinkedHashSet<>(variables);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -105,7 +105,7 @@ public boolean replaceOriginalContentsFor(IEventConfiguration workingCopy) {
*/
@Override
public void notifyObservers(Object arg) {
Collections.sort(m_templates, COMPARATOR);
m_templates.sort(COMPARATOR);
super.notifyObservers(arg);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,7 +36,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void addAttributesFromRules(Collection<IRule> rules) {
pageAttributes.add(new AttributeGroup(rule.getName(), unique));
}
}
Collections.sort(pageAttributes, (p1, p2) -> p1.groupTitle.compareTo(p2.groupTitle));
pageAttributes.sort((p1, p2) -> p1.groupTitle.compareTo(p2.groupTitle));
if (rest.size() > 0) {
pageAttributes.add(new AttributeGroup(Messages.ATTRIBUTE_CONFIG_SHARED_GROUP_NAME, rest));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.flightrecorder.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -173,7 +172,7 @@ private void sortChildren() {
((EventTypeFolderNode) c).sortChildren();
}
}
Collections.sort(getChildren(), new Comparator<Object>() {
getChildren().sort(new Comparator<Object>() {

@Override
public int compare(Object o1, Object o2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.joverflow.batch;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
Expand Down Expand Up @@ -284,7 +283,7 @@ private <T extends AbstractClusterNode> void generateFullRefChainClusters(
clusterList.add(cluster.getFinalCluster(referer));
}

Collections.sort(clusterList, ReferencedObjCluster.DEFAULT_COMPARATOR);
clusterList.sort(ReferencedObjCluster.DEFAULT_COMPARATOR);
}

private List<List<? extends ReferencedObjCluster>> getProblematicDataClustersWithNearestField(int minOvhd) {
Expand Down Expand Up @@ -369,7 +368,7 @@ private <T extends AbstractClusterNode> void generateFieldClusters(
clusterList.add(cluster.getFinalCluster(referer));
}

Collections.sort(clusterList, ReferencedObjCluster.DEFAULT_COMPARATOR);
clusterList.sort(ReferencedObjCluster.DEFAULT_COMPARATOR);
}

private abstract static class AbstractClusterNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.joverflow.descriptors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.logging.Logger;
Expand Down Expand Up @@ -135,7 +134,7 @@ public ArrayList<CollectionClassDescriptor> getOverheadsByClass() {
result.add(factory.getClassDescriptor());
}

Collections.sort(result, new Comparator<CollectionClassDescriptor>() {
result.sort(new Comparator<CollectionClassDescriptor>() {
@Override
public int compare(CollectionClassDescriptor d1, CollectionClassDescriptor d2) {
long o1 = d1.getTotalOverhead();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,7 +36,6 @@
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -606,7 +605,7 @@ public Snapshot buildSnapshot(ReadBuffer readBuf) {
JavaObjectTable objectTable = objTableBuilder.buildJavaObjectTable(classes);
resolveSuperclasses(classes);
recheckPointerSize(objectTable, readBuf);
Collections.sort(roots); // More interesting roots will be scanned first
roots.sort(null); // More interesting roots will be scanned first

Snapshot snapshot = new Snapshot(hprofPointerSize, pointerSize, objHeaderSize, objAlignment,
usingNarrowPointers, roughTotalObjectSize, roots, objectTable, objIdToPosInObjectTable, classes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.joverflow.stats;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

Expand Down Expand Up @@ -67,7 +66,7 @@ public List<Entry> getPrunedAndSortedEntries(int sizeThreshold) {
}
result.add(entryForOthers);

Collections.sort(result, SPECIAL_LENGTH_COMPARATOR);
result.sort(SPECIAL_LENGTH_COMPARATOR);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -33,7 +33,6 @@
package org.openjdk.jmc.joverflow.stats;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -88,7 +87,7 @@ public List<Entry> getListSortedByInclusiveSize(int minInclusiveSize) {
}
}

Collections.sort(result, new Comparator<Entry>() {
result.sort(new Comparator<Entry>() {
@Override
public int compare(Entry o1, Entry o2) {
long diff = (o2.getTotalInclusiveSize() - o1.getTotalInclusiveSize());
Expand Down Expand Up @@ -144,7 +143,7 @@ public List<ProblemFieldsEntry> getListSortedByNullFieldsOvhd(float percentile)
ArrayList<ProblemFieldsEntry> result = findClassesWithNullFields(percentile);
checkForSuperclassesDefiningProblemFields(result);

Collections.sort(result, PROBLEM_OVERHEAD_COMPARATOR);
result.sort(PROBLEM_OVERHEAD_COMPARATOR);
return result;
}

Expand All @@ -162,7 +161,7 @@ public List<ProblemFieldsEntry> getListSortedByUnusedHiByteFieldsOvhd(float perc
ArrayList<ProblemFieldsEntry> result = findClassesWithUnusedHiByteFields(percentile);
checkForSuperclassesDefiningProblemFields(result);

Collections.sort(result, PROBLEM_OVERHEAD_COMPARATOR);
result.sort(PROBLEM_OVERHEAD_COMPARATOR);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -34,7 +34,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

import org.openjdk.jmc.joverflow.heap.model.JavaValueArray;
Expand Down Expand Up @@ -118,7 +117,7 @@ void calculateFinalStats() {
}
}

Collections.sort(result, new Comparator<DupArrayStats.Entry>() {
result.sort(new Comparator<DupArrayStats.Entry>() {
@Override
public int compare(DupArrayStats.Entry e1, DupArrayStats.Entry e2) {
if (e1.overhead > e2.overhead) {
Expand Down
Loading

0 comments on commit 77580fe

Please sign in to comment.