package org.nfunk.jep;

import java.util.Observable;

public class Variable extends Observable {
  protected String name;
  
  private Object value;
  
  private boolean isConstant = false;
  
  private boolean validValue = false;
  
  protected Variable(String paramString) {
    this.name = paramString;
    this.value = null;
    this.validValue = false;
  }
  
  protected Variable(String paramString, Object paramObject) {
    this.name = paramString;
    this.value = paramObject;
    this.validValue = (paramObject != null);
  }
  
  public String getName() {
    return this.name;
  }
  
  public boolean isConstant() {
    return this.isConstant;
  }
  
  public void setIsConstant(boolean paramBoolean) {
    this.isConstant = paramBoolean;
  }
  
  public Object getValue() {
    return this.value;
  }
  
  public boolean hasValidValue() {
    return this.validValue;
  }
  
  public void setValidValue(boolean paramBoolean) {
    this.validValue = paramBoolean;
  }
  
  public boolean setValue(Object paramObject) {
    if (!setValueRaw(paramObject))
      return false; 
    setChanged();
    notifyObservers();
    return true;
  }
  
  protected boolean setValueRaw(Object paramObject) {
    if (this.isConstant)
      return false; 
    this.validValue = true;
    this.value = paramObject;
    return true;
  }
  
  public String toString() {
    return (!this.validValue || this.value == null) ? (this.name + ": null") : (this.isConstant ? (this.name + ": " + this.value.toString() + " (Constant)") : (this.name + ": " + this.value.toString()));
  }
}
