]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Slight correction:
authorAndreas L. Delmelle <adelmelle@apache.org>
Fri, 20 Jul 2007 16:48:55 +0000 (16:48 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Fri, 20 Jul 2007 16:48:55 +0000 (16:48 +0000)
- make NumberProperty, EnumProperty, EnumNumber and StringProperty final, so instanceof suffices in the check for equality
- instead of subclassing NumberProperty, make EnumNumber implement the Numeric interface

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@558045 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/properties/EnumNumber.java
src/java/org/apache/fop/fo/properties/EnumProperty.java
src/java/org/apache/fop/fo/properties/NumberProperty.java
src/java/org/apache/fop/fo/properties/StringProperty.java

index fcd596d7e181db8e0187d2183531858d08be99ce..2cfc67f279aeb7de63db81f66fc75d85ed6988aa 100755 (executable)
  
 package org.apache.fop.fo.properties;
 
+import org.apache.fop.datatypes.Numeric;
+import org.apache.fop.datatypes.PercentBaseContext;
+import org.apache.fop.fo.expr.PropertyException;
+
 /**
  * A number quantity in XSL which is specified as an enum, such as "no-limit".
  */
-public class EnumNumber extends NumberProperty {
+public final class EnumNumber extends Property implements Numeric {
 
     /** cache holding all canonical EnumNumber instances */
     private static final PropertyCache cache = new PropertyCache();
@@ -34,13 +38,13 @@ public class EnumNumber extends NumberProperty {
      * @param enumProperty  the base EnumProperty
      */
     private EnumNumber(Property enumProperty) {
-        super(null);
         this.enumProperty = (EnumProperty) enumProperty;
     }
 
     /**
      * Returns the canonical EnumNumber instance corresponding
      * to the given Property
+     * 
      * @param enumProperty  the base EnumProperty
      * @return  the canonical instance
      */
@@ -49,45 +53,22 @@ public class EnumNumber extends NumberProperty {
                 new EnumNumber((EnumProperty) enumProperty));
     }
 
+    /** {@inheritDoc} */
     public int getEnum() {
         return enumProperty.getEnum();
     }
 
-    /**
-     * Returns the length in 1/1000ths of a point (millipoints)
-     * @return the length in millipoints
-     */
-    public int getValue() {
-        log.error("getValue() called on " + enumProperty + " number");
-        return 0;
-    }
-
-    /**
-     * Returns the value as numeric.
-     * @return the length in millipoints
-     */
-    public double getNumericValue() {
-        log.error("getNumericValue() called on " + enumProperty + " number");
-        return 0;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public String getString() {
         return enumProperty.toString();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public Object getObject() {
         return enumProperty.getObject();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public boolean equals(Object obj) {
         if (obj instanceof EnumNumber) {
             return (((EnumNumber)obj).enumProperty == this.enumProperty);
@@ -96,11 +77,65 @@ public class EnumNumber extends NumberProperty {
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int hashCode() {
         return enumProperty.hashCode();
     }
+
+    /** {@inheritDoc} */
+    public int getDimension() {
+        return 0;
+    }
+
+    /** 
+     * {@inheritDoc}
+     * Always <code>true</code> for instances of this type
+     */
+    public boolean isAbsolute() {
+        return true;
+    }
     
+    /** 
+     * {@inheritDoc} 
+     * logs an error, because it's not supposed to be called
+     */
+    public double getNumericValue(PercentBaseContext context) throws PropertyException {
+        log.error("getNumericValue() called on " + enumProperty + " number");
+        return 0;
+    }
+
+    /** 
+     * {@inheritDoc} 
+     * logs an error, because it's not supposed to be called
+     */
+    public int getValue(PercentBaseContext context) {
+        log.error("getValue() called on " + enumProperty + " number");
+        return 0;
+    }
+
+    /** 
+     * {@inheritDoc} 
+     * logs an error, because it's not supposed to be called
+     */
+    public int getValue() {
+        log.error("getValue() called on " + enumProperty + " number");
+        return 0;
+    }
+
+    /** 
+     * {@inheritDoc} 
+     * logs an error, because it's not supposed to be called
+     */
+    public double getNumericValue() {
+        log.error("getNumericValue() called on " + enumProperty + " number");
+        return 0;
+    }
+
+    /** 
+     * {@inheritDoc}
+     */
+    public Numeric getNumeric() {
+        return this;
+    }
+
 }
index b5435b0f1ca0588344f70a8224f5f851b2d116c6..328ed85a95ff31792e2a28ac6b3b66945cc46a78 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.fop.fo.expr.PropertyException;
 /**
  * Superclass for properties that wrap an enumeration value
  */
-public class EnumProperty extends Property {
+public final class EnumProperty extends Property {
     
     /** cache holding all canonical EnumProperty instances */
     private static final PropertyCache cache = new PropertyCache();
index 091e3649423b9823f6e83d1e65bf0ff12ecb90f6..2dd65e1ce47398ce3c42e31edcb063a700df9c26 100644 (file)
@@ -32,7 +32,7 @@ import org.apache.fop.fo.expr.PropertyException;
 /**
  * Class for handling numeric properties
  */
-public class NumberProperty extends Property implements Numeric {
+public final class NumberProperty extends Property implements Numeric {
 
     /**
      * Inner class for making NumberProperty objects
@@ -77,7 +77,7 @@ public class NumberProperty extends Property implements Numeric {
      * Constructor for Number input
      * @param num Number object value for property
      */
-    protected NumberProperty(Number num) {
+    private NumberProperty(Number num) {
         this.number = num;
     }
 
@@ -224,13 +224,15 @@ public class NumberProperty extends Property implements Numeric {
     
     /** {@inheritDoc} */
     public boolean equals(Object o) {
-        if (o != null && o instanceof NumberProperty) {
+        if (o == this) {
+            return true;
+        }
+        if (o instanceof NumberProperty) {
             NumberProperty np = (NumberProperty) o;
             return (np.number == this.number
                     || (this.number != null
                         && this.number.equals(np.number)));
-        } else {
-            return false;
         }
+        return false;
     }
 }
index a38840352722f728c76082bab6f8fb26b3458bfd..f84a76c830eddfc0e15ee54d2614d5da810ca8cc 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.fop.fo.PropertyList;
  * Exists primarily as a container for its Maker inner class, which is
  * extended by many string-based FO property classes.
  */
-public class StringProperty extends Property {
+public final class StringProperty extends Property {
 
     /**
      * Inner class for making instances of StringProperty