simplification: use Objects.equals in classes from intellij.platform.util module

This commit is contained in:
nik
2019-02-11 18:48:18 +03:00
parent 0845c6afc1
commit 8dbb526c52
9 changed files with 19 additions and 32 deletions
@@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* @author traff
@@ -327,8 +328,8 @@ public class PathMappingSettings extends AbstractPathMapper implements Cloneable
PathMapping mapping = (PathMapping)o;
if (myLocalRoot != null ? !myLocalRoot.equals(mapping.myLocalRoot) : mapping.myLocalRoot != null) return false;
if (myRemoteRoot != null ? !myRemoteRoot.equals(mapping.myRemoteRoot) : mapping.myRemoteRoot != null) return false;
if (!Objects.equals(myLocalRoot, mapping.myLocalRoot)) return false;
if (!Objects.equals(myRemoteRoot, mapping.myRemoteRoot)) return false;
return true;
}
@@ -335,7 +335,7 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
}
if (mySize == 1) {
return myElem == null ? that.myElem == null : myElem.equals(that.myElem);
return Objects.equals(myElem, that.myElem);
}
return compareOneByOne(that);
@@ -347,8 +347,7 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
}
if (mySize == 1) {
Object o = that.get(0);
return myElem == null ? o == null : myElem.equals(o);
return Objects.equals(myElem, that.get(0));
}
return compareOneByOne(that);
@@ -358,7 +357,7 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
for (int i = 0; i < mySize; i++) {
E o1 = get(i);
Object o2 = that.get(i);
if (o1 == null ? o2 != null : !o1.equals(o2)) {
if (!Objects.equals(o1, o2)) {
return false;
}
}
@@ -249,15 +249,11 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
return ent.setValue(value);
}
private static boolean valEquals(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) return false;
Map.Entry e = (Map.Entry)o;
return valEquals(key, e.getKey()) && valEquals(getValue(), e.getValue());
return Objects.equals(key, e.getKey()) && Objects.equals(getValue(), e.getValue());
}
@Override
@@ -611,7 +611,7 @@ public class ContainerUtil extends ContainerUtilRt {
K key = entry.getKey();
V v2 = entry.getValue();
V v1 = map1.get(key);
if (!(v1 == v2 || v1 != null && v1.equals(v2))) {
if (!Objects.equals(v1, v2)) {
res.remove(key);
}
}
@@ -626,7 +626,7 @@ public class ContainerUtil extends ContainerUtilRt {
for (K k : keys) {
V v1 = map1.get(k);
V v2 = map2.get(k);
if (!(v1 == v2 || v1 != null && v1.equals(v2))) {
if (!Objects.equals(v1, v2)) {
res.put(k, Couple.of(v1, v2));
}
}
@@ -111,7 +111,7 @@ public abstract class ImmutableList<E> extends AbstractCollection<E> implements
while (e1.hasNext() && e2.hasNext()) {
E o1 = e1.next();
Object o2 = e2.next();
if (o1 == null ? o2 != null : !o1.equals(o2)) {
if (!Objects.equals(o1, o2)) {
return false;
}
}
@@ -61,13 +61,6 @@ class LockFreeCopyOnWriteArrayList<E> implements List<E>, RandomAccess, Concurre
return size() == 0;
}
/**
* Test for equality, coping with nulls.
*/
private static boolean eq(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
/**
* static version of indexOf, to allow repeated calls without
* needing to re-acquire array each time.
@@ -443,7 +436,7 @@ class LockFreeCopyOnWriteArrayList<E> implements List<E>, RandomAccess, Concurre
int i;
for (i = newLen; i != 0; --i) {
Object element = elements[i];
if (eq(o, element)) {
if (Objects.equals(o, element)) {
// found one; copy remaining and exit
System.arraycopy(elements, 0, newElements, 0, i);
break;
@@ -452,7 +445,7 @@ class LockFreeCopyOnWriteArrayList<E> implements List<E>, RandomAccess, Concurre
}
// special handling for last cell
if (i == 0 && !eq(o, elements[0])) {
if (i == 0 && !Objects.equals(o, elements[0])) {
return null;
}
return newElements;
@@ -511,7 +504,7 @@ class LockFreeCopyOnWriteArrayList<E> implements List<E>, RandomAccess, Concurre
int len = elements.length;
newElements = new Object[len + 1];
for (int i = 0; i < len; ++i) {
if (eq(e, elements[i])) {
if (Objects.equals(e, elements[i])) {
return false; // exit, throwing away copy
}
newElements[i] = elements[i];
@@ -813,7 +806,7 @@ class LockFreeCopyOnWriteArrayList<E> implements List<E>, RandomAccess, Concurre
List<?> list = (List<?>)o;
Iterator<?> it = list.iterator();
for (Object element : array) {
if (!it.hasNext() || !eq(element, it.next())) {
if (!it.hasNext() || !Objects.equals(element, it.next())) {
return false;
}
}
@@ -285,16 +285,12 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
return ent.setValue(value);
}
private static boolean valEqual(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Entry)) return false;
//noinspection unchecked
Entry<K,V> e = (Entry)o;
return keyEqual(key, e.getKey(), myStrategy) && valEqual(getValue(), e.getValue());
return keyEqual(key, e.getKey(), myStrategy) && Objects.equals(getValue(), e.getValue());
}
@Override
@@ -19,6 +19,7 @@ import com.intellij.ui.Gray;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Objects;
import static java.lang.Math.ceil;
@@ -94,7 +95,7 @@ public class ColorIcon extends EmptyIcon {
if (myBorder != icon.myBorder) return false;
if (myColorSize != icon.myColorSize) return false;
if (myColor != null ? !myColor.equals(icon.myColor) : icon.myColor != null) return false;
if (!Objects.equals(myColor, icon.myColor)) return false;
return true;
}
@@ -21,6 +21,7 @@ import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.util.Comparator;
import java.util.Objects;
public abstract class ColumnInfo <Item, Aspect> {
private String myName;
@@ -121,7 +122,7 @@ public abstract class ColumnInfo <Item, Aspect> {
final ColumnInfo that = (ColumnInfo)o;
if (myName != null ? !myName.equals(that.myName) : that.myName != null) return false;
if (!Objects.equals(myName, that.myName)) return false;
return true;
}