Skip to content

Commit e30f97b

Browse files
committed
optimization some method
1 parent 5ecbc05 commit e30f97b

File tree

1 file changed

+12
-60
lines changed

1 file changed

+12
-60
lines changed

src/main/java/org/apache/ibatis/parsing/XNode.java

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -142,59 +142,39 @@ public Boolean getBooleanBody() {
142142
}
143143

144144
public Boolean getBooleanBody(Boolean def) {
145-
if (body == null) {
146-
return def;
147-
} else {
148-
return Boolean.valueOf(body);
149-
}
145+
return body == null ? def : Boolean.valueOf(body);
150146
}
151147

152148
public Integer getIntBody() {
153149
return getIntBody(null);
154150
}
155151

156152
public Integer getIntBody(Integer def) {
157-
if (body == null) {
158-
return def;
159-
} else {
160-
return Integer.parseInt(body);
161-
}
153+
return body == null ? def : Integer.valueOf(body);
162154
}
163155

164156
public Long getLongBody() {
165157
return getLongBody(null);
166158
}
167159

168160
public Long getLongBody(Long def) {
169-
if (body == null) {
170-
return def;
171-
} else {
172-
return Long.parseLong(body);
173-
}
161+
return body == null ? def : Long.parseLong(body);
174162
}
175163

176164
public Double getDoubleBody() {
177165
return getDoubleBody(null);
178166
}
179167

180168
public Double getDoubleBody(Double def) {
181-
if (body == null) {
182-
return def;
183-
} else {
184-
return Double.parseDouble(body);
185-
}
169+
return body == null ? def : Double.parseDouble(body);
186170
}
187171

188172
public Float getFloatBody() {
189173
return getFloatBody(null);
190174
}
191175

192176
public Float getFloatBody(Float def) {
193-
if (body == null) {
194-
return def;
195-
} else {
196-
return Float.parseFloat(body);
197-
}
177+
return body == null ? def : Float.parseFloat(body);
198178
}
199179

200180
public <T extends Enum<T>> T getEnumAttribute(Class<T> enumType, String name) {
@@ -203,11 +183,7 @@ public <T extends Enum<T>> T getEnumAttribute(Class<T> enumType, String name) {
203183

204184
public <T extends Enum<T>> T getEnumAttribute(Class<T> enumType, String name, T def) {
205185
String value = getStringAttribute(name);
206-
if (value == null) {
207-
return def;
208-
} else {
209-
return Enum.valueOf(enumType, value);
210-
}
186+
return value == null ? def : Enum.valueOf(enumType,value);
211187
}
212188

213189
/**
@@ -234,11 +210,7 @@ public String getStringAttribute(String name) {
234210

235211
public String getStringAttribute(String name, String def) {
236212
String value = attributes.getProperty(name);
237-
if (value == null) {
238-
return def;
239-
} else {
240-
return value;
241-
}
213+
return value == null ? def : value;
242214
}
243215

244216
public Boolean getBooleanAttribute(String name) {
@@ -247,11 +219,7 @@ public Boolean getBooleanAttribute(String name) {
247219

248220
public Boolean getBooleanAttribute(String name, Boolean def) {
249221
String value = attributes.getProperty(name);
250-
if (value == null) {
251-
return def;
252-
} else {
253-
return Boolean.valueOf(value);
254-
}
222+
return value == null ? def : Boolean.valueOf(value);
255223
}
256224

257225
public Integer getIntAttribute(String name) {
@@ -260,11 +228,7 @@ public Integer getIntAttribute(String name) {
260228

261229
public Integer getIntAttribute(String name, Integer def) {
262230
String value = attributes.getProperty(name);
263-
if (value == null) {
264-
return def;
265-
} else {
266-
return Integer.parseInt(value);
267-
}
231+
return value == null ? def : Integer.parseInt(value);
268232
}
269233

270234
public Long getLongAttribute(String name) {
@@ -273,11 +237,7 @@ public Long getLongAttribute(String name) {
273237

274238
public Long getLongAttribute(String name, Long def) {
275239
String value = attributes.getProperty(name);
276-
if (value == null) {
277-
return def;
278-
} else {
279-
return Long.parseLong(value);
280-
}
240+
return value == null ? def : Long.parseLong(value);
281241
}
282242

283243
public Double getDoubleAttribute(String name) {
@@ -286,11 +246,7 @@ public Double getDoubleAttribute(String name) {
286246

287247
public Double getDoubleAttribute(String name, Double def) {
288248
String value = attributes.getProperty(name);
289-
if (value == null) {
290-
return def;
291-
} else {
292-
return Double.parseDouble(value);
293-
}
249+
return value == null ? def : Double.parseDouble(value);
294250
}
295251

296252
public Float getFloatAttribute(String name) {
@@ -299,11 +255,7 @@ public Float getFloatAttribute(String name) {
299255

300256
public Float getFloatAttribute(String name, Float def) {
301257
String value = attributes.getProperty(name);
302-
if (value == null) {
303-
return def;
304-
} else {
305-
return Float.parseFloat(value);
306-
}
258+
return value == null ? def : Float.parseFloat(value);
307259
}
308260

309261
public List<XNode> getChildren() {

0 commit comments

Comments
 (0)