2
* This file is part of Zaluum
4
* Zaluum is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* Zaluum is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with Zaluum. If not, see <http://www.gnu.org/licenses/>.
17
* Copyright 2008,2009 Frederic Perez Ordeig
18
* Copyright 2008,2009 Elias Hortas Garcia
20
package org.zaluum.model;
23
import java.util.Map.Entry;
25
import com.google.common.base.Preconditions;
26
import com.google.common.collect.HashBiMap;
27
import com.google.common.collect.ImmutableSet;
28
import com.google.common.collect.Sets;
34
public class FSMBox extends OpenBox{
35
private static final long serialVersionUID = 1L;
36
private final Set<State> states;
44
states = Sets.newHashSet();
46
public FSMBox(FSMBox toCopy){
48
states = Sets.newHashSet();
49
HashBiMap<State, State> oldToNew = HashBiMap.create();
50
for (State s : toCopy.states){
51
State newState = new State(s, this);
52
oldToNew.put(s, newState);
54
for (Entry<State, State> e : oldToNew.entrySet()){
55
State oldfrom = e.getKey();
56
State newfrom = e.getValue();
57
for (Transition trans : oldfrom.getFrom()){
58
State oldTo = trans.getTarget();
59
State newTo = oldToNew.get(oldTo);
60
Transition transition = Transition.create(newfrom, newTo);
61
transition.setCondition(trans.getCondition());
67
protected void addStateInternal(State s){
69
observable.notifyObservers();
71
public void restoreState(State s){
72
Preconditions.checkArgument(s.getBox()==this);
75
public ImmutableSet<State> getStates() {
76
return ImmutableSet.copyOf(states);
78
public void removeState(State stateModel) {
79
stateModel.disconnectAll();
80
states.remove(stateModel);
81
observable.notifyObservers();
84
public Box deepCopy(){
85
return new FSMBox(this);
88
public BoxDescriptor getDescriptor() {
89
return BoxDescriptors.FSMBox;