mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
merge duplicated ArrayUtil.indexOf into single method (PR #887)
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeStyleSettingsLoader;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -66,14 +67,14 @@ public class FormatterStarter extends ApplicationStarterEx {
|
||||
if (args.length < 2) {
|
||||
showUsageInfo(messageOutput);
|
||||
}
|
||||
for (int i = 1; i < args.length; i ++) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (args[i].startsWith("-")) {
|
||||
if (checkOption(args[i], "-h", "-help")) {
|
||||
showUsageInfo(messageOutput);
|
||||
}
|
||||
if (checkOption(args[i], "-s", "-settings")) {
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i ++;
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
fatalError(messageOutput, "Missing settings file path.");
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public class FormatterStarter extends ApplicationStarterEx {
|
||||
}
|
||||
else if (checkOption(args[i], "-m", "-mask")) {
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
i ++;
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
fatalError(messageOutput, "Missing file mask(s).");
|
||||
}
|
||||
@@ -138,10 +139,7 @@ public class FormatterStarter extends ApplicationStarterEx {
|
||||
}
|
||||
|
||||
private static boolean checkOption(@NotNull String arg, String... variants) {
|
||||
for (String variant: variants) {
|
||||
if (variant.equals(arg)) return true;
|
||||
}
|
||||
return false;
|
||||
return ArrayUtil.contains(arg, variants);
|
||||
}
|
||||
|
||||
private static String getAppInfo() {
|
||||
|
||||
@@ -44,19 +44,21 @@ public class ArrayUtilRt {
|
||||
* {@code equals} of arrays elements to compare {@code obj} with
|
||||
* these elements.
|
||||
*/
|
||||
@Contract(pure=true)
|
||||
@Contract(pure = true)
|
||||
public static <T> int find(@NotNull final T[] src, @Nullable final T obj) {
|
||||
for (int i = 0; i < src.length; i++) {
|
||||
final T o = src[i];
|
||||
if (o == null) {
|
||||
if (obj == null) {
|
||||
return i;
|
||||
}
|
||||
return indexOf(src, obj, 0, src.length);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static int indexOf(@NotNull Object[] objects, Object object, int start, int end) {
|
||||
if (object == null) {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (objects[i] == null) return i;
|
||||
}
|
||||
else {
|
||||
if (o.equals(obj)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (object.equals(objects[i])) return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -682,17 +682,7 @@ public class ArrayUtil extends ArrayUtilRt {
|
||||
|
||||
@Contract(pure=true)
|
||||
public static int indexOf(@NotNull Object[] objects, Object object, int start, int end) {
|
||||
if (object == null) {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (objects[i] == null) return i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (object.equals(objects[i])) return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return ArrayUtilRt.indexOf(objects, object, start, end);
|
||||
}
|
||||
|
||||
@Contract(pure=true)
|
||||
|
||||
Reference in New Issue
Block a user