Author: adelmelle
Date: Sun Feb 10 05:01:07 2008
New Revision: 620277

URL: http://svn.apache.org/viewvc?rev=620277&view=rev
Log:
Tweak: wrap numeric values internally in Integers or Longs if possible, Doubles 
only if necessary.

Modified:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java?rev=620277&r1=620276&r2=620277&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java 
Sun Feb 10 05:01:07 2008
@@ -61,7 +61,7 @@
             }
             Number val = p.getNumber();
             if (val != null) {
-                return new NumberProperty(val);
+                return getInstance(val.doubleValue());
             }
             return convertPropertyDatatype(p, propertyList, fo);
         }
@@ -74,40 +74,54 @@
     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



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to