Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
71df9cef
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
71df9cef
编写于
6月 09, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ObjectUtils.nullSafeEquals allows for JVM method inlining (through reducing its bytecode size)
Issue: SPR-14349 (cherry picked from commit
ca12e13e
)
上级
3680ec5a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
31 deletion
+46
-31
spring-core/src/main/java/org/springframework/util/ObjectUtils.java
...e/src/main/java/org/springframework/util/ObjectUtils.java
+46
-31
未找到文件。
spring-core/src/main/java/org/springframework/util/ObjectUtils.java
浏览文件 @
71df9cef
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -277,14 +277,14 @@ public abstract class ObjectUtils {
//---------------------------------------------------------------------
/**
* Determine if the given objects are equal, returning {@code true}
* if both are {@code null} or {@code false} if only one is
* {@code null}.
* Determine if the given objects are equal, returning {@code true} if
* both are {@code null} or {@code false} if only one is {@code null}.
* <p>Compares arrays with {@code Arrays.equals}, performing an equality
* check based on the array elements rather than the array reference.
* @param o1 first Object to compare
* @param o2 second Object to compare
* @return whether the given objects are equal
* @see Object#equals(Object)
* @see java.util.Arrays#equals
*/
public
static
boolean
nullSafeEquals
(
Object
o1
,
Object
o2
)
{
...
...
@@ -298,33 +298,47 @@ public abstract class ObjectUtils {
return
true
;
}
if
(
o1
.
getClass
().
isArray
()
&&
o2
.
getClass
().
isArray
())
{
if
(
o1
instanceof
Object
[]
&&
o2
instanceof
Object
[])
{
return
Arrays
.
equals
((
Object
[])
o1
,
(
Object
[])
o2
);
}
if
(
o1
instanceof
boolean
[]
&&
o2
instanceof
boolean
[])
{
return
Arrays
.
equals
((
boolean
[])
o1
,
(
boolean
[])
o2
);
}
if
(
o1
instanceof
byte
[]
&&
o2
instanceof
byte
[])
{
return
Arrays
.
equals
((
byte
[])
o1
,
(
byte
[])
o2
);
}
if
(
o1
instanceof
char
[]
&&
o2
instanceof
char
[])
{
return
Arrays
.
equals
((
char
[])
o1
,
(
char
[])
o2
);
}
if
(
o1
instanceof
double
[]
&&
o2
instanceof
double
[])
{
return
Arrays
.
equals
((
double
[])
o1
,
(
double
[])
o2
);
}
if
(
o1
instanceof
float
[]
&&
o2
instanceof
float
[])
{
return
Arrays
.
equals
((
float
[])
o1
,
(
float
[])
o2
);
}
if
(
o1
instanceof
int
[]
&&
o2
instanceof
int
[])
{
return
Arrays
.
equals
((
int
[])
o1
,
(
int
[])
o2
);
}
if
(
o1
instanceof
long
[]
&&
o2
instanceof
long
[])
{
return
Arrays
.
equals
((
long
[])
o1
,
(
long
[])
o2
);
}
if
(
o1
instanceof
short
[]
&&
o2
instanceof
short
[])
{
return
Arrays
.
equals
((
short
[])
o1
,
(
short
[])
o2
);
}
return
arrayEquals
(
o1
,
o2
);
}
return
false
;
}
/**
* Compare the given arrays with {@code Arrays.equals}, performing an equality
* check based on the array elements rather than the array reference.
* @param o1 first array to compare
* @param o2 second array to compare
* @return whether the given objects are equal
* @see #nullSafeEquals(Object, Object)
* @see java.util.Arrays#equals
*/
private
static
boolean
arrayEquals
(
Object
o1
,
Object
o2
)
{
if
(
o1
instanceof
Object
[]
&&
o2
instanceof
Object
[])
{
return
Arrays
.
equals
((
Object
[])
o1
,
(
Object
[])
o2
);
}
if
(
o1
instanceof
boolean
[]
&&
o2
instanceof
boolean
[])
{
return
Arrays
.
equals
((
boolean
[])
o1
,
(
boolean
[])
o2
);
}
if
(
o1
instanceof
byte
[]
&&
o2
instanceof
byte
[])
{
return
Arrays
.
equals
((
byte
[])
o1
,
(
byte
[])
o2
);
}
if
(
o1
instanceof
char
[]
&&
o2
instanceof
char
[])
{
return
Arrays
.
equals
((
char
[])
o1
,
(
char
[])
o2
);
}
if
(
o1
instanceof
double
[]
&&
o2
instanceof
double
[])
{
return
Arrays
.
equals
((
double
[])
o1
,
(
double
[])
o2
);
}
if
(
o1
instanceof
float
[]
&&
o2
instanceof
float
[])
{
return
Arrays
.
equals
((
float
[])
o1
,
(
float
[])
o2
);
}
if
(
o1
instanceof
int
[]
&&
o2
instanceof
int
[])
{
return
Arrays
.
equals
((
int
[])
o1
,
(
int
[])
o2
);
}
if
(
o1
instanceof
long
[]
&&
o2
instanceof
long
[])
{
return
Arrays
.
equals
((
long
[])
o1
,
(
long
[])
o2
);
}
if
(
o1
instanceof
short
[]
&&
o2
instanceof
short
[])
{
return
Arrays
.
equals
((
short
[])
o1
,
(
short
[])
o2
);
}
return
false
;
}
...
...
@@ -335,6 +349,7 @@ public abstract class ObjectUtils {
* this method will delegate to any of the {@code nullSafeHashCode}
* methods for arrays in this class. If the object is {@code null},
* this method returns 0.
* @see Object#hashCode()
* @see #nullSafeHashCode(Object[])
* @see #nullSafeHashCode(boolean[])
* @see #nullSafeHashCode(byte[])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录