mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8226831: Use Objects.equals() when appropriate
Reviewed-by: rriggs, bpb
This commit is contained in:
parent
99bf89c581
commit
3ed845784d
7 changed files with 26 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue