Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- /**
- *
- */
- public class NierAuxTomates {
- /*On crée l'état initial, final, courrant et existants*/
- private State initialState;
- private ArrayList<State> finalStates;
- private State currentState;
- private ArrayList<State> existingStates;
- private String[] resultat;
- /**
- * Constructor of NierAuxTomates, it initialize the initial and final States, and the existing ones.
- *
- * @param initialState
- * @param finalState
- * @param existingStates
- */
- public NierAuxTomates(State initialState, ArrayList<State> finalState, ArrayList<State> existingStates) {
- this.initialState = initialState;
- this.finalStates = finalState;
- this.existingStates = existingStates;
- }
- /**
- * Add a possible transition for the automata
- * Possible transitions are actually written into the HashMap of the States.
- *
- * @param st1
- * @param val
- * @param st2
- */
- public void addTransition(State st1, Label val, State st2) {
- int indexTmp = existingStates.indexOf(st1);
- State stTmp = existingStates.get(indexTmp);
- stTmp.addTransition(val, st2);
- }
- /**
- * Method to add an existing state in the automata
- *
- * @param st1
- */
- public void addState(State st1) {
- existingStates.add(st1);
- }
- /**
- * Methods need to set and get specified values
- */
- public State getInitialState() {
- return initialState;
- }
- public void setInitialState(State initialState) {
- this.initialState = initialState;
- }
- public ArrayList<State> getFinalState() {
- return finalStates;
- }
- public void addFinalState(State finalState) {
- this.finalStates.add(finalState);
- }
- public State getCurrentState() {
- return currentState;
- }
- public void setCurrentState(State currentState) {
- this.currentState = currentState;
- }
- public ArrayList<State> giveExistingStates() {
- return existingStates;
- }
- private boolean inFinalState(State currentState){
- for (int i = 0; i < finalStates.size(); i++) {
- if (currentState == finalStates.get(i)) return true;
- }
- return false;
- }
- /*Il faut que l'aux tomates avance à chaque fois qu'il lit une valeur, et qu'il regarde s'il peut aller quelque
- part avec la valeur qu'il lit depuis l'état actuel.
- */
- /**
- * The automate read an array of labels which is the actual values the user want to test with the automata
- * This method advance in the graph thanks to the given values and the HashMap contained in the current State
- *
- * @param values
- * @return
- */
- public String[] execute(Label[] values) {
- resultat = new String[10];
- Label labTmp;
- int it = 0;
- currentState = initialState;
- while (!(inFinalState(currentState)) && existingStates.contains(currentState)) {
- labTmp = values[it];
- currentState = currentState.giveNextState(labTmp);
- resultat[it] = labTmp.getValue();
- it++;
- }
- if (inFinalState(currentState))
- return resultat;
- else {
- resultat[0] = null;
- return resultat;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement