001: package org.drools.base.extractors;
002:
003: import java.lang.reflect.Method;
004:
005: import org.drools.RuntimeDroolsException;
006: import org.drools.base.BaseClassFieldExtractor;
007: import org.drools.base.ValueType;
008: import org.drools.common.InternalWorkingMemory;
009:
010: public abstract class BaseDoubleClassFieldExtractor extends
011: BaseClassFieldExtractor {
012:
013: private static final long serialVersionUID = 400L;
014:
015: public BaseDoubleClassFieldExtractor(final Class clazz,
016: final String fieldName) {
017: super (clazz, fieldName);
018: }
019:
020: /**
021: * This constructor is not supposed to be used from outside the class hirarchy
022: *
023: * @param index
024: * @param fieldType
025: * @param valueType
026: */
027: protected BaseDoubleClassFieldExtractor(final int index,
028: final Class fieldType, final ValueType valueType) {
029: super (index, fieldType, valueType);
030: }
031:
032: public Object getValue(InternalWorkingMemory workingMemory,
033: final Object object) {
034: return new Double(getDoubleValue(workingMemory, object));
035: }
036:
037: public boolean getBooleanValue(InternalWorkingMemory workingMemory,
038: final Object object) {
039: throw new RuntimeDroolsException(
040: "Conversion to boolean not supported from double");
041: }
042:
043: public byte getByteValue(InternalWorkingMemory workingMemory,
044: final Object object) {
045: return (byte) getDoubleValue(workingMemory, object);
046:
047: }
048:
049: public char getCharValue(InternalWorkingMemory workingMemory,
050: final Object object) {
051: throw new RuntimeDroolsException(
052: "Conversion to char not supported from double");
053: }
054:
055: public abstract double getDoubleValue(
056: InternalWorkingMemory workingMemory, Object object);
057:
058: public float getFloatValue(InternalWorkingMemory workingMemory,
059: final Object object) {
060: return (float) getDoubleValue(workingMemory, object);
061: }
062:
063: public int getIntValue(InternalWorkingMemory workingMemory,
064: final Object object) {
065: return (int) getDoubleValue(workingMemory, object);
066: }
067:
068: public long getLongValue(InternalWorkingMemory workingMemory,
069: final Object object) {
070: return (long) getDoubleValue(workingMemory, object);
071: }
072:
073: public short getShortValue(InternalWorkingMemory workingMemory,
074: final Object object) {
075: return (short) getDoubleValue(workingMemory, object);
076: }
077:
078: public boolean isNullValue(InternalWorkingMemory workingMemory,
079: final Object object) {
080: return false;
081: }
082:
083: public Method getNativeReadMethod() {
084: try {
085: return this .getClass().getDeclaredMethod(
086: "getDoubleValue",
087: new Class[] { InternalWorkingMemory.class,
088: Object.class });
089: } catch (final Exception e) {
090: throw new RuntimeDroolsException(
091: "This is a bug. Please report to development team: "
092: + e.getMessage(), e);
093: }
094: }
095:
096: public int getHashCode(InternalWorkingMemory workingMemory,
097: final Object object) {
098: final long temp = Double.doubleToLongBits(getDoubleValue(
099: workingMemory, object));
100: return (int) (temp ^ (temp >>> 32));
101: }
102:
103: }
|