mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 17:03:12 +07:00
cleanup: generification
This commit is contained in:
+3
-6
@@ -44,18 +44,15 @@ import com.intellij.psi.util.PsiUtilCore;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class InspectionResultsViewComparator implements Comparator {
|
||||
public class InspectionResultsViewComparator implements Comparator<InspectionTreeNode> {
|
||||
private static final Logger LOG = Logger.getInstance(InspectionResultsViewComparator.class);
|
||||
|
||||
public boolean areEqual(Object o1, Object o2) {
|
||||
public boolean areEqual(InspectionTreeNode o1, InspectionTreeNode o2) {
|
||||
return o1.getClass().equals(o2.getClass()) && compare(o1, o2) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
InspectionTreeNode node1 = (InspectionTreeNode)o1;
|
||||
InspectionTreeNode node2 = (InspectionTreeNode)o2;
|
||||
|
||||
public int compare(InspectionTreeNode node1, InspectionTreeNode node2) {
|
||||
if (node1 instanceof InspectionSeverityGroupNode && node2 instanceof InspectionSeverityGroupNode) {
|
||||
final InspectionSeverityGroupNode groupNode1 = (InspectionSeverityGroupNode)node1;
|
||||
final InspectionSeverityGroupNode groupNode2 = (InspectionSeverityGroupNode)node2;
|
||||
|
||||
@@ -989,8 +989,8 @@ public final class TreeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertNode(@NotNull MutableTreeNode child, @NotNull MutableTreeNode parent, @Nullable DefaultTreeModel model,
|
||||
@NotNull Comparator<? extends TreeNode> comparator) {
|
||||
public static <T extends MutableTreeNode> void insertNode(@NotNull T child, @NotNull T parent, @Nullable DefaultTreeModel model,
|
||||
@NotNull Comparator<? super T> comparator) {
|
||||
int index = indexedBinarySearch(parent, child, comparator);
|
||||
if (index >= 0) {
|
||||
LOG.error("Node " + child + " is already added to " + parent);
|
||||
@@ -1005,13 +1005,14 @@ public final class TreeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static int indexedBinarySearch(@NotNull TreeNode parent, @NotNull TreeNode key, Comparator comparator) {
|
||||
public static <T extends TreeNode> int indexedBinarySearch(@NotNull T parent, @NotNull T key, @NotNull Comparator<? super T> comparator) {
|
||||
int low = 0;
|
||||
int high = parent.getChildCount() - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) / 2;
|
||||
TreeNode treeNode = parent.getChildAt(mid);
|
||||
//noinspection unchecked
|
||||
T treeNode = (T)parent.getChildAt(mid);
|
||||
int cmp = comparator.compare(treeNode, key);
|
||||
if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
@@ -1028,6 +1029,6 @@ public final class TreeUtil {
|
||||
|
||||
@NotNull
|
||||
public static Comparator<TreePath> getDisplayOrderComparator(@NotNull final JTree tree) {
|
||||
return (path1, path2) -> tree.getRowForPath(path1) - tree.getRowForPath(path2);
|
||||
return Comparator.comparingInt(tree::getRowForPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user