Skip to content

Commit 5dd5975

Browse files
committed
Refactor getPropertyAsFloat and getPropertyAsInteger
DEVSIX-1381
1 parent 5e52d4d commit 5dd5975

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.itextpdf.io.util;
2+
3+
4+
/**
5+
* This file is a helper class for internal usage only.
6+
* Be aware that it's API and functionality may be changed in future.
7+
*/
8+
public class NumberUtil {
9+
10+
private NumberUtil() {
11+
}
12+
13+
public static Float asFloat(Object obj) {
14+
Number value = (Number)obj;
15+
return value != null ? value.floatValue() : null;
16+
}
17+
18+
public static Integer asInteger(Object obj) {
19+
Number value = (Number)obj;
20+
return value != null ? value.intValue() : null;
21+
}
22+
23+
}

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.layout.renderer;
4545

4646
import com.itextpdf.io.LogMessageConstant;
47+
import com.itextpdf.io.util.NumberUtil;
4748
import com.itextpdf.kernel.color.Color;
4849
import com.itextpdf.kernel.font.PdfFont;
4950
import com.itextpdf.kernel.geom.AffineTransform;
@@ -363,8 +364,7 @@ public TransparentColor getPropertyAsTransparentColor(int property) {
363364
* @return a {@link Float}
364365
*/
365366
public Float getPropertyAsFloat(int property) {
366-
Number value = this.<Number>getProperty(property);
367-
return value != null ? value.floatValue() : null;
367+
return NumberUtil.asFloat(this.<Object>getProperty(property));
368368
}
369369

370370
/**
@@ -375,8 +375,7 @@ public Float getPropertyAsFloat(int property) {
375375
* @return a {@link Float}
376376
*/
377377
public Float getPropertyAsFloat(int property, Float defaultValue) {
378-
Number value = this.<Number>getProperty(property, defaultValue);
379-
return value != null ? value.floatValue() : null;
378+
return NumberUtil.asFloat(this.<Object>getProperty(property, defaultValue));
380379
}
381380

382381
/**
@@ -396,8 +395,7 @@ public Boolean getPropertyAsBoolean(int property) {
396395
* @return a {@link Integer}
397396
*/
398397
public Integer getPropertyAsInteger(int property) {
399-
Number value = getProperty(property);
400-
return value != null ? value.intValue() : null;
398+
return NumberUtil.asInteger(this.<Object>getProperty(property));
401399
}
402400

403401
/**

0 commit comments

Comments
 (0)