1 9 12 package org.nfunk.jep; 13 import java.util.*; 14 15 28 public class Variable extends Observable { 29 protected String name; 30 private Object value; 31 private boolean isConstant = false; 32 private boolean validValue = false; 33 35 39 protected Variable(String name) 40 { 41 this.name = name; 42 this.value = null; 43 validValue = false; 44 } 45 49 protected Variable(String name,Object value) 50 { 51 this.name = name; 52 this.value = value; 53 validValue = (value!=null); 54 } 55 public String getName() {return name;} 56 public boolean isConstant() { return this.isConstant; } 58 public void setIsConstant(boolean b) { this.isConstant = b; } 59 public Object getValue() { return value; } 60 61 public boolean hasValidValue() { return validValue; } 62 63 public void setValidValue(boolean val) { validValue = val; } 64 65 76 public boolean setValue(Object object) { 77 if(!setValueRaw(object)) return false; 78 setChanged(); 79 notifyObservers(); 80 return true; 81 } 82 83 91 protected boolean setValueRaw(Object object) { 92 if(isConstant) return false; 93 validValue = true; 94 value = object; 95 return true; 96 } 97 98 106 public String toString() { 107 if(!validValue || value == null) 108 return name + ": null"; 109 else if(isConstant) 110 return name + ": " + value.toString() + " (Constant)"; 111 else 112 return name + ": " + value.toString(); 113 } 114 } 115 | Popular Tags |