1 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.IDfm; 15 import org.eclipse.ant.internal.ui.dtd.util.Factory; 16 import org.eclipse.ant.internal.ui.dtd.util.FactoryObject; 17 import org.eclipse.ant.internal.ui.dtd.util.MapHolder; 18 import org.eclipse.ant.internal.ui.dtd.util.SortedMap; 19 20 21 29 public class Dfm extends MapHolder implements IDfm, FactoryObject { 30 31 public boolean accepting; 32 public boolean empty, any; 33 public int id; 34 private static int unique = 0; 35 private static Factory factory = new Factory(); 36 private Dfm fNext; 37 38 public static Dfm dfm(boolean accepting) { 39 Dfm dfm = free(); 40 dfm.accepting = accepting; 41 return dfm; 42 } 43 44 protected Dfm() { 45 } 46 47 private static Dfm free() { 48 Dfm dfm = (Dfm) factory.getFree(); 49 if (dfm == null) 50 dfm = new Dfm(); 51 dfm.accepting = dfm.empty = dfm.any = false; 52 dfm.id = unique++; 53 return dfm; 54 } 55 56 public static Dfm dfm(IAtom accept, Dfm follow) { 57 Dfm dfm = free(); 58 dfm.keys = new Object [1]; 59 dfm.keys[0] = accept; 60 dfm.values = new Object [1]; 61 dfm.values[0] = follow; 62 return dfm; 63 } 64 65 public static void free(Dfm dfm) { 66 dfm.setKeys(null); 67 dfm.setValues(null); 68 factory.setFree(dfm); 69 } 70 71 public boolean isAccepting() { 72 return accepting; 73 } 74 75 public IDfm advance(String name) { 76 if (any) 77 return this; 78 if (empty) 79 return null; 80 if (keys == null) 81 return null; 82 SortedMap map = getIndirectStringMap(this); 83 Dfm dfm = (Dfm) map.get(name); 84 freeMap(map); 85 return dfm; 86 } 87 88 public String [] getAccepts() { 89 if (keys == null) 90 return new String [0]; 91 String [] s = new String [keys.length]; 92 for (int i = 0; i < s.length; i++) { 93 s[i] = keys[i].toString(); 94 } 95 return s; 96 } 97 98 public Dfm[] getFollows() { 99 if (values == null) 100 return new Dfm[0]; 101 Dfm[] s = new Dfm[values.length]; 102 System.arraycopy(values,0,s,0,values.length); 103 return s; 104 } 105 106 public void merge(Dfm other) { 107 accepting |= other.accepting; 108 SortedMap map = getIndirectStringMap(this); 109 SortedMap othermap = getIndirectStringMap(other); 110 map.merge(othermap); 111 freeMap(map); 112 freeMap(othermap); 113 } 114 115 public SortedMap getMap() { 116 return getIndirectStringMap(this); 117 } 118 119 122 public FactoryObject next() { 123 return fNext; 124 } 125 126 129 public void next(FactoryObject obj) { 130 fNext = (Dfm) obj; 131 } 132 133 136 public boolean isAny() { 137 return any; 138 } 139 140 143 public boolean isEmpty() { 144 return empty; 145 } 146 147 150 public IAtom getAtom(String name) { 151 Object [] allKeys = getKeys(); 152 if (empty || allKeys == null){ 153 return null; 154 } 155 SortedMap map = getIndirectStringMap(this); 156 int index = map.keyIndex(name); 157 if (index < 0) { 158 return null; 159 } 160 return (IAtom) allKeys[index]; 161 } 162 163 166 public IDfm advance(String namespace, String localname) { 167 return advance(localname); 169 } 170 } | Popular Tags |