1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .expression .spel .support ;
18
18
19
19
import java .math .BigDecimal ;
20
+ import java .math .BigInteger ;
20
21
21
22
import org .springframework .expression .TypeComparator ;
22
23
import org .springframework .expression .spel .SpelEvaluationException ;
@@ -75,19 +76,36 @@ else if (leftNumber instanceof Double || rightNumber instanceof Double) {
75
76
else if (leftNumber instanceof Float || rightNumber instanceof Float ) {
76
77
return Float .compare (leftNumber .floatValue (), rightNumber .floatValue ());
77
78
}
79
+ else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger ) {
80
+ BigInteger leftBigInteger = NumberUtils .convertNumberToTargetClass (leftNumber , BigInteger .class );
81
+ BigInteger rightBigInteger = NumberUtils .convertNumberToTargetClass (rightNumber , BigInteger .class );
82
+ return leftBigInteger .compareTo (rightBigInteger );
83
+ }
78
84
else if (leftNumber instanceof Long || rightNumber instanceof Long ) {
79
85
// Don't call Long.compare here - only available on JDK 1.7+
80
86
return compare (leftNumber .longValue (), rightNumber .longValue ());
81
87
}
82
- else {
88
+ else if ( leftNumber instanceof Integer || rightNumber instanceof Integer ) {
83
89
// Don't call Integer.compare here - only available on JDK 1.7+
84
90
return compare (leftNumber .intValue (), rightNumber .intValue ());
85
91
}
92
+ else if (leftNumber instanceof Short || rightNumber instanceof Short ) {
93
+ // Don't call Short.compare here - only available on JDK 1.7+
94
+ return compare (leftNumber .shortValue (), rightNumber .shortValue ());
95
+ }
96
+ else if (leftNumber instanceof Byte || rightNumber instanceof Byte ) {
97
+ // Don't call Short.compare here - only available on JDK 1.7+
98
+ return compare (leftNumber .byteValue (), rightNumber .byteValue ());
99
+ }
100
+ else {
101
+ // Unknown Number subtypes -> best guess is double multiplication
102
+ return Double .compare (leftNumber .doubleValue (), rightNumber .doubleValue ());
103
+ }
86
104
}
87
105
88
106
try {
89
107
if (left instanceof Comparable ) {
90
- return ((Comparable ) left ).compareTo (right );
108
+ return ((Comparable < Object > ) left ).compareTo (right );
91
109
}
92
110
}
93
111
catch (ClassCastException ex ) {
@@ -98,12 +116,20 @@ else if (leftNumber instanceof Long || rightNumber instanceof Long) {
98
116
}
99
117
100
118
101
- private static int compare (int x , int y ) {
119
+ private static int compare (long x , long y ) {
102
120
return (x < y ? -1 : (x > y ? 1 : 0 ));
103
121
}
104
122
105
- private static int compare (long x , long y ) {
123
+ private static int compare (int x , int y ) {
106
124
return (x < y ? -1 : (x > y ? 1 : 0 ));
107
125
}
108
126
127
+ private static int compare (short x , short y ) {
128
+ return x - y ;
129
+ }
130
+
131
+ private static int compare (byte x , byte y ) {
132
+ return x - y ;
133
+ }
134
+
109
135
}
0 commit comments