Java API By Example, From Geeks To Geeks.

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

 `1 /* 2  * \$Id: AdjustmentNode.java,v 1.4 2005/07/08 12:04:11 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 import java.util.TreeSet ;21 import java.util.ArrayList ;22 import java.util.TreeMap ;23 import java.util.Iterator ;24 25 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException;26 import SOFA.SOFAnode.Util.DFSRChecker.state.CompositeState;27 import SOFA.SOFAnode.Util.DFSRChecker.state.State;28 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair;29 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs;30 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol;31 32 33 /**34  * Adjustment node represent the adjustment operator35  */36 public class AdjustmentNode extends TreeNode {37 38     /** Creates a new instance of AdjustmentNode */39     public AdjustmentNode(TreeNode node1, TreeNode node2, TreeSet events) {40         //super(getUnion(node1, node2));41 super("(" + node1.protocol + ") " + "|S|" + " (" + node2.protocol + ")");42         this.events = events;43         this.nodes = new TreeNode[2];44         this.nodes[0] = node1;45         this.nodes[1] = node2;46     }47 48     /**49      * 50      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getInitial()51      */52     public State getInitial() {53         State[] states = new State[2];54         states[0] = nodes[0].getInitial();55         states[1] = nodes[1].getInitial();56 57         return new CompositeState(states);58     }59 60     /**61      * 62      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#isAccepting(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)63      */64     public boolean isAccepting(State state) {65         CompositeState cstate = (CompositeState) state;66 67         return (nodes[0].isAccepting(cstate.states[0])) && (nodes[1].isAccepting(cstate.states[1]));68     }69 70     /**71      * 72      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getTransitions(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)73      */74     public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException {75         CompositeState cstate = (CompositeState) state;76 77         TransitionPair[] trans1 = nodes[0].getTransitions(cstate.states[0]).transitions;78         TransitionPair[] trans2 = nodes[1].getTransitions(cstate.states[1]).transitions;79 80         ArrayList result = new ArrayList ();81         TreeMap sync = new TreeMap ();82 83         //we divide the transitions of node1 (states[0]) into two groups84 // - that of not present within the events set and the others85 for (int i = 0; i < trans1.length; ++i) {86             Integer key = new Integer (trans1[i].eventIndex);87             Integer basekey = new Integer (ActionRepository.getPure(key.intValue()));88 89             if (events.contains(basekey))90                 if (sync.containsKey(key))91                     ((ArrayList ) sync.get(key)).add(trans1[i]);92                 else {93                     ArrayList value = new ArrayList ();94                     value.add(trans1[i]);95                     sync.put(new Integer (trans1[i].eventIndex), value);96                 }97             else {98                 State[] states = new State[2];99                 states[0] = trans1[i].state;100                 states[1] = cstate.states[1];101 102                 result.add(new TransitionPair(trans1[i].eventIndex, new CompositeState(states)));103             }104         }105 106         // now complete the result array107 for (int i = 0; i < trans2.length; ++i) {108             Integer key = new Integer (trans2[i].eventIndex);109             Integer basekey = new Integer (ActionRepository.getPure(key.intValue()));110 111             if (events.contains(basekey)) {112                 if (sync.containsKey(key)) {113                     Iterator it = ((ArrayList ) sync.get(key)).iterator();114 115                     while (it.hasNext()) {116                         State[] states = new State[2];117                         states[0] = ((TransitionPair) it.next()).state;118                         states[1] = trans2[i].state;119 120                         result.add(new TransitionPair(trans2[i].eventIndex, new CompositeState(states)));121                     }122                 }123             }124 125             else {126                 State[] states = new State[2];127                 states[0] = cstate.states[0];128                 states[1] = trans2[i].state;129 130                 result.add(new TransitionPair(trans2[i].eventIndex, new CompositeState(states)));131             }132         }133 134         TransitionPair[] result1 = new TransitionPair[result.size()];135         Iterator it = result.iterator();136         int i = 0;137 138         while (it.hasNext())139             result1[i++] = (TransitionPair) it.next();140 141         return new TransitionPairs(result1);142     }143 144     /**145      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getWeight()146      */147     public long getWeight() {148         if (weight != -1)149             return weight;150         else {151             return weight = nodes[0].getWeight() * nodes[1].getWeight();152         }153     }154 155     /**156      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#forwardCut(java.util.TreeSet)157      */158     public TreeNode forwardCut(TreeSet livingevents) {159         TreeSet exlivev = new TreeSet (livingevents);160 161         exlivev.addAll(events);162         TreeSet exlivev2 = new TreeSet (exlivev);163 164         nodes[0] = nodes[0].forwardCut(exlivev);165         nodes[1] = nodes[1].forwardCut(exlivev2);166 167         if ((nodes[0] == null) || (nodes[1] == null))168             return null;169 170         else171             return this;172     }173 174     /**175      * @return the symbolic name of the treenode denoting its type176      */177     public String [] getTypeName() {178         String [] result = { "Adjustment", "/" };179         return result;180     }181 182     /**183      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.node.TreeNode#getAnotatedProtocol(SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.state.State)184      */185     public AnotatedProtocol getAnotatedProtocol(State state) {186         throw new RuntimeException (this.getClass().getName() + ".getAnotatedProtocol is not implemented");187     }188 189     //--------------------------------------------------------------------------190 191     /**192      * The set of event for composition operator193      */194     final private TreeSet events;195 196 197 }` Popular Tags