All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.statefulj.fsm.model.impl.StateImpl Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
/***
 * 
 * Copyright 2014 Andrew Hall
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package org.statefulj.fsm.model.impl;

import java.util.HashMap;
import java.util.Map;

import org.statefulj.fsm.model.Action;
import org.statefulj.fsm.model.State;
import org.statefulj.fsm.model.Transition;

public class StateImpl implements State {

	private String name;
	private Map> transitions = new HashMap>();
	boolean isEndState = false;
	boolean isBlocking = false;
	
	public StateImpl() {
	}

	public StateImpl(String name) {
		this.name = name;
	}

	public StateImpl(String name, boolean isEndState) {
		this(name);
		this.isEndState = isEndState;
	}

	public StateImpl(String name, boolean isEndState, boolean isBlocking) {
		this(name, isEndState);
		this.isBlocking = isBlocking;
	}

	public StateImpl(String name, Map> transitions, boolean isEndState) {
		this(name, isEndState);
		this.transitions = transitions;
	}

	public StateImpl(String name, Map> transitions, boolean isEndState, boolean isBlocking) {
		this(name, transitions, isEndState);
		this.isBlocking = isBlocking;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Transition getTransition(String event) {
		return transitions.get(event);
	}

	public Map> getTransitions() {
		return transitions;
	}

	public void setTransitions(Map> transitions) {
		this.transitions = transitions;
	}

	public boolean isEndState() {
		return isEndState;
	}

	public void setEndState(boolean isEndState) {
		this.isEndState = isEndState;
	}

	@Override
	public void addTransition(String event, State next) {
		this.transitions.put(event, new DeterministicTransitionImpl(next, null));
	}
	
	@Override
	public void addTransition(String event, State next, Action action) {
		this.transitions.put(event, new DeterministicTransitionImpl(next, action));
	}
	
	@Override
	public void addTransition(String event, Transition transition) {
		this.transitions.put(event, transition);
	}
	
	@Override
	public void removeTransition(String event) {
		this.transitions.remove(event);
	}

	@Override
	public void setBlocking(boolean isBlocking) {
		this.isBlocking = isBlocking;
	}

	@Override
	public boolean isBlocking() {
		return this.isBlocking;
	}
	
	@Override
	public String toString() {
		return "State[name=" + this.name + ", isEndState=" + this.isEndState + ", isBlocking=" + this.isBlocking +"]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy