Class.java
package algorithmen.umleditor;
import java.util.*;
/**
* Class with Methods and Fields.
*/
public class Class extends UmlElement implements Cloneable {
protected Vector fields;
protected Vector methods;
protected boolean abstractFlag;
/**
* Creates a new instance of Class with given name
*/
public Class(String name) {
super(name);
fields = new Vector();
methods = new Vector();
abstractFlag = false;
}
/**
* Standard-Konstruktor mit Namen "NewClass"
*/
public Class() {
this("NewClass");
}
/**
* Fügt das Field f der Feldliste (am Ende) hinzu.
*/
public void addField(Field f) {
fields.add(f);
}
/**
* Entfernt das Field an der Position index aus der Feldliste.
*/
public void removeField(int index) {
fields.remove(index);
}
/*
* Gibt die Anzahl der Felder zurück.
*/
public int getNFields() {
return fields.size();
}
/**
* Gibt das n-te Feld zurück.
*/
public Field getField(int n) {
return (Field) fields.get(n);
}
/**
* Setzt das n-te Feld.
*/
public void setField(int n, Field f) {
fields.set(n, f);
}
/**
* Gibt die Feldliste zurück.
*/
public Vector getFields() {
return fields;
}
/**
* Ersetzt die komplette Feldliste.
*/
public void setFields(Vector f) {
fields = f;
}
/**
* Fügt die Method m der Methodenliste (am Ende) hinzu.
*/
public void addMethod(Method m) {
methods.add(m);
}
/**
* Entfernt die Method an der Position index aus der Methodenliste.
*/
public void removeMethod(int index) {
methods.remove(index);
}
/*
* Gibt die Anzahl der Methoden zurück.
*/
public int getNMethods() {
return methods.size();
}
/**
* Gibt die n-te Methode zurück.
*/
public Method getMethod(int n) {
return (Method) methods.get(n);
}
/**
* Setzt die n-te Methode.
*/
public void setMethod(int n, Method f) {
methods.set(n, f);
}
/**
* Gibt die Methodenliste zurück.
*/
public Vector getMethods() {
return methods;
}
/**
* Ersetzt die komplette Methodenliste.
*/
public void setMethods(Vector m) {
methods = m;
}
/**
* Gets the abstract flag of the Class.
*/
public boolean isAbstract() {
return abstractFlag;
}
/**
* Sets the abstract flag of the Class.
*/
public void setAbstract(boolean flag) {
abstractFlag = flag;
}
/**
* Liefert eine String-Darstellung eines Class-Objekts.
* Typisches Beispiel:
* "public class Point {
* private double x = 0.0;
* private double y = 0.0;
*
* public Point(double x0, double y0);
* public void move(double dx, double dy);
* }"
*/
public String toString() {
String s = "public ";
if (abstractFlag) {
s += "abstract ";
}
s += "class " + name + " {\n";
// laufe durch die Feldliste
for (Iterator i = fields.iterator(); i.hasNext(); ) {
Field f = (Field) i.next();
s += " " + f + ";\n";
}
s += "\n";
// laufe durch die Methodenliste
for (Iterator i = methods.iterator(); i.hasNext(); ) {
Method m = (Method) i.next();
s += " " + m + ";\n";
}
s += "}";
return s;
}
}