KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > dtd > schema > NfmNode


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 Object Factory Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Object Factory Inc. - Initial implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.dtd.schema;
12
13 import org.eclipse.ant.internal.ui.dtd.IAtom;
14 import org.eclipse.ant.internal.ui.dtd.util.Factory;
15 import org.eclipse.ant.internal.ui.dtd.util.FactoryObject;
16
17 /**
18  * Non-deterministic finite state machine node.<p>
19  *
20  * Following Aho & Ullman, nfm nodes contain two
21  * transition links. The graph is constructed so
22  * that no node requires more than two links.
23  * There are exactly these kinds of nodes:
24  * <pre>
25  * Symbol Next1 Next2 Meaning
26  * "a" fwd null Regexp "a"
27  * null null null Accepting node
28  * null fwd1 fwd2 Start node of ? and * regexp
29  * fwd2 points to stop node
30  * null fwd bkw Internal node of + and * regexp
31  * fwd points to stop node
32  * bkw points, e.g., in "a*" to start node of "a"
33  * null fwd1 fwd2 Start node of | regexp, e.g., "a|b",
34  * fwd nodes point to start nodes of "a" and "b".
35  * null fwd null Internal node of |.
36  * fwd points to stop node.
37  * </pre>
38  * See Nfm for pictures of how nodes are used.
39  * @author Bob Foster
40  */

41 public class NfmNode implements FactoryObject {
42
43     public IAtom symbol;
44     public NfmNode next1;
45     public NfmNode next2;
46     public Dfm dfm;
47     public int mark;
48     
49     private NfmNode() {
50     }
51     
52     public static NfmNode nfmNode(IAtom symbol, NfmNode next) {
53         NfmNode nfm = getFree();
54         nfm.symbol = symbol;
55         nfm.next1 = next;
56         return nfm;
57     }
58     
59     public static NfmNode nfmNode(NfmNode next) {
60         NfmNode nfm = getFree();
61         nfm.next1 = next;
62         return nfm;
63     }
64     
65     public static NfmNode nfmNode() {
66         return getFree();
67     }
68     
69     /**
70      * Free all NfmNodes in use.
71      */

72     public static void freeAll() {
73         while (fUsed != null) {
74             FactoryObject nfm = fUsed;
75             fUsed = nfm.next();
76             setFree((NfmNode)nfm);
77         }
78     }
79     
80     // Below here is factory stuff
81

82     /* (non-Javadoc)
83      * @see org.eclipse.ant.internal.ui.dtd.util.FactoryObject#next()
84      */

85     public FactoryObject next() {
86         return next;
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.ant.internal.ui.dtd.util.FactoryObject#next(org.eclipse.ant.internal.ui.dtd.util.FactoryObject)
91      */

92     public void next(FactoryObject obj) {
93         next = (NfmNode) obj;
94     }
95     private NfmNode next;
96     private static Factory fFactory = new Factory();
97     private static FactoryObject fUsed = null;
98     private static NfmNode getFree() {
99         NfmNode nfm = (NfmNode) fFactory.getFree();
100         if (nfm == null)
101             nfm = new NfmNode();
102         nfm.next(fUsed);
103         fUsed = nfm;
104         return nfm;
105     }
106     private static void setFree(NfmNode nfm) {
107         nfm.symbol = null;
108         nfm.next1 = nfm.next2 = null;
109         nfm.dfm = null;
110         nfm.mark = 0;
111         fFactory.setFree(nfm);
112     }
113 }
114
Popular Tags