提交 ffab6390 编写于 作者: D darcy

7041136: Use Objects.equals in JDK platform classes

Reviewed-by: alanb, mduigou
上级 0924c27d
......@@ -26,6 +26,7 @@ package java.beans;
import java.util.*;
import java.lang.reflect.*;
import java.util.Objects;
import sun.reflect.misc.*;
......@@ -181,10 +182,6 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
return method;
}
private static boolean equals(Object o1, Object o2) {
return (o1 == null) ? (o2 == null) : o1.equals(o2);
}
private void doProperty(Class type, PropertyDescriptor pd, Object oldInstance, Object newInstance, Encoder out) throws Exception {
Method getter = pd.getReadMethod();
Method setter = pd.getWriteMethod();
......@@ -195,7 +192,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!equals(newValue, out.get(oldValue))) {
if (!Objects.equals(newValue, out.get(oldValue))) {
// Search for a static constant with this value;
Object e = (Object[])pd.getValue("enumerationValues");
if (e instanceof Object[] && Array.getLength(e) % 3 == 0) {
......@@ -233,7 +230,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!equals(newValue, out.get(oldValue))) {
if (!Objects.equals(newValue, out.get(oldValue))) {
out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
}
}
......
......@@ -56,6 +56,8 @@ import javax.swing.plaf.ColorUIResource;
import sun.swing.PrintColorUIResource;
import java.util.Objects;
/*
* Like the <code>Intropector</code>, the <code>MetaData</code> class
* contains <em>meta</em> objects that describe the way
......@@ -134,7 +136,7 @@ class ArrayPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!MetaData.equals(newValue, out.get(oldValue))) {
if (!Objects.equals(newValue, out.get(oldValue))) {
// System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
// invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
......@@ -635,7 +637,7 @@ class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!MetaData.equals(newValue, out.get(oldValue))) {
if (!Objects.equals(newValue, out.get(oldValue))) {
invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
}
}
......@@ -675,7 +677,7 @@ class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!MetaData.equals(newValue, out.get(oldValue))) {
if (!Objects.equals(newValue, out.get(oldValue))) {
invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
} else if ((newValue == null) && !newMap.containsKey(oldKey)) {
// put oldValue(=null?) if oldKey is absent in newMap
......@@ -899,17 +901,17 @@ class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate
if (!(oldInstance instanceof java.awt.Window)) {
Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
Object newBackground = c2.isBackgroundSet() ? c2.getBackground() : null;
if (!MetaData.equals(oldBackground, newBackground)) {
if (!Objects.equals(oldBackground, newBackground)) {
invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
}
Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
Object newForeground = c2.isForegroundSet() ? c2.getForeground() : null;
if (!MetaData.equals(oldForeground, newForeground)) {
if (!Objects.equals(oldForeground, newForeground)) {
invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
}
Object oldFont = c.isFontSet() ? c.getFont() : null;
Object newFont = c2.isFontSet() ? c2.getFont() : null;
if (!MetaData.equals(oldFont, newFont)) {
if (!Objects.equals(oldFont, newFont)) {
invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
}
}
......@@ -1306,10 +1308,6 @@ class MetaData {
internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
}
/*pp*/ static boolean equals(Object o1, Object o2) {
return (o1 == null) ? (o2 == null) : o1.equals(o2);
}
public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
if (type == null) {
return nullPersistenceDelegate;
......
......@@ -34,6 +34,7 @@ import java.util.Date;
import java.lang.NullPointerException; // for javadoc
import java.util.Locale;
import java.util.Objects;
/**
* An HttpCookie object represents an http cookie, which carries state
......@@ -817,7 +818,7 @@ public final class HttpCookie implements Cloneable {
// 3. and have same path (case-sensitive).
return equalsIgnoreCase(getName(), other.getName()) &&
equalsIgnoreCase(getDomain(), other.getDomain()) &&
equals(getPath(), other.getPath());
Objects.equals(getPath(), other.getPath());
}
......@@ -1162,14 +1163,6 @@ public final class HttpCookie implements Cloneable {
return false;
}
private static boolean equals(String s, String t) {
if (s == t) return true;
if ((s != null) && (t != null)) {
return s.equals(t);
}
return false;
}
private static boolean startsWithIgnoreCase(String s, String start) {
if (s == null || start == null) return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册