Biblioteca Java - Rev 17
Subversion Repositories:
package rtuml.capsuleimpl;
import rtuml.capsule.*;
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
StateMachine m1 = new StateMachine("1");
OnState on = new OnState();
OffState off = new OffState();
TransitionToOff toOff = new TransitionToOff(off);
TransitionToOn toOn = new TransitionToOn(on);
on.addTransition(toOff);
off.addTransition(toOn);
m1.addState(on);
m1.addState(off);
m1.setStartState(off);
//////////////////////////////////
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter command (on/off) and press Enter:");
while(true){
String s = br.readLine();
if(s.equalsIgnoreCase("on")){
m1.dispatchEvent(new SwitchTurnedOn());
}
else if(s.equalsIgnoreCase("off")){
m1.dispatchEvent(new SwitchTurnedOff());
}
}
}
}
class SwitchTurnedOn extends Event{}
class SwitchTurnedOff extends Event{}
class OnState extends MState{
@Override
public void exitAction(Event e) {
}
@Override
public void entryAction(Event e) {
System.out.println("Swith light ON");
}
@Override
public void doAction(Event e) {
System.out.println("Light stays ON!");
}
}
class OffState extends MState{
@Override
public void exitAction(Event e) {
}
@Override
public void entryAction(Event e) {
System.out.println("Swith light OFF");
}
@Override
public void doAction(Event e) {
System.out.println("Light stays OFF!");
}
}
class TransitionToOff extends Transition{
public TransitionToOff(MState nextState) {
super(nextState);
}
@Override
public boolean gaurdCondition(Event e) {
return e instanceof SwitchTurnedOff;
}
}
class TransitionToOn extends Transition{
public TransitionToOn(MState nextState) {
super(nextState);
}
@Override
public boolean gaurdCondition(Event e) {
return e instanceof SwitchTurnedOn;
}
}
import rtuml.capsule.*;
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
StateMachine m1 = new StateMachine("1");
OnState on = new OnState();
OffState off = new OffState();
TransitionToOff toOff = new TransitionToOff(off);
TransitionToOn toOn = new TransitionToOn(on);
on.addTransition(toOff);
off.addTransition(toOn);
m1.addState(on);
m1.addState(off);
m1.setStartState(off);
//////////////////////////////////
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter command (on/off) and press Enter:");
while(true){
String s = br.readLine();
if(s.equalsIgnoreCase("on")){
m1.dispatchEvent(new SwitchTurnedOn());
}
else if(s.equalsIgnoreCase("off")){
m1.dispatchEvent(new SwitchTurnedOff());
}
}
}
}
class SwitchTurnedOn extends Event{}
class SwitchTurnedOff extends Event{}
class OnState extends MState{
@Override
public void exitAction(Event e) {
}
@Override
public void entryAction(Event e) {
System.out.println("Swith light ON");
}
@Override
public void doAction(Event e) {
System.out.println("Light stays ON!");
}
}
class OffState extends MState{
@Override
public void exitAction(Event e) {
}
@Override
public void entryAction(Event e) {
System.out.println("Swith light OFF");
}
@Override
public void doAction(Event e) {
System.out.println("Light stays OFF!");
}
}
class TransitionToOff extends Transition{
public TransitionToOff(MState nextState) {
super(nextState);
}
@Override
public boolean gaurdCondition(Event e) {
return e instanceof SwitchTurnedOff;
}
}
class TransitionToOn extends Transition{
public TransitionToOn(MState nextState) {
super(nextState);
}
@Override
public boolean gaurdCondition(Event e) {
return e instanceof SwitchTurnedOn;
}
}