瀏覽代碼

Slight correction:

- 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
tags/fop-0_95beta
Andreas L. Delmelle 17 年之前
父節點
當前提交
04db874afa

+ 67
- 32
src/java/org/apache/fop/fo/properties/EnumNumber.java 查看文件

@@ -19,10 +19,14 @@
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;
}

}

+ 1
- 1
src/java/org/apache/fop/fo/properties/EnumProperty.java 查看文件

@@ -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();

+ 7
- 5
src/java/org/apache/fop/fo/properties/NumberProperty.java 查看文件

@@ -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;
}
}

+ 1
- 1
src/java/org/apache/fop/fo/properties/StringProperty.java 查看文件

@@ -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

Loading…
取消
儲存