Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
a4195843
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
a4195843
编写于
11月 21, 2013
作者:
P
Phillip Webb
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #406 from aclement/fix-SPR-9194
* fix-SPR-9194: Change SpEL equality operators to use .equals
上级
7c3cdf82
2a05e6af
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
69 addition
and
52 deletion
+69
-52
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java
...in/java/org/springframework/expression/spel/ast/OpEQ.java
+2
-23
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java
...in/java/org/springframework/expression/spel/ast/OpGT.java
+4
-0
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java
...in/java/org/springframework/expression/spel/ast/OpLT.java
+2
-1
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java
...in/java/org/springframework/expression/spel/ast/OpNE.java
+2
-27
spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
...ava/org/springframework/expression/spel/ast/Operator.java
+30
-1
spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java
...a/org/springframework/expression/spel/SpelReproTests.java
+29
-0
未找到文件。
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java
浏览文件 @
a4195843
...
...
@@ -28,6 +28,7 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public
class
OpEQ
extends
Operator
{
public
OpEQ
(
int
pos
,
SpelNodeImpl
...
operands
)
{
super
(
"=="
,
pos
,
operands
);
}
...
...
@@ -38,29 +39,7 @@ public class OpEQ extends Operator {
throws
EvaluationException
{
Object
left
=
getLeftOperand
().
getValueInternal
(
state
).
getValue
();
Object
right
=
getRightOperand
().
getValueInternal
(
state
).
getValue
();
if
(
left
instanceof
Number
&&
right
instanceof
Number
)
{
Number
op1
=
(
Number
)
left
;
Number
op2
=
(
Number
)
right
;
if
(
op1
instanceof
Double
||
op2
instanceof
Double
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
doubleValue
()
==
op2
.
doubleValue
());
}
else
if
(
op1
instanceof
Float
||
op2
instanceof
Float
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
floatValue
()
==
op2
.
floatValue
());
}
else
if
(
op1
instanceof
Long
||
op2
instanceof
Long
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
longValue
()
==
op2
.
longValue
());
}
else
{
return
BooleanTypedValue
.
forValue
(
op1
.
intValue
()
==
op2
.
intValue
());
}
}
if
(
left
!=
null
&&
(
left
instanceof
Comparable
))
{
return
BooleanTypedValue
.
forValue
(
state
.
getTypeComparator
().
compare
(
left
,
right
)
==
0
);
}
else
{
return
BooleanTypedValue
.
forValue
(
left
==
right
);
}
return
BooleanTypedValue
.
forValue
(
equalityCheck
(
state
,
left
,
right
));
}
}
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java
浏览文件 @
a4195843
...
...
@@ -28,6 +28,7 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public
class
OpGT
extends
Operator
{
public
OpGT
(
int
pos
,
SpelNodeImpl
...
operands
)
{
super
(
">"
,
pos
,
operands
);
}
...
...
@@ -43,6 +44,9 @@ public class OpGT extends Operator {
if
(
leftNumber
instanceof
Double
||
rightNumber
instanceof
Double
)
{
return
BooleanTypedValue
.
forValue
(
leftNumber
.
doubleValue
()
>
rightNumber
.
doubleValue
());
}
else
if
(
leftNumber
instanceof
Float
||
rightNumber
instanceof
Float
)
{
return
BooleanTypedValue
.
forValue
(
leftNumber
.
floatValue
()
>
rightNumber
.
floatValue
());
}
else
if
(
leftNumber
instanceof
Long
||
rightNumber
instanceof
Long
)
{
return
BooleanTypedValue
.
forValue
(
leftNumber
.
longValue
()
>
rightNumber
.
longValue
());
}
...
...
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java
浏览文件 @
a4195843
...
...
@@ -28,6 +28,7 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public
class
OpLT
extends
Operator
{
public
OpLT
(
int
pos
,
SpelNodeImpl
...
operands
)
{
super
(
"<"
,
pos
,
operands
);
}
...
...
@@ -38,7 +39,7 @@ public class OpLT extends Operator {
throws
EvaluationException
{
Object
left
=
getLeftOperand
().
getValueInternal
(
state
).
getValue
();
Object
right
=
getRightOperand
().
getValueInternal
(
state
).
getValue
();
// TODO could leave all of these to the comparator - just seems quicker to do some here
if
(
left
instanceof
Number
&&
right
instanceof
Number
)
{
Number
leftNumber
=
(
Number
)
left
;
Number
rightNumber
=
(
Number
)
right
;
...
...
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java
浏览文件 @
a4195843
...
...
@@ -28,6 +28,7 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public
class
OpNE
extends
Operator
{
public
OpNE
(
int
pos
,
SpelNodeImpl
...
operands
)
{
super
(
"!="
,
pos
,
operands
);
}
...
...
@@ -35,35 +36,9 @@ public class OpNE extends Operator {
@Override
public
BooleanTypedValue
getValueInternal
(
ExpressionState
state
)
throws
EvaluationException
{
Object
left
=
getLeftOperand
().
getValueInternal
(
state
).
getValue
();
Object
right
=
getRightOperand
().
getValueInternal
(
state
).
getValue
();
if
(
left
instanceof
Number
&&
right
instanceof
Number
)
{
Number
op1
=
(
Number
)
left
;
Number
op2
=
(
Number
)
right
;
if
(
op1
instanceof
Double
||
op2
instanceof
Double
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
doubleValue
()
!=
op2
.
doubleValue
());
}
if
(
op1
instanceof
Float
||
op2
instanceof
Float
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
floatValue
()
!=
op2
.
floatValue
());
}
if
(
op1
instanceof
Long
||
op2
instanceof
Long
)
{
return
BooleanTypedValue
.
forValue
(
op1
.
longValue
()
!=
op2
.
longValue
());
}
return
BooleanTypedValue
.
forValue
(
op1
.
intValue
()
!=
op2
.
intValue
());
}
if
(
left
!=
null
&&
(
left
instanceof
Comparable
))
{
return
BooleanTypedValue
.
forValue
(
state
.
getTypeComparator
().
compare
(
left
,
right
)
!=
0
);
}
return
BooleanTypedValue
.
forValue
(
left
!=
right
);
return
BooleanTypedValue
.
forValue
(!
equalityCheck
(
state
,
left
,
right
));
}
}
spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
浏览文件 @
a4195843
...
...
@@ -16,6 +16,8 @@
package
org.springframework.expression.spel.ast
;
import
org.springframework.expression.spel.ExpressionState
;
/**
* Common supertype for operators that operate on either one or two operands. In the case
* of multiply or divide there would be two operands, but for unary plus or minus, there
...
...
@@ -26,7 +28,7 @@ package org.springframework.expression.spel.ast;
*/
public
abstract
class
Operator
extends
SpelNodeImpl
{
String
operatorName
;
private
final
String
operatorName
;
public
Operator
(
String
payload
,
int
pos
,
SpelNodeImpl
...
operands
)
{
...
...
@@ -63,4 +65,31 @@ public abstract class Operator extends SpelNodeImpl {
return
sb
.
toString
();
}
protected
boolean
equalityCheck
(
ExpressionState
state
,
Object
left
,
Object
right
)
{
if
(
left
instanceof
Number
&&
right
instanceof
Number
)
{
Number
op1
=
(
Number
)
left
;
Number
op2
=
(
Number
)
right
;
if
(
op1
instanceof
Double
||
op2
instanceof
Double
)
{
return
(
op1
.
doubleValue
()
==
op2
.
doubleValue
());
}
if
(
op1
instanceof
Float
||
op2
instanceof
Float
)
{
return
(
op1
.
floatValue
()
==
op2
.
floatValue
());
}
if
(
op1
instanceof
Long
||
op2
instanceof
Long
)
{
return
(
op1
.
longValue
()
==
op2
.
longValue
());
}
return
(
op1
.
intValue
()
==
op2
.
intValue
());
}
if
(
left
!=
null
&&
(
left
instanceof
Comparable
))
{
return
(
state
.
getTypeComparator
().
compare
(
left
,
right
)
==
0
);
}
return
(
left
==
null
?
right
==
null
:
left
.
equals
(
right
));
}
}
spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java
浏览文件 @
a4195843
...
...
@@ -1839,6 +1839,19 @@ public class SpelReproTests extends ExpressionTestCase {
equalTo
((
Object
)
"name"
));
}
@Test
public
void
testOperatorEq_SPR9194
()
{
TestClass2
one
=
new
TestClass2
(
"abc"
);
TestClass2
two
=
new
TestClass2
(
"abc"
);
Map
<
String
,
TestClass2
>
map
=
new
HashMap
<
String
,
TestClass2
>();
map
.
put
(
"one"
,
one
);
map
.
put
(
"two"
,
two
);
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
Expression
classNameExpression
=
parser
.
parseExpression
(
"['one'] == ['two']"
);
assertTrue
(
classNameExpression
.
getValue
(
map
,
Boolean
.
class
));
}
private
static
enum
ABC
{
A
,
B
,
C
}
...
...
@@ -1922,4 +1935,20 @@ public class SpelReproTests extends ExpressionTestCase {
}
}
static
class
TestClass2
{
// SPR-9194
String
string
;
public
TestClass2
(
String
string
)
{
this
.
string
=
string
;
}
public
boolean
equals
(
Object
o
)
{
if
(
o
instanceof
TestClass2
)
{
return
string
.
equals
(((
TestClass2
)
o
).
string
);
}
return
false
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录