1 18 19 package org.sablecc.sablecc.automaton; 20 21 import org.sablecc.sablecc.alphabet.Symbol; 22 import org.sablecc.sablecc.exception.InternalException; 23 24 28 class Element<T extends Comparable <? super T>> { 29 30 31 private final Partition<T> partition; 32 33 34 private final DfaState<T> state; 35 36 37 private Group<T> group; 38 39 51 Element( 52 final Partition<T> partition, 53 final DfaState<T> state) { 54 55 if (partition == null) { 56 throw new InternalException("partition may not be null"); 57 } 58 59 if (state == null) { 60 throw new InternalException("state may not be null"); 61 } 62 63 if (state.getDfa() != partition.getDfa()) { 64 throw new InternalException("invalid state"); 65 } 66 67 this.partition = partition; 68 this.state = state; 69 this.group = null; 70 71 partition.addElement(this); 72 } 73 74 79 Partition<T> getPartition() { 80 81 return this.partition; 82 } 83 84 89 DfaState<T> getState() { 90 91 return this.state; 92 } 93 94 99 Group<T> getGroup() { 100 101 return this.group; 102 } 103 104 113 void setGroup( 114 Group<T> group) { 115 116 if (group == null) { 117 throw new InternalException("group may not be null"); 118 } 119 120 if (group.getPartition() != this.partition) { 121 throw new InternalException("invalid group"); 122 } 123 124 if (this.group != null) { 126 this.group.removeElement(this); 127 } 128 129 this.group = group; 130 group.addElement(this); 131 } 132 133 143 Group<T> getTarget( 144 Symbol<T> symbol) { 145 146 if (symbol == null) { 147 throw new InternalException("symbol may not be null"); 148 } 149 150 if (!this.partition.getDfa().getAlphabet().getSymbols() 151 .contains(symbol)) { 152 throw new InternalException("invalid symbol"); 153 } 154 155 return this.partition.getElement(this.state.getTarget(symbol)).group; 156 } 157 } 158 | Popular Tags |