home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / ContextLSystem.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-03-21  |  2.0 KB  |  70 lines

  1. import java.applet.Applet;
  2. import java.util.Vector;
  3.  
  4. class ContextLSystem {
  5.    String axiom;
  6.    Vector rules = new Vector();
  7.    int level;
  8.    StringBuffer currentPath;
  9.  
  10.    public ContextLSystem(Applet var1) {
  11.       this.axiom = var1.getParameter("axiom");
  12.       int var2 = 1;
  13.  
  14.       while(true) {
  15.          String var3 = var1.getParameter("pred" + var2);
  16.          String var4 = var1.getParameter("succ" + var2);
  17.          if (var3 == null || var4 == null) {
  18.             this.currentPath = new StringBuffer(this.axiom);
  19.             this.level = 0;
  20.             return;
  21.          }
  22.  
  23.          this.rules.addElement(new CLSRule(var3, var4, var1.getParameter("lContext" + var2), var1.getParameter("rContext" + var2)));
  24.          ++var2;
  25.       }
  26.    }
  27.  
  28.    public int getLevel() {
  29.       return this.level;
  30.    }
  31.  
  32.    public synchronized String getPath() {
  33.       return this.currentPath == null ? null : this.currentPath.toString();
  34.    }
  35.  
  36.    private synchronized void setPath(StringBuffer var1) {
  37.       this.currentPath = var1;
  38.       ++this.level;
  39.    }
  40.  
  41.    public void generate() {
  42.       StringBuffer var1 = new StringBuffer();
  43.       int var2 = 0;
  44.  
  45.       while(var2 < this.currentPath.length()) {
  46.          CLSRule var3 = this.findRule(var2);
  47.          if (var3 == null) {
  48.             var1.append(this.currentPath.charAt(var2));
  49.             ++var2;
  50.          } else {
  51.             var1.append(var3.succ);
  52.             var2 += var3.pred.length();
  53.          }
  54.       }
  55.  
  56.       this.setPath(var1);
  57.    }
  58.  
  59.    public CLSRule findRule(int var1) {
  60.       for(int var2 = 0; var2 < this.rules.size(); ++var2) {
  61.          CLSRule var3 = (CLSRule)this.rules.elementAt(var2);
  62.          if (var3.matches(this.currentPath, var1)) {
  63.             return var3;
  64.          }
  65.       }
  66.  
  67.       return null;
  68.    }
  69. }
  70.