Field.java

package algorithmen.umleditor;

/**
 * Data field with type and value.
 * Part of Class and Object objects as well as parameter lists.
 */
public class Field extends Member implements Cloneable {
  
  protected String value;
  
  /** Creates a new instance with given name and type */
  public Field(String name, String type) {
    super(name, type);
  }
  
  /**
   * Standard-Konstruktor mit Namen "NewField" und Typ int.
   */
  public Field() {
    this("newField", "int");
  }
  
  /**
   * Gets the value of the Field.
   */
  public String getValue() {
    return value;
  }
  
  /**
   * Sets the value of the Field.
   */
  public void setValue(String newValue) {
    value = newValue;
  }
  
  /**
   * Returns String representation of a Field in Java form.
   * Typical examples:
   *    "protected int alter=18"
   *    "static public double PI=3.1415926"
   */
  public String toString() {
    String s = "";
    if (staticFlag) {
      s += "static ";
    }
    
    if (visibility != Visibility.DEFAULT) {
      s += visibility + " ";
    }
    
    s += type + " " + name;
    if (value != null && !value.equals("")) {
      s += " = " + value;
    }
    
    return s;
  }
  
  /**
   * support for cloning.
   */
  public java.lang.Object clone() {
    java.lang.Object o = null;
    try {
      o = super.clone();
    } catch(CloneNotSupportedException e) {
      System.err.println("Field kann nicht klonen.");
    }
    return o;
  }
}