8226831: Use Objects.equals() when appropriate
Reviewed-by: rriggs, bpb
This commit is contained in:
parent
99bf89c581
commit
3ed845784d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,6 +25,8 @@
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class represents a Network Interface address. In short it's an
|
||||
* IP address, a subnet mask and a broadcast address when the address is
|
||||
@ -99,17 +101,17 @@ public class InterfaceAddress {
|
||||
* @see java.net.InterfaceAddress#hashCode()
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof InterfaceAddress)) {
|
||||
return false;
|
||||
if (obj instanceof InterfaceAddress) {
|
||||
InterfaceAddress cmp = (InterfaceAddress) obj;
|
||||
|
||||
if (Objects.equals(address, cmp.address) &&
|
||||
Objects.equals(broadcast, cmp.broadcast) &&
|
||||
maskLength == cmp.maskLength)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
InterfaceAddress cmp = (InterfaceAddress) obj;
|
||||
if ( !(address == null ? cmp.address == null : address.equals(cmp.address)) )
|
||||
return false;
|
||||
if ( !(broadcast == null ? cmp.broadcast == null : broadcast.equals(cmp.broadcast)) )
|
||||
return false;
|
||||
if (maskLength != cmp.maskLength)
|
||||
return false;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ import java.io.InputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Objects;
|
||||
import sun.net.util.IPAddressUtil;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
@ -343,10 +344,7 @@ public abstract class URLStreamHandler {
|
||||
* @since 1.3
|
||||
*/
|
||||
protected boolean equals(URL u1, URL u2) {
|
||||
String ref1 = u1.getRef();
|
||||
String ref2 = u2.getRef();
|
||||
return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
|
||||
sameFile(u1, u2);
|
||||
return Objects.equals(u1.getRef(), u2.getRef()) && sameFile(u1, u2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1100,8 +1100,7 @@ class AttributeEntry implements Map.Entry<Attribute,Object> {
|
||||
return false;
|
||||
}
|
||||
AttributeEntry other = (AttributeEntry) o;
|
||||
return other.key.equals(key) &&
|
||||
(value == null ? other.value == null : other.value.equals(value));
|
||||
return other.key.equals(key) && Objects.equals(other.value, value);
|
||||
}
|
||||
|
||||
public Attribute getKey() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -311,8 +311,7 @@ public class TreeMap<K,V>
|
||||
public void putAll(Map<? extends K, ? extends V> map) {
|
||||
int mapSize = map.size();
|
||||
if (size==0 && mapSize!=0 && map instanceof SortedMap) {
|
||||
Comparator<?> c = ((SortedMap<?,?>)map).comparator();
|
||||
if (c == comparator || (c != null && c.equals(comparator))) {
|
||||
if (Objects.equals(comparator, ((SortedMap<?,?>)map).comparator())) {
|
||||
++modCount;
|
||||
try {
|
||||
buildFromSorted(mapSize, map.entrySet().iterator(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -302,9 +302,7 @@ public class TreeSet<E> extends AbstractSet<E>
|
||||
m instanceof TreeMap) {
|
||||
SortedSet<? extends E> set = (SortedSet<? extends E>) c;
|
||||
TreeMap<E,Object> map = (TreeMap<E, Object>) m;
|
||||
Comparator<?> cc = set.comparator();
|
||||
Comparator<? super E> mc = map.comparator();
|
||||
if (cc==mc || (cc != null && cc.equals(mc))) {
|
||||
if (Objects.equals(set.comparator(), map.comparator())) {
|
||||
map.addAllForTreeSet(set, PRESENT);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,7 +23,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*-
|
||||
/*
|
||||
* FTP stream opener
|
||||
*/
|
||||
|
||||
@ -34,6 +34,7 @@ import java.net.URL;
|
||||
import java.net.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import sun.net.ftp.FtpClient;
|
||||
import sun.net.www.protocol.http.HttpURLConnection;
|
||||
|
||||
@ -47,8 +48,7 @@ public class Handler extends java.net.URLStreamHandler {
|
||||
protected boolean equals(URL u1, URL u2) {
|
||||
String userInfo1 = u1.getUserInfo();
|
||||
String userInfo2 = u2.getUserInfo();
|
||||
return super.equals(u1, u2) &&
|
||||
(userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2));
|
||||
return super.equals(u1, u2) && Objects.equals(userInfo1, userInfo2);
|
||||
}
|
||||
|
||||
protected java.net.URLConnection openConnection(URL u)
|
||||
|
@ -274,8 +274,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
||||
* with the same parameters.
|
||||
*/
|
||||
public boolean equals(AlgorithmId other) {
|
||||
boolean paramsEqual =
|
||||
(params == null ? other.params == null : params.equals(other.params));
|
||||
boolean paramsEqual = Objects.equals(other.params, params);
|
||||
return (algid.equals((Object)other.algid) && paramsEqual);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user