2002/css-validator/org/w3c/css/values CssFrequency.java,1.7,1.8 CssLength.java,1.8,1.9 CssNumber.java,1.11,1.12 CssPercentage.java,1.9,1.10 CssTime.java,1.7,1.8 CssValueList.java,1.1,1.2

Update of /sources/public/2002/css-validator/org/w3c/css/values
In directory hutz:/tmp/cvs-serv25830/w3c/css/values

Modified Files:
	CssFrequency.java CssLength.java CssNumber.java 
	CssPercentage.java CssTime.java CssValueList.java 
Log Message:
various things: Use of BigIntegers to avoid limits, background-* are now avoiding multiplication of checks and properties in CssXStyles impls, various updates for other properties, use of a string reader for string input, added the possibility of not following links, prepared for aggregation of all uris parsed

Index: CssValueList.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssValueList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssValueList.java	5 Jan 2010 13:50:01 -0000	1.1
+++ CssValueList.java	9 Feb 2012 17:36:33 -0000	1.2
@@ -70,10 +70,15 @@
      */
     public String toString() {
         StringBuilder sb = new StringBuilder();
+        boolean first = true;
         for (CssValue aCssValue: value) {
-            sb.append(aCssValue.toString()).append(" ");
+            if (!first) {
+                sb.append(' ');
+            } else {
+                first = false;
+            }
+            sb.append(aCssValue.toString());
         }
-        sb.setLength(sb.length()-1);
         return sb.toString();
     }
 

Index: CssTime.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssTime.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- CssTime.java	6 Jan 2010 09:27:44 -0000	1.7
+++ CssTime.java	9 Feb 2012 17:36:33 -0000	1.8
@@ -8,20 +8,21 @@
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.util.Util;
+
+import java.math.BigDecimal;
 
 /**
  * <H3>Time</H3>
- *
+ * <p/>
  * <P>Time units are used with aural cascading style sheets.
- *
+ * <p/>
  * <P>These following are legal time units:
- *
+ * <p/>
  * <UL>
  * <LI>ms: milliseconds
  * <LI>s: seconds
  * </UL>
- *
+ * <p/>
  * <p>Time values may not be negative.
  *
  * @version $Revision$
@@ -29,120 +30,120 @@
 public class CssTime extends CssValue {
 
     public static final int type = CssTypes.CSS_TIME;
-    
+
     public final int getType() {
-	return type;
+        return type;
     }
 
-  /**
-   * Create a new CssTime.
-   */
-  public CssTime() {
-    value = defaultValue;
-  }
+    /**
+     * Create a new CssTime.
+     */
+    public CssTime() {
+        value = defaultValue;
+    }
 
-  /**
-   * Create a new CssTime with a Float object.
-   *
-   * @param value the Float object
-   */
-  public CssTime(Float value) {
-    this.value = value;
-  }
+    /**
+     * Create a new CssTime with a Float object.
+     *
+     * @param value the Float object
+     */
+    public CssTime(Float value) {
+        this.value = new BigDecimal(value);
+    }
 
-  /**
-   * Set the value of this time.
-   *
-   * @param s     the string representation of the time.
-   * @param ac For errors and warnings reports.
-   * @exception InvalidParamException The unit is incorrect
-   */
-  public void set(String s, ApplContext ac) throws InvalidParamException {
-    s = s.toLowerCase();
-    int length = s.length();
-    String unit;
+    /**
+     * Set the value of this time.
+     *
+     * @param ts  the string representation of the time.
+     * @param ac For errors and warnings reports.
+     * @throws InvalidParamException The unit is incorrect
+     */
+    public void set(String ts, ApplContext ac) throws InvalidParamException {
+        String s = ts.toLowerCase();
+        int length = s.length();
+        String unit;
 
-    if (s.charAt(length-2) == 'm') {
-      unit = s.substring(length-2, length);
-      this.value = new Float(s.substring(0, length-2));
-    } else {
-      unit = s.substring(length-1, length);
-      this.value = Float.valueOf(s.substring(0, length-1));
-    }
+        if (s.charAt(length - 2) == 'm') {
+            unit = s.substring(length - 2, length);
+            this.value = new BigDecimal(s.substring(0, length - 2));
+        } else {
+            unit = s.substring(length - 1, length);
+            this.value = new BigDecimal(s.substring(0, length - 1));
+        }
 
-    if (this.value.floatValue() < 0) {
-      throw new InvalidParamException("negative-value",
-				      this.value.toString(), ac);
-    }
+        if (this.value.signum() == -1) {
+            throw new InvalidParamException("negative-value",
+                    this.value.toString(), ac);
+        }
 
-    this.unit = 1; // there is no unit by default
+        this.unit = 1; // there is no unit by default
 
-    if (this.value.floatValue() != 0) {
-      int hash = unit.hashCode();
-      int i = 0;
-      while (i<units.length) {
-	if (hash == hash_units[i]) {
-	  this.unit = i;
-	  return;
-	}
-	i++;
-      }
-    } else {
-      return;
-    }
+        if (!BigDecimal.ZERO.equals(this.value)) {
+            int hash = unit.hashCode();
+            int i = 0;
+            while (i < units.length) {
+                if (hash == hash_units[i]) {
+                    this.unit = i;
+                    return;
+                }
+                i++;
+            }
+        } else {
+            return;
+        }
 
-    throw new InvalidParamException("unit", unit, ac);
-  }
+        throw new InvalidParamException("unit", unit, ac);
+    }
 
-  /**
-   * Returns the current value
-   *  Float
-   */
-  public Object get() {
-    if (unit == 1) {
-      return new Float(value.floatValue() * 1000);
+    /**
+     * Returns the current value
+     * Float
+     * TODO move to a BigDecimal
+     */
+    public Object get() {
+        if (unit == 1) {
+            return new Float(value.floatValue() * 1000);
+        }
+        return value;
     }
-    return value;
-  }
 
-  /**
-   * Returns the current value
-   */
-  public String getUnit() {
-    return units[unit];
-  }
+    /**
+     * Returns the current value
+     */
+    public String getUnit() {
+        return units[unit];
+    }
 
-  /**
-   * Returns a string representation of the object.
-   */
-  public String toString() {
-      if (value.floatValue() != 0) {
-	  return Util.displayFloat(value) + getUnit();
-      } else {
-	  return Util.displayFloat(value);
-      }
-  }
+    /**
+     * Returns a string representation of the object.
+     */
+    public String toString() {
+        if (BigDecimal.ZERO.equals(value)) {
+            return value.toPlainString();
+        }
+        return value.toPlainString() + getUnit();
+    }
 
-  /**
-   * Compares two values for equality.
-   *
-   * @param value The other value.
-   */
-  public boolean equals(Object value) {
-    return (value instanceof CssTime && this.value.equals(((CssTime) value).value) &&
-	     unit == ((CssTime) value).unit);
-  }
+    /**
+     * Compares two values for equality.
+     *
+     * @param value The other value.
+     */
+    public boolean equals(Object value) {
+        return (value instanceof CssTime && this.value.equals(((CssTime) value).value) &&
+                unit == ((CssTime) value).unit);
+    }
 
-  private Float value;
-  private int unit;
-  private static String[] units = { "ms", "s" };
-  private static int[] hash_units;
-  private static Float defaultValue = new Float(0);
+    private BigDecimal value;
+    private int unit;
+    private static String[] units = {"ms", "s"};
+    private static int[] hash_units;
+    private static BigDecimal defaultValue = BigDecimal.ZERO;
 
-  static {
-    hash_units = new int[units.length];
-    for (int i=0; i<units.length; i++)
-      hash_units[i] = units[i].hashCode();
-  }
+    static {
+        hash_units = new int[units.length];
+        for (int i = 0; i < units.length; i++)
+            hash_units[i] = units[i].hashCode();
+    }
 }
 

Index: CssNumber.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssNumber.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- CssNumber.java	7 Oct 2011 09:33:19 -0000	1.11
+++ CssNumber.java	9 Feb 2012 17:36:33 -0000	1.12
@@ -1,16 +1,17 @@
-//
 // $Id$
 // From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
 //
-// (c) COPYRIGHT MIT and INRIA, 1997.
+// (c) COPYRIGHT MIT, ERCIM and Keio University, 2011
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.values;
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 
+import java.math.BigDecimal;
+
 /**
- * A CSS float number.
+ * A CSS number.
  *
  * @version $Revision$
  */
@@ -23,7 +24,7 @@
     }
 
     ApplContext ac;
-    Float value;
+    BigDecimal value;
     boolean isInt = false;
 
     /**
@@ -37,11 +38,11 @@
      */
     public CssNumber(ApplContext ac, float value) {
         this.ac = ac;
-        this.value = new Float(value);
+        this.value = new BigDecimal(value);
     }
 
     public CssNumber(float value) {
-        this.value = new Float(value);
+        this.value = new BigDecimal(value);
     }
 
     /**
@@ -51,42 +52,37 @@
      * @param ac For errors and warnings reports.
      */
     public void set(String s, ApplContext ac) {
+        value = new BigDecimal(s);
         try {
-            new Integer(s);
+            value.toBigIntegerExact();
             isInt = true;
-        } catch (NumberFormatException e) {
+        } catch (ArithmeticException e) {
             isInt = false;
-        } finally {
-            value = new Float(s);
         }
         this.ac = ac;
     }
 
     /**
      * Set the value explicitly
-     *
      */
     public void setIntValue(int v) {
         isInt = true;
-        value = new Float(v);
+        value = new BigDecimal(v);
+
     }
 
-     /**
+    /**
      * Set the value explicitly
-     *
      */
     public void setFloatValue(float v) {
         isInt = false;
-        value = v;
+        value = new BigDecimal(v);
     }
 
     /**
      * Returns the value
      */
     public Object get() {
-        if (isInt) {
-            return new Integer(value.intValue());
-        }
         return value;
     }
 
@@ -99,10 +95,14 @@
 
     public int getInt() throws InvalidParamException {
         if (isInt) {
-            return value.intValue();
-        } else {
-            throw new InvalidParamException("invalid-color", ac);
+            try {
+                return value.intValueExact();
+            } catch (ArithmeticException aex) {
+                throw new InvalidParamException("out-of-range", ac);
+            }
         }
+        // FIXME ???
+        throw new InvalidParamException("invalid-color", ac);
     }
 
     public boolean isInteger() {
@@ -110,18 +110,43 @@
     }
 
     /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isPositive() {
+        return (value.signum() >= 0);
+    }
+
+    /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isStrictlyPositive() {
+        return (value.signum() == 1);
+    }
+
+    /**
+     * Returns true is the value is zero
+     *
+     * @return a boolean
+     */
+    public boolean isZero() {
+        return BigDecimal.ZERO.equals(value);
+    }
+
+    /**
      * Returns a length.
      * Only zero can be a length.
      *
      * @throws InvalidParamException The value is not zero
      */
     public CssLength getLength() throws InvalidParamException {
-        float num = value.floatValue();
-        if (num == 0) {
+        if (value.equals(BigDecimal.ZERO)) {
             return new CssLength();
-        } else {
-            throw new InvalidParamException("zero", "length", ac);
         }
+        throw new InvalidParamException("zero", "length", ac);
     }
 
     /**
@@ -131,14 +156,12 @@
      * @throws InvalidParamException The value is not zero
      */
     public CssPercentage getPercentage() throws InvalidParamException {
-        float num = value.floatValue();
-        if (num == 0)
+        if (value.equals(BigDecimal.ZERO)) {
             return new CssPercentage();
-        else {
-            throw new InvalidParamException("zero",
-                    value.toString(),
-                    "percentage", ac);
         }
+        throw new InvalidParamException("zero",
+                value.toString(),
+                "percentage", ac);
     }
 
     /**
@@ -148,12 +171,11 @@
      * @throws InvalidParamException The value is not zero
      */
     public CssTime getTime() throws InvalidParamException {
-        float num = value.floatValue();
-        if (num == 0)
+        if (value.equals(BigDecimal.ZERO)) {
             return new CssTime();
-        else
-            throw new InvalidParamException("zero", value.toString(),
-                    "time", ac);
+        }
+        throw new InvalidParamException("zero", value.toString(),
+                "time", ac);
     }
 
     /**
@@ -163,12 +185,11 @@
      * @throws InvalidParamException The value is not zero
      */
     public CssAngle getAngle() throws InvalidParamException {
-        float num = value.floatValue();
-        if (num == 0)
+        if (value.equals(BigDecimal.ZERO)) {
             return new CssAngle();
-        else
-            throw new InvalidParamException("zero", value.toString(),
-                    "angle", ac);
+        }
+        throw new InvalidParamException("zero", value.toString(),
+                "angle", ac);
     }
 
     /**
@@ -178,23 +199,18 @@
      * @throws InvalidParamException The value is not zero
      */
     public CssFrequency getFrequency() throws InvalidParamException {
-        float num = value.floatValue();
-        if (num == 0) {
+        if (value.equals(BigDecimal.ZERO)) {
             return new CssFrequency();
-        } else {
-            throw new InvalidParamException("zero",
-                    value.toString(), "frequency", ac);
         }
+        throw new InvalidParamException("zero",
+                value.toString(), "frequency", ac);
     }
 
     /**
      * Returns a string representation of the object.
      */
     public String toString() {
-        if (isInt) {
-            return Integer.toString(value.intValue());
-        }
-        return value.toString();
+        return value.toPlainString();
     }
 
     /**

Index: CssFrequency.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssFrequency.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- CssFrequency.java	5 Jan 2010 13:50:00 -0000	1.7
+++ CssFrequency.java	9 Feb 2012 17:36:33 -0000	1.8
@@ -8,20 +8,21 @@
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.util.Util;
+
+import java.math.BigDecimal;
 
 /**
  * <H3> Frequencies</H3>
- *
+ * <p/>
  * <P>Frequency units are used with aural cascading style sheets.
- *
+ * <p/>
  * <p>There are two legal frequency units:
- *
+ * <p/>
  * <ul>
  * <li>Hz: Hertz
  * <li>kHz: kilo Hertz
  * </ul>
- *
+ * <p/>
  * <P> For example, 200Hz is a bass sound, and 6kHz is a treble sound.
  *
  * @version $Revision$
@@ -29,115 +30,117 @@
 public class CssFrequency extends CssValue {
 
     public static final int type = CssTypes.CSS_FREQUENCY;
-    
+
     public final int getType() {
-	return type;
+        return type;
     }
 
-  /**
-   * Create a new CssFrequency
-   */
-  public CssFrequency() {
-    value = defaultValue;
-  }
-
-  /**
-   * Create a new CssFrequency with a float number.
-   *
-   * @param value the float number.
-   */
-  public CssFrequency(Float value) {
-    this.value = value;
-  }
+    private BigDecimal value;
+    private int unit;
+    private static String[] units = {"Hz", "kHz"};
+    private static int[] hash_units;
+    private static BigDecimal defaultValue = BigDecimal.ZERO;
 
-  /**
-   * Set the value of this frequency.
-   *
-   * @param s     the string representation of the frequency.
-   * @param ac For errors and warnings reports.
-   * @exception InvalidParamException The unit is incorrect
-   */
-  public void set(String s, ApplContext ac) throws InvalidParamException {
-    s = s.toLowerCase();
-    int length = s.length();
-    String unit;
-    float v;
-    if (s.charAt(length-3) == 'k') {
-      unit = s.substring(length-3, length);
-      v = Float.parseFloat(s.substring(0, length - 3));
-    } else {
-      unit = s.substring(length-2, length);
-      v = Float.parseFloat(s.substring(0, length - 2));
+    static {
+        hash_units = new int[units.length];
+        for (int i = 0; i < units.length; i++)
+            hash_units[i] = units[i].toLowerCase().hashCode();
     }
-    int hash = unit.hashCode();
-
 
-    int i = 0;
-    while (i<units.length) {
-      if (hash == hash_units[i]) {
-	this.unit = i;
-	break;
-      }
-      i++;
+    /**
+     * Create a new CssFrequency
+     */
+    public CssFrequency() {
+        value = defaultValue;
     }
 
-    if (i == units.length) {
-      throw new InvalidParamException("unit", unit, ac);
+    /**
+     * Create a new CssFrequency with a float number.
+     *
+     * @param value the float number.
+     */
+    public CssFrequency(BigDecimal value) {
+        this.value = value;
     }
 
-    this.value = new Float(v);
+    /**
+     * Set the value of this frequency.
+     *
+     * @param s  the string representation of the frequency.
+     * @param ac For errors and warnings reports.
+     * @throws InvalidParamException The unit is incorrect
+     */
+    public void set(String s, ApplContext ac) throws InvalidParamException {
+        s = s.toLowerCase();
+        int length = s.length();
+        String unit;
+        BigDecimal v;
+        if (s.charAt(length - 3) == 'k') {
+            unit = s.substring(length - 3, length);
+            v = new BigDecimal(s.substring(0, length - 3));
+        } else {
+            unit = s.substring(length - 2, length);
+            v = new BigDecimal(s.substring(0, length - 2));
+        }
+        int hash = unit.hashCode();
 
-  }
 
-  /**
-   * Returns the current value
-   */
-  public Object get() {
-    if (unit == 1) {
-      return new Float(value.floatValue() * 1000);
+        int i = 0;
+        while (i < units.length) {
+            if (hash == hash_units[i]) {
+                this.unit = i;
+                break;
+            }
+            i++;
+        }
+
+        if (i == units.length) {
+            throw new InvalidParamException("unit", unit, ac);
+        }
+
+        this.value = v;
+
     }
-    return value;
-  }
 
-  /**
-   * Returns the current value
-   */
-  public String getUnit() {
-    return units[unit];
-  }
+    /**
+     * Returns the current value
+     */
+    public Object get() {
+        // TODO FIXME should not be a Float...
+        if (unit == 1) {
+            return new Float(value.floatValue() * 1000);
+        }
+        return value.floatValue();
+    }
 
-  /**
-   * Returns a string representation of the object.
-   */
-  public String toString() {
-      if (value.floatValue() != 0) {
-	  return Util.displayFloat(value) + getUnit();
-      } else {
-	  return Util.displayFloat(value);
-      }
-  }
+    /**
+     * Returns the current value
+     */
+    public String getUnit() {
+        return units[unit];
+    }
 
-  /**
-   * Compares two values for equality.
-   *
-   * @param value The other value.
-   */
-  public boolean equals(Object value) {
-    return (value instanceof CssFrequency
-	        && this.value.equals(((CssFrequency) value).value)
-	        && unit == ((CssFrequency) value).unit);
-  }
+    /**
+     * Returns a string representation of the object.
+     */
+    public String toString() {
+        if (BigDecimal.ZERO.equals(value)) {
+            return value.toPlainString();
+        }
+        return value.toPlainString() + getUnit();
+    }
+
+    /**
+     * Compares two values for equality.
+     *
+     * @param value The other value.
+     */
+    public boolean equals(Object value) {
+        return (value instanceof CssFrequency
+                && this.value.equals(((CssFrequency) value).value)
+                && unit == ((CssFrequency) value).unit);
+    }
 
-  private Float value;
-  private int unit;
-  private static String[] units = { "Hz", "kHz" };
-  private static int[] hash_units;
-  private static Float defaultValue = new Float(0);
 
-  static {
-    hash_units = new int[units.length];
-    for (int i=0; i<units.length; i++)
-      hash_units[i] = units[i].toLowerCase().hashCode();
-  }
 }
 

Index: CssPercentage.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssPercentage.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CssPercentage.java	27 Sep 2011 08:15:46 -0000	1.9
+++ CssPercentage.java	9 Feb 2012 17:36:33 -0000	1.10
@@ -9,7 +9,8 @@
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.util.Util;
+
+import java.math.BigDecimal;
 
 /**
  * <H3>
@@ -41,14 +42,14 @@
         return type;
     }
 
-    static Float defaultValue = new Float(0);
-    Float value;
+    private BigDecimal defaultValue = BigDecimal.ZERO;
+    private BigDecimal value;
 
     /**
      * Create a new CssPercentage
      */
     public CssPercentage() {
-        this(defaultValue);
+        this.value = defaultValue;
     }
 
     /**
@@ -57,7 +58,7 @@
      * @param value The value.
      */
     public CssPercentage(int value) {
-        this(new Float(value));
+        this(new BigDecimal(value));
     }
 
     /**
@@ -66,7 +67,7 @@
      * @param value the float value.
      */
     public CssPercentage(float value) {
-        this(new Float(value));
+        this(new BigDecimal(value));
     }
 
     /**
@@ -74,7 +75,7 @@
      *
      * @param value the Float object.
      */
-    public CssPercentage(Float value) {
+    public CssPercentage(BigDecimal value) {
         this.value = value;
     }
 
@@ -90,14 +91,42 @@
         if (s.charAt(slength - 1) != '%') {
             throw new InvalidParamException("percentage", s, ac);
         }
-        this.value = new Float(s.substring(0, slength - 1));
+        this.value = new BigDecimal(s.substring(0, slength - 1));
     }
 
     /**
      * Returns the current value
      */
     public Object get() {
-        return value;
+        // TODO FIXME
+        return new Float(value.floatValue());
+    }
+
+    /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isPositive() {
+        return (value.signum() >= 0);
+    }
+
+    /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isStrictlyPositive() {
+        return (value.signum() == 1);
+    }
+
+    /**
+     * Returns true is the value is zero
+     *
+     * @return a boolean
+     */
+    public boolean isZero() {
+        return BigDecimal.ZERO.equals(value);
     }
 
     /**
@@ -111,7 +140,9 @@
      * Returns a string representation of the object.
      */
     public String toString() {
-        return Util.displayFloat(value) + "%";
+        StringBuilder sb = new StringBuilder();
+        sb.append(value.toPlainString()).append('%');
+        return sb.toString();
     }
 
     /**

Index: CssLength.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssLength.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- CssLength.java	27 Sep 2011 08:15:46 -0000	1.8
+++ CssLength.java	9 Feb 2012 17:36:33 -0000	1.9
@@ -9,7 +9,8 @@
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.util.Util;
+
+import java.math.BigDecimal;
 
 /**
  * <H3>
@@ -96,11 +97,24 @@
         return type;
     }
 
+
+    private BigDecimal value;
+    private int unit;
+    private static String[] units = {"mm", "cm", "pt", "pc", "em",
+            "ex", "px", "in", "gd"};
+    private static int[] hash_units;
+
+    static {
+        hash_units = new int[units.length];
+        for (int i = 0; i < units.length; i++)
+            hash_units[i] = units[i].hashCode();
+    }
+
     /**
      * Create a new CssLength
      */
     public CssLength() {
-        value = defaultValue;
+        value = BigDecimal.ZERO;
     }
 
     /**
@@ -113,7 +127,7 @@
         s = s.toLowerCase();
         int length = s.length();
         String unit = s.substring(length - 2, length);
-        this.value = new Float(s.substring(0, length - 2));
+        this.value = new BigDecimal(s.substring(0, length - 2));
 
         this.unit = 2; // there is no unit by default
 
@@ -142,7 +156,9 @@
      * Returns the current value
      */
     public Object get() {
-        return value;
+        // TODO this is old ugly crap, needed for not breaking everything
+        // remove as soon as reference to get is removed...
+        return new Float(value.floatValue());
     }
 
     /**
@@ -153,6 +169,33 @@
     }
 
     /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isPositive() {
+        return (value.signum() >= 0);
+    }
+
+    /**
+     * Returns true is the value is positive of null
+     *
+     * @return a boolean
+     */
+    public boolean isStrictlyPositive() {
+        return (value.signum() == 1);
+    }
+
+    /**
+     * Returns true is the value is zero
+     *
+     * @return a boolean
+     */
+    public boolean isZero() {
+        return BigDecimal.ZERO.equals(value);
+    }
+
+    /**
      * Returns the current value
      */
     public String getUnit() {
@@ -163,11 +206,10 @@
      * Returns a string representation of the object.
      */
     public String toString() {
-        if (value.floatValue() != 0) {
-            return Util.displayFloat(value) + getUnit();
-        } else {
-            return Util.displayFloat(value);
+        if (BigDecimal.ZERO.equals(value)) {
+            return value.toPlainString();
         }
+        return value.toPlainString() + getUnit();
     }
 
     /**
@@ -181,17 +223,5 @@
                 unit == ((CssLength) value).unit);
     }
 
-    private Float value;
-    private int unit;
-    private static String[] units = {"mm", "cm", "pt", "pc", "em",
-            "ex", "px", "in", "gd"};
-    private static int[] hash_units;
-    private static Float defaultValue = new Float(0);
-
-    static {
-        hash_units = new int[units.length];
-        for (int i = 0; i < units.length; i++)
-            hash_units[i] = units[i].hashCode();
-    }
 }
 

Received on Thursday, 9 February 2012 17:36:37 UTC