1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class CharValue implements Value 18 { 19 private Character m_value; 20 21 22 public CharValue() 23 { 24 this((char)0); 25 } 26 27 28 public CharValue(char value) 29 { 30 m_value = new Character (value); 31 } 32 33 34 public CharValue(Object value) 35 { 36 m_value = (Character )value; 37 } 38 39 40 public void setValue(Object value) 41 { 42 m_value = (Character )value; 43 } 44 45 46 public int getTypeId() 47 { 48 return ValueType.CHAR; 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.CHAR) 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.CHAR) { 76 Character c = (Character )nv.getValue(); 77 result = (m_value.charValue() < c.charValue()); 78 } 79 else 80 throw new IllegalArgumentException (); 81 82 return result; 83 } 84 85 86 public boolean lessThanEqual(Value nv) 87 { 88 return (lessThan(nv) || equals(nv)); 89 } 90 91 92 public boolean greaterThan(Value nv) 93 { 94 return (! lessThan(nv) && ! equals(nv)); 95 } 96 97 98 public boolean greaterThanEqual(Value nv) 99 { 100 return (! lessThan(nv)); 101 } 102 103 104 public Value plus(Value nv) 105 { 106 throw new ArithmeticException (); 107 } 108 109 110 public Value minus(Value nv) 111 { 112 throw new ArithmeticException (); 113 } 114 115 116 public Value multiply(Value nv) 117 { 118 throw new ArithmeticException (); 119 } 120 121 122 public Value divide(Value nv) 123 { 124 throw new ArithmeticException (); 125 } 126 127 128 public Value negate() 129 { 130 throw new ArithmeticException (); 131 } 132 133 134 public Value convert(int typeId) 135 { 136 Value result = null; 137 138 if (typeId == ValueType.CHAR) 139 result = new CharValue(m_value); 140 else if (typeId == ValueType.STRING) { 141 char[] arr = new char[1]; 142 arr[0] = m_value.charValue(); 143 String s = new String (arr); 144 result = ValueFactory.createString(s); 145 } 146 else 147 throw new IllegalArgumentException (); 148 149 return result; 150 } 151 152 153 public String toString() 154 { 155 return m_value.toString(); 156 } 157 } 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | Popular Tags |