forked from cs-au-dk/dk.brics.automaton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateRegistry.java
49 lines (44 loc) · 1.45 KB
/
StateRegistry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dk.brics.automaton;
import java.util.HashMap;
import java.util.Map;
/**
* This class provides a registry to maintain relationship between state numbers
* and various automaton IDs. This registry is useful when a union automaton
* gets built out of multiple automata and subsequently it becomes essential to
* track each state's original relationship with its previous automaton.
*
* @author neeraj
*
*/
public class StateRegistry {
private static final Map<Integer, Integer> REGISTRY = new HashMap<Integer, Integer>( );
/**
* Returns the automaton ID associated with the given state number.
*
* @param state
* the state number
* @return the automaton ID associated with the given state number;
* {@link Automaton#UNASSIGNED_AUTOMATON_ID} if no automaton is
* associated with the given state number
*/
public static Integer get( Integer state ) {
if( StateRegistry.REGISTRY.get( state ) != null ) {
return StateRegistry.REGISTRY.get( state );
} else {
return Automaton.UNASSIGNED_AUTOMATON_ID;
}
}
/**
* Registers the given state number and automaton ID that it's associated
* with. Note: this method writes to a {@code java.util.HashMap} and is not
* thread-safe.
*
* @param state
* the state number
* @param automatonId
* the automaton ID
*/
public static void set( Integer state, Integer automatonId ) {
StateRegistry.REGISTRY.put( state, automatonId );
}
}