1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class StringValue implements Value 18 { 19 private String m_value; 20 21 22 public StringValue() 23 { 24 this(null); 25 } 26 27 28 public StringValue(String value) 29 { 30 m_value = value; 31 } 32 33 34 public StringValue(Object value) 35 { 36 m_value = (String )value; 37 } 38 39 40 public void setValue(Object value) 41 { 42 m_value = (String )value; 43 } 44 45 46 public int getTypeId() 47 { 48 return ValueType.STRING; 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.STRING) 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.STRING) { 76 String s = (String )nv.getValue(); 77 result = (m_value.compareTo(s) < 0); 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.STRING) 139 result = new StringValue(m_value); 140 else 141 throw new IllegalArgumentException (); 142 143 return result; 144 } 145 146 147 public String toString() 148 { 149 return m_value; 150 } 151 } 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | Popular Tags |