home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.util.Vector;
-
- class ContextLSystem {
- String axiom;
- Vector rules = new Vector();
- int level;
- StringBuffer currentPath;
-
- public ContextLSystem(Applet var1) {
- this.axiom = var1.getParameter("axiom");
- int var2 = 1;
-
- while(true) {
- String var3 = var1.getParameter("pred" + var2);
- String var4 = var1.getParameter("succ" + var2);
- if (var3 == null || var4 == null) {
- this.currentPath = new StringBuffer(this.axiom);
- this.level = 0;
- return;
- }
-
- this.rules.addElement(new CLSRule(var3, var4, var1.getParameter("lContext" + var2), var1.getParameter("rContext" + var2)));
- ++var2;
- }
- }
-
- public int getLevel() {
- return this.level;
- }
-
- public synchronized String getPath() {
- return this.currentPath == null ? null : this.currentPath.toString();
- }
-
- private synchronized void setPath(StringBuffer var1) {
- this.currentPath = var1;
- ++this.level;
- }
-
- public void generate() {
- StringBuffer var1 = new StringBuffer();
- int var2 = 0;
-
- while(var2 < this.currentPath.length()) {
- CLSRule var3 = this.findRule(var2);
- if (var3 == null) {
- var1.append(this.currentPath.charAt(var2));
- ++var2;
- } else {
- var1.append(var3.succ);
- var2 += var3.pred.length();
- }
- }
-
- this.setPath(var1);
- }
-
- public CLSRule findRule(int var1) {
- for(int var2 = 0; var2 < this.rules.size(); ++var2) {
- CLSRule var3 = (CLSRule)this.rules.elementAt(var2);
- if (var3.matches(this.currentPath, var1)) {
- return var3;
- }
- }
-
- return null;
- }
- }
-