From dfe78601810c44b533e30c95546838ee2e0a9a70 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Sat, 19 Oct 2002 02:04:19 +0000 Subject: Added subtract/add(double) and isInteger(). Removed setPower(). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195333 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/datatypes/Numeric.java | 47 +++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/org/apache/fop/datatypes/Numeric.java b/src/org/apache/fop/datatypes/Numeric.java index 0f18cf42b..9c5732fa6 100644 --- a/src/org/apache/fop/datatypes/Numeric.java +++ b/src/org/apache/fop/datatypes/Numeric.java @@ -14,6 +14,7 @@ import java.lang.Number; import org.apache.fop.datatypes.AbstractPropertyValue; import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropNames; import org.apache.fop.fo.PropertyConsts; import org.apache.fop.fo.Properties; import org.apache.fop.datatypes.PropertyValue; @@ -286,14 +287,6 @@ public class Numeric extends AbstractPropertyValue implements Cloneable { return power; } - /** - * Set the power. A complement to the setValue method. - * @param power - the int power. - */ - protected void setPower(int power) { - this.power = power; - } - /** * @return int current baseunit of this Numeric. */ @@ -373,6 +366,14 @@ public class Numeric extends AbstractPropertyValue implements Cloneable { return (baseunit == NUMBER); } + /** + * This object is an integer if it is a number and the + * rounded value is equal to the value. + */ + public boolean isInteger() { + return (isNumber() && (double)(Math.round(value)) == value); + } + /** * This object is an EMS factor if the baseunit is EMS. Power is * guaranteed to be zero for EMS baseunit. @@ -498,6 +499,21 @@ public class Numeric extends AbstractPropertyValue implements Cloneable { return this; } + /** + * Subtract a double from the current value. + * @param op - the value to subtract. + * @return Numeric; this object. + * @throws PropertyException if this is not a number. + */ + public Numeric subtract(double op) throws PropertyException { + // Check of same dimension + if (power != 0 || baseunit != NUMBER) + throw new PropertyException + ("Can't subtract number from length."); + value -= op; + return this; + } + /** * Add the operand to the current value. * @param op The value to add. @@ -526,6 +542,21 @@ public class Numeric extends AbstractPropertyValue implements Cloneable { return this; } + /** + * Add a double to the current value. + * @param op - the value to add. + * @return Numeric; this object. + * @throws PropertyException if this is not a number. + */ + public Numeric add(double op) throws PropertyException { + // Check of same dimension + if (power != 0 || baseunit != NUMBER) + throw new PropertyException + ("Can't add number to length."); + value += op; + return this; + } + /** * Derive the remainder from a truncating division (mod). As with * additive operators, the values must be absolute Numerics -- cgit v1.2.3