001: /*
002: * Copyright 2005 JBoss Inc
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.drools.base.field;
018:
019: import org.drools.RuntimeDroolsException;
020: import org.drools.spi.FieldValue;
021:
022: /**
023: * @author etirelli
024: *
025: */
026: public class BooleanFieldImpl implements FieldValue {
027:
028: private static final long serialVersionUID = 400L;
029: private final boolean value;
030:
031: public BooleanFieldImpl(final boolean value) {
032: this .value = value;
033: }
034:
035: public Object getValue() {
036: return this .value ? Boolean.TRUE : Boolean.FALSE;
037: }
038:
039: public String toString() {
040: return this .value ? Boolean.TRUE.toString() : Boolean.FALSE
041: .toString();
042: }
043:
044: public boolean getBooleanValue() {
045: return this .value;
046: }
047:
048: public byte getByteValue() {
049: throw new RuntimeDroolsException(
050: "Conversion to byte not supported for type boolean");
051: }
052:
053: public char getCharValue() {
054: throw new RuntimeDroolsException(
055: "Conversion to char not supported for type boolean");
056: }
057:
058: public double getDoubleValue() {
059: throw new RuntimeDroolsException(
060: "Conversion to double not supported for type boolean");
061: }
062:
063: public float getFloatValue() {
064: throw new RuntimeDroolsException(
065: "Conversion to float not supported for type boolean");
066: }
067:
068: public int getIntValue() {
069: throw new RuntimeDroolsException(
070: "Conversion to int not supported for type boolean");
071: }
072:
073: public long getLongValue() {
074: throw new RuntimeDroolsException(
075: "Conversion to long not supported for type boolean");
076: }
077:
078: public short getShortValue() {
079: throw new RuntimeDroolsException(
080: "Conversion to short not supported for type boolean");
081: }
082:
083: public boolean equals(final Object object) {
084: if (this == object) {
085: return true;
086: }
087: if (object == null || !(object instanceof BooleanFieldImpl)) {
088: return false;
089: }
090: final BooleanFieldImpl other = (BooleanFieldImpl) object;
091:
092: return this .value == other.value;
093: }
094:
095: public int hashCode() {
096: return this .value ? 1 : 0;
097: }
098:
099: public boolean isNull() {
100: return false;
101: }
102:
103: public boolean isBooleanField() {
104: return true;
105: }
106:
107: public boolean isFloatNumberField() {
108: return false;
109: }
110:
111: public boolean isIntegerNumberField() {
112: return false;
113: }
114:
115: public boolean isObjectField() {
116: return false;
117: }
118:
119: public boolean isCollectionField() {
120: return false;
121: }
122:
123: }
|