mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extracted method for comparing nullable strings
This commit is contained in:
+2
-8
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.rename.naming;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.usages.RenameableUsage;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -37,15 +38,8 @@ public abstract class AutomaticUsageRenamer<T> {
|
||||
myNewName = newName;
|
||||
List<T> elements = new ArrayList<T>(renamedElements);
|
||||
Collections.sort(elements, new Comparator<T>() {
|
||||
private int compareNullable(@Nullable String s1, @Nullable String s2) {
|
||||
if (s1 != null) {
|
||||
return s2 == null ? 1 : s1.compareTo(s2);
|
||||
}
|
||||
return s2 == null ? 0 : -1;
|
||||
}
|
||||
|
||||
public int compare(T o1, T o2) {
|
||||
int i = compareNullable(getSourceName(o1), getSourceName(o2));
|
||||
int i = StringUtil.compare(getSourceName(o1), getSourceName(o2), false);
|
||||
if (i != 0) return i;
|
||||
return getName(o1).compareTo(getName(o2));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ui.treeStructure;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
@@ -57,10 +58,6 @@ public class WeightBasedComparator implements Comparator<NodeDescriptor> {
|
||||
}
|
||||
|
||||
protected static int compareToString(final NodeDescriptor first, final NodeDescriptor second) {
|
||||
String s1 = first.toString();
|
||||
String s2 = second.toString();
|
||||
if (s1 == null) return s2 == null ? 0 : -1;
|
||||
if (s2 == null) return +1;
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
return StringUtil.compare(first.toString(), second.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
@@ -94,9 +95,7 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
case COLUMN_NAME:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
return compareStrings(name1, name2);
|
||||
return StringUtil.compare(o1.getName(), o2.getName(), true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,9 +119,7 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
case COLUMN_CATEGORY:
|
||||
return new Comparator<IdeaPluginDescriptor>() {
|
||||
public int compare(IdeaPluginDescriptor o1, IdeaPluginDescriptor o2) {
|
||||
String cat1 = o1.getCategory();
|
||||
String cat2 = o2.getCategory();
|
||||
return compareStrings(cat1, cat2);
|
||||
return StringUtil.compare(o1.getCategory(), o2.getCategory(), true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -148,21 +145,6 @@ class PluginManagerColumnInfo extends ColumnInfo<IdeaPluginDescriptor, String> {
|
||||
}
|
||||
}
|
||||
|
||||
public static int compareStrings(String str1, String str2) {
|
||||
if (str1 == null && str2 == null) {
|
||||
return 0;
|
||||
}
|
||||
else if (str1 == null) {
|
||||
return -1;
|
||||
}
|
||||
else if (str2 == null) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return str1.compareToIgnoreCase(str2);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public static String getFormattedSize(String size) {
|
||||
if (size.equals("-1")) {
|
||||
|
||||
@@ -1800,6 +1800,13 @@ public class StringUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static int compare(@Nullable String s1, @Nullable String s2, boolean ignoreCase) {
|
||||
if (s1 == s2) return 0;
|
||||
if (s1 == null) return -1;
|
||||
if (s2 == null) return 1;
|
||||
return ignoreCase ? s1.compareToIgnoreCase(s2) : s1.compareTo(s2);
|
||||
}
|
||||
|
||||
public static int hashCode(@NotNull CharSequence s) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user