File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ * .class
Original file line number Diff line number Diff line change
1
+ import java .util .List ;
2
+ import java .io .IOException ;
3
+
4
+ public class Main {
5
+
6
+ public static void main (String [] args ) throws IOException {
7
+
8
+ State s1 = new State ("A" , false );
9
+ State s2 = new State ("B" , false );
10
+ State s3 = new State ("C" , true );
11
+
12
+ s1 .addTransitionForSymbol ("a" , s2 );
13
+ s2 .addTransitionForSymbol ("b" , s3 );
14
+ List <State > states = s2 .getTransitionsForSymbol ("b" );
15
+
16
+ for (State state : states ) {
17
+ System .out .println (state .getName ());
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .ArrayList ;
2
+ import java .util .HashMap ;
3
+ import java .util .List ;
4
+
5
+ public class State {
6
+
7
+ private String name ;
8
+ private boolean accepting ;
9
+ private HashMap <String , List <State >> states ;
10
+
11
+ public State (String name , boolean accepting ) {
12
+ this .name = name ;
13
+ this .accepting = accepting ;
14
+ this .states = new HashMap <>();
15
+ }
16
+
17
+ public String getName () {
18
+ return name ;
19
+ }
20
+
21
+ public boolean getIsAccepting () {
22
+ return accepting ;
23
+ }
24
+
25
+ public void addTransitionForSymbol (String symbol , State state ) {
26
+
27
+ List <State > stateArray = states .get (symbol );
28
+
29
+ if (stateArray != null ) {
30
+ stateArray .add (state );
31
+ } else {
32
+ states .put (symbol , new ArrayList <State >());
33
+ states .get (symbol ).add (state );
34
+ }
35
+ }
36
+
37
+ public List <State > getTransitionsForSymbol (String symbol ) {
38
+ return states .get (symbol );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments