aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo/properties/NumberProperty.java
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2008-02-10 13:01:07 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2008-02-10 13:01:07 +0000
commit0a64e43af52c6d8af108ba97c719817ae82a710f (patch)
treef7e08728c6c2f5ba45c5ff2dacd41dd5fe59e99c /src/java/org/apache/fop/fo/properties/NumberProperty.java
parent2d84b6d1ed7b09a95cad0305e8377f397e455f8f (diff)
downloadxmlgraphics-fop-0a64e43af52c6d8af108ba97c719817ae82a710f.tar.gz
xmlgraphics-fop-0a64e43af52c6d8af108ba97c719817ae82a710f.zip
Tweak: wrap numeric values internally in Integers or Longs if possible, Doubles only if necessary.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@620277 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo/properties/NumberProperty.java')
-rw-r--r--src/java/org/apache/fop/fo/properties/NumberProperty.java44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/java/org/apache/fop/fo/properties/NumberProperty.java b/src/java/org/apache/fop/fo/properties/NumberProperty.java
index 2dd65e1ce..087429dba 100644
--- a/src/java/org/apache/fop/fo/properties/NumberProperty.java
+++ b/src/java/org/apache/fop/fo/properties/NumberProperty.java
@@ -61,7 +61,7 @@ public final class NumberProperty extends Property implements Numeric {
}
Number val = p.getNumber();
if (val != null) {
- return new NumberProperty(val);
+ return getInstance(val.doubleValue());
}
return convertPropertyDatatype(p, propertyList, fo);
}
@@ -74,42 +74,56 @@ public final class NumberProperty extends Property implements Numeric {
private final Number number;
/**
- * Constructor for Number input
- * @param num Number object value for property
- */
- private NumberProperty(Number num) {
- this.number = num;
- }
-
- /**
* Constructor for double input
* @param num double numeric value for property
*/
- protected NumberProperty(double num) {
- this.number = new Double(num);
+ private NumberProperty(double num) {
+ //Store the number as an int or a long,
+ //if possible
+ if ((num >= 0 && num == Math.floor(num))
+ || num == Math.ceil(num)) {
+ if (num < Integer.MAX_VALUE) {
+ this.number = new Integer((int)num);
+ } else {
+ this.number = new Long((long)num);
+ }
+ } else {
+ this.number = new Double(num);
+ }
}
/**
* Constructor for integer input
* @param num integer numeric value for property
*/
- protected NumberProperty(int num) {
+ private NumberProperty(int num) {
this.number = new Integer(num);
}
/**
* Returns the canonical NumberProperty instance
* corresponding to the given Number
- * @param num the base Number
+ * @param num the base Double
* @return the canonical NumberProperty
*/
- public static NumberProperty getInstance(Number num) {
+ public static NumberProperty getInstance(Double num) {
return (NumberProperty)cache.fetch(
- new NumberProperty(num));
+ new NumberProperty(num.doubleValue()));
}
/**
* Returns the canonical NumberProperty instance
+ * corresponding to the given Integer
+ * @param num the base Integer
+ * @return the canonical NumberProperty
+ */
+ public static NumberProperty getInstance(Integer num) {
+ return (NumberProperty)cache.fetch(
+ new NumberProperty(num.intValue()));
+ }
+
+ /**
+ * Returns the canonical NumberProperty instance
* corresponding to the given double
* @param num the base double value
* @return the canonical NumberProperty