Ver código fonte

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 anos atrás
pai
commit
04db874afa

+ 67
- 32
src/java/org/apache/fop/fo/properties/EnumNumber.java Ver arquivo

package org.apache.fop.fo.properties; 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". * 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 */ /** cache holding all canonical EnumNumber instances */
private static final PropertyCache cache = new PropertyCache(); private static final PropertyCache cache = new PropertyCache();
* @param enumProperty the base EnumProperty * @param enumProperty the base EnumProperty
*/ */
private EnumNumber(Property enumProperty) { private EnumNumber(Property enumProperty) {
super(null);
this.enumProperty = (EnumProperty) enumProperty; this.enumProperty = (EnumProperty) enumProperty;
} }


/** /**
* Returns the canonical EnumNumber instance corresponding * Returns the canonical EnumNumber instance corresponding
* to the given Property * to the given Property
*
* @param enumProperty the base EnumProperty * @param enumProperty the base EnumProperty
* @return the canonical instance * @return the canonical instance
*/ */
new EnumNumber((EnumProperty) enumProperty)); new EnumNumber((EnumProperty) enumProperty));
} }


/** {@inheritDoc} */
public int getEnum() { public int getEnum() {
return enumProperty.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() { public String getString() {
return enumProperty.toString(); return enumProperty.toString();
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public Object getObject() { public Object getObject() {
return enumProperty.getObject(); return enumProperty.getObject();
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EnumNumber) { if (obj instanceof EnumNumber) {
return (((EnumNumber)obj).enumProperty == this.enumProperty); return (((EnumNumber)obj).enumProperty == this.enumProperty);
} }
} }


/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public int hashCode() { public int hashCode() {
return enumProperty.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 Ver arquivo

/** /**
* Superclass for properties that wrap an enumeration value * 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 */ /** cache holding all canonical EnumProperty instances */
private static final PropertyCache cache = new PropertyCache(); private static final PropertyCache cache = new PropertyCache();

+ 7
- 5
src/java/org/apache/fop/fo/properties/NumberProperty.java Ver arquivo

/** /**
* Class for handling numeric properties * 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 * Inner class for making NumberProperty objects
* Constructor for Number input * Constructor for Number input
* @param num Number object value for property * @param num Number object value for property
*/ */
protected NumberProperty(Number num) {
private NumberProperty(Number num) {
this.number = num; this.number = num;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public boolean equals(Object o) { public boolean equals(Object o) {
if (o != null && o instanceof NumberProperty) {
if (o == this) {
return true;
}
if (o instanceof NumberProperty) {
NumberProperty np = (NumberProperty) o; NumberProperty np = (NumberProperty) o;
return (np.number == this.number return (np.number == this.number
|| (this.number != null || (this.number != null
&& this.number.equals(np.number))); && this.number.equals(np.number)));
} else {
return false;
} }
return false;
} }
} }

+ 1
- 1
src/java/org/apache/fop/fo/properties/StringProperty.java Ver arquivo

* Exists primarily as a container for its Maker inner class, which is * Exists primarily as a container for its Maker inner class, which is
* extended by many string-based FO property classes. * 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 * Inner class for making instances of StringProperty

Carregando…
Cancelar
Salvar