KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > process > extended > StackNode


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.process.extended;
10
11 import net.sourceforge.chaperon.model.extended.Pattern;
12 import net.sourceforge.chaperon.common.Decoder;
13
14 public abstract class StackNode
15 {
16   public Pattern pattern = null;
17   public StackNode last = null;
18   public StackNode ancestor = null;
19   public StackNode sibling = null;
20   private static int internalNodeCount = 0;
21   public final int index = internalNodeCount++;
22
23   public abstract String JavaDoc getText();
24
25   public String JavaDoc toString()
26   {
27     return pattern.toString()/*+"["+index+"]"*/+Decoder.toString(getText())/*+"{"+last.pattern+"}"*/;
28   }
29
30   public String JavaDoc dump()
31   {
32     return dump("");
33   }
34
35   public String JavaDoc dump(String JavaDoc rest)
36   {
37     if (this==sibling)
38       throw new IllegalStateException JavaDoc();
39     if (this==ancestor)
40       throw new IllegalStateException JavaDoc();
41
42     //System.out.println("index="+index+" "+toString()+" sibling="+sibling+" ancestor="+ancestor);
43

44     if (ancestor!=null)
45     {
46       if (sibling!=null)
47         return ancestor.dump("->"+toString()+rest)+sibling.dump(rest);
48       else
49         return ancestor.dump("->"+toString()+rest);
50     }
51
52     if (sibling!=null)
53       return toString()+rest+"\n"+sibling.dump(rest);
54     else
55       return toString()+rest+"\n";
56   }
57 }
58
Popular Tags