1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.mojo.natives.parser;
18
19 public class BranchState
20 extends AbstractParserState
21 {
22 private char[] branchChars;
23
24 private AbstractParserState[] branchStates;
25
26 private AbstractParserState noMatchState;
27
28 public BranchState( AbstractParser parser, char[] branchChars, AbstractParserState[] branchStates,
29 AbstractParserState noMatchState )
30 {
31 super( parser );
32 this.branchChars = (char[]) branchChars.clone();
33 this.branchStates = (AbstractParserState[]) branchStates.clone();
34 this.noMatchState = noMatchState;
35 }
36
37 public AbstractParserState consume( char ch )
38 {
39 AbstractParserState state;
40 for ( int i = 0; i < branchChars.length; i++ )
41 {
42 if ( ch == branchChars[i] )
43 {
44 state = branchStates[i];
45 return state.consume( ch );
46 }
47 }
48 state = getNoMatchState();
49 if ( state != null )
50 {
51 return state.consume( ch );
52 }
53 return state;
54 }
55
56 protected AbstractParserState getNoMatchState()
57 {
58 return noMatchState;
59 }
60 }