1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class BooleanValue implements Value 18 { 19 private Boolean m_value; 20 21 22 public BooleanValue() 23 { 24 this(false); 25 } 26 27 28 public BooleanValue(boolean value) 29 { 30 m_value = new Boolean (value); 31 } 32 33 34 public BooleanValue(Object value) 35 { 36 m_value = (Boolean )value; 37 } 38 39 40 public void setValue(Object value) 41 { 42 m_value = (Boolean )value; 43 } 44 45 46 public int getTypeId() 47 { 48 return ValueType.BOOLEAN; 49 } 50 51 52 public Object getValue() 53 { 54 return m_value; 55 } 56 57 58 public boolean equals(Value nv) 59 { 60 boolean result = false; 61 62 if (nv.getTypeId() == ValueType.BOOLEAN) 63 result = m_value.equals(nv.getValue()); 64 else 65 throw new IllegalArgumentException (); 66 67 return result; 68 } 69 70 71 public boolean lessThan(Value nv) 72 { 73 boolean result = false; 74 75 if (nv.getTypeId() == ValueType.BOOLEAN) { 76 Boolean b = (Boolean )nv.getValue(); 77 result = (m_value.booleanValue() == false && b.booleanValue() == true); 79 } 80 else 81 throw new IllegalArgumentException (); 82 83 return result; 84 } 85 86 87 public boolean lessThanEqual(Value nv) 88 { 89 return (lessThan(nv) || equals(nv)); 90 } 91 92 93 public boolean greaterThan(Value nv) 94 { 95 return (! lessThan(nv) && ! equals(nv)); 96 } 97 98 99 public boolean greaterThanEqual(Value nv) 100 { 101 return (! lessThan(nv)); 102 } 103 104 105 public Value plus(Value nv) 106 { 107 throw new ArithmeticException (); 108 } 109 110 111 public Value minus(Value nv) 112 { 113 throw new ArithmeticException (); 114 } 115 116 117 public Value multiply(Value nv) 118 { 119 throw new ArithmeticException (); 120 } 121 122 123 public Value divide(Value nv) 124 { 125 throw new ArithmeticException (); 126 } 127 128 129 public Value negate() 130 { 131 throw new ArithmeticException (); 132 } 133 134 135 public Value convert(int typeId) 136 { 137 Value result = null; 138 139 if (typeId == ValueType.BOOLEAN) 140 result = new BooleanValue(m_value); 141 else 142 throw new IllegalArgumentException (); 143 144 return result; 145 } 146 147 148 public String toString() 149 { 150 return m_value.toString(); 151 } 152 } 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | Popular Tags |