Java API By Example, From Geeks To Geeks.

# Java > Open Source Codes > SOFA > SOFAnode > Util > DFSRChecker > node > DeterministicNode

 `1 /* 2  * \$Id: DeterministicNode.java,v 1.4 2005/07/08 12:04:12 kofron Exp \$ 3  *4  * Copyright 20045  * Distributed Systems Research Group6  * Department of Software Engineering7  * Faculty of Mathematics and Physics8  * Charles University, Prague9  *10  * Copyright 200511  * Formal Methods In Software Engineering Group12  * Institute of Computer Science13  * Academy of Sciences of the Czech Republic14  * 15  * This code was developed by Jan Kofron 16  */17 18 package SOFA.SOFAnode.Util.DFSRChecker.node;19 20 21 import java.util.ArrayList ;22 import java.util.LinkedList ;23 import java.util.TreeMap ;24 import java.util.Iterator ;25 import java.util.Set ;26 import java.util.TreeSet ;27 28 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException;29 import SOFA.SOFAnode.Util.DFSRChecker.state.CompositeState;30 import SOFA.SOFAnode.Util.DFSRChecker.state.State;31 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair;32 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs;33 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol;34 35 /**36  * Represented operation of determinization.37  */38 public class DeterministicNode extends TreeNode {39 40     /**41      * Creates a new instance of DeterministicNode42      */43     public DeterministicNode(TreeNode node) {44         super("Det(" + node.protocol + ")");45         this.nodes = new TreeNode[1];46         this.nodes[0] = node;47     }48 49     /**50      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getInitial()51      */52     public State getInitial() {53         State[] state = new State[1];54         state[0] = nodes[0].getInitial();55 56         return new CompositeState(state);57     }58 59     /**60      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#isAccepting(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)61      */62     public boolean isAccepting(State state) {63         CompositeState cstate = (CompositeState) state;64 65         for (int i = 0; i < cstate.states.length; ++i)66             if (nodes[0].isAccepting(cstate.states[i]))67                 return true;68 69         return false;70 71     }72 73     /**74      * This method creates the deterministic transition set form a75      * nedeterministic one. It creates, of course, for each of the possible76      * transitions via the same event a transition to a newly created77      * CompositeState.78      * 79      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getTransitions(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)80      */81     public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException {82         CompositeState cstate = (CompositeState) state;83         TreeMap transmap = new TreeMap ();84         LinkedList deps = new LinkedList ();85 86         int nodecnt = cstate.states.length;87 88         for (int i = 0; i < nodecnt; ++i) {89             TransitionPairs transp = nodes[0].getTransitions(cstate.states[i]);90             TransitionPair[] trans = transp.transitions;91             92             if (transp.deps != null)93                 deps.addAll(transp.deps);94             95             for (int j = 0; j < trans.length; ++j) {96                 TreeSet states = (TreeSet ) transmap.get(new Integer (trans[j].eventIndex));97                 if (states != null) {98                     states.add(trans[j].state);99                 } else {100                     states = new TreeSet ();101                     states.add(trans[j].state);102                     transmap.put(new Integer (trans[j].eventIndex), states);103                 }104             }105         }106 107         TransitionPair[] result = new TransitionPair[transmap.size()];108         Set keys = transmap.keySet();109         Iterator it = keys.iterator();110         int i = 0;111 112         while (it.hasNext()) {113             Integer eventindex = (Integer ) it.next();114             TreeSet states = (TreeSet ) transmap.get(eventindex);115             State[] resultstates = new State[states.size()];116 117             Iterator it2 = states.iterator();118             int l = 0;119 120             while (it2.hasNext())121                 resultstates[l++] = (State) it2.next();122 123             result[i++] = new TransitionPair(eventindex.intValue(), new CompositeState(resultstates));124         }125 126         //TODO: debug only!127 /*128         for (i = 0; i < result.length; ++i)129             result[i].state.getSignature();130         */131         132         TransitionPairs restrans = new TransitionPairs(result);133         restrans.deps = deps;134         return restrans;135     }136 137     /**138      * 139      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getWeight()140      */141     public long getWeight() {142         if (weight != -1)143             return weight;144         else {145             return weight = nodes[0].getWeight();146         }147     }148     149     /**150      * @return the symbolic name of the treenode denoting its type151      */152     public String [] getTypeName() {153         String [] result = { "Deterministic", "DET" };154         return result;155     }156     157     158 159     /**160      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getAnotatedProtocol(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)161      */162     public AnotatedProtocol getAnotatedProtocol(State state) {163         CompositeState cstate = (CompositeState) state;164         String result = new String ();165         int cnt = cstate != null ? cstate.states.length : 0;166         ArrayList indicesresult = new ArrayList ();167 168         for (int i = 0; i < cnt; ++i) {169             AnotatedProtocol subresult = nodes[0].getAnotatedProtocol(cstate.states[i]);170             171             for (int j = 0; j < subresult.indices.size(); ++j)172                 indicesresult.add(new Integer (((Integer )subresult.indices.get(j)).intValue() + result.length()));173             174         }175         176         result = nodes[0].getAnotatedProtocol(null).protocol;177         178         return new AnotatedProtocol(result, indicesresult);179     }180     181 182     //---------------------------------------------------------------183 }` Popular Tags