17
17
package org .springframework .boot .configurationprocessor .json ;
18
18
19
19
class JSON {
20
- /**
21
- * Returns the input if it is a JSON-permissible value; throws otherwise.
22
- */
20
+
23
21
static double checkDouble (double d ) throws JSONException {
24
22
if (Double .isInfinite (d ) || Double .isNaN (d )) {
25
23
throw new JSONException ("Forbidden numeric value: " + d );
@@ -31,12 +29,12 @@ static Boolean toBoolean(Object value) {
31
29
if (value instanceof Boolean ) {
32
30
return (Boolean ) value ;
33
31
}
34
- else if (value instanceof String ) {
32
+ if (value instanceof String ) {
35
33
String stringValue = (String ) value ;
36
34
if ("true" .equalsIgnoreCase (stringValue )) {
37
35
return true ;
38
36
}
39
- else if ("false" .equalsIgnoreCase (stringValue )) {
37
+ if ("false" .equalsIgnoreCase (stringValue )) {
40
38
return false ;
41
39
}
42
40
}
@@ -47,10 +45,10 @@ static Double toDouble(Object value) {
47
45
if (value instanceof Double ) {
48
46
return (Double ) value ;
49
47
}
50
- else if (value instanceof Number ) {
48
+ if (value instanceof Number ) {
51
49
return ((Number ) value ).doubleValue ();
52
50
}
53
- else if (value instanceof String ) {
51
+ if (value instanceof String ) {
54
52
try {
55
53
return Double .valueOf ((String ) value );
56
54
}
@@ -64,10 +62,10 @@ static Integer toInteger(Object value) {
64
62
if (value instanceof Integer ) {
65
63
return (Integer ) value ;
66
64
}
67
- else if (value instanceof Number ) {
65
+ if (value instanceof Number ) {
68
66
return ((Number ) value ).intValue ();
69
67
}
70
- else if (value instanceof String ) {
68
+ if (value instanceof String ) {
71
69
try {
72
70
return (int ) Double .parseDouble ((String ) value );
73
71
}
@@ -81,10 +79,10 @@ static Long toLong(Object value) {
81
79
if (value instanceof Long ) {
82
80
return (Long ) value ;
83
81
}
84
- else if (value instanceof Number ) {
82
+ if (value instanceof Number ) {
85
83
return ((Number ) value ).longValue ();
86
84
}
87
- else if (value instanceof String ) {
85
+ if (value instanceof String ) {
88
86
try {
89
87
return (long ) Double .parseDouble ((String ) value );
90
88
}
@@ -98,7 +96,7 @@ static String toString(Object value) {
98
96
if (value instanceof String ) {
99
97
return (String ) value ;
100
98
}
101
- else if (value != null ) {
99
+ if (value != null ) {
102
100
return String .valueOf (value );
103
101
}
104
102
return null ;
@@ -109,22 +107,19 @@ public static JSONException typeMismatch(Object indexOrName, Object actual,
109
107
if (actual == null ) {
110
108
throw new JSONException ("Value at " + indexOrName + " is null." );
111
109
}
112
- else {
113
- throw new JSONException ("Value " + actual + " at " + indexOrName
114
- + " of type " + actual .getClass ().getName ()
115
- + " cannot be converted to " + requiredType );
116
- }
110
+ throw new JSONException ("Value " + actual + " at " + indexOrName + " of type "
111
+ + actual .getClass ().getName () + " cannot be converted to "
112
+ + requiredType );
117
113
}
118
114
119
115
public static JSONException typeMismatch (Object actual , String requiredType )
120
116
throws JSONException {
121
117
if (actual == null ) {
122
118
throw new JSONException ("Value is null." );
123
119
}
124
- else {
125
- throw new JSONException ("Value " + actual
126
- + " of type " + actual .getClass ().getName ()
127
- + " cannot be converted to " + requiredType );
128
- }
120
+ throw new JSONException (
121
+ "Value " + actual + " of type " + actual .getClass ().getName ()
122
+ + " cannot be converted to " + requiredType );
129
123
}
124
+
130
125
}
0 commit comments