KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > ltl > trans > State


1
2 //
3
// Copyright (C) 2005 United States Government as represented by the
4
// Administrator of the National Aeronautics and Space Administration
5
// (NASA). All Rights Reserved.
6
//
7
// This software is distributed under the NASA Open Source Agreement
8
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
9
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
10
// directory tree for the complete NOSA document.
11
//
12
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
13
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
14
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
15
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
16
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
17
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
18
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
19
//
20

21 //Written by Dimitra Giannakopoulou, 29 Jan 2001
22
package gov.nasa.ltl.trans;
23
24 import java.util.*;
25
26
27 /**
28  * DOCUMENT ME.
29  */

30 class State implements Comparable JavaDoc {
31   private int representativeId = -1;
32   private LinkedList transitions;
33   private BitSet accepting;
34   private boolean safety_acceptance;
35
36   public State (BitSet acc) {
37     transitions = new LinkedList();
38     accepting = acc;
39     safety_acceptance = false;
40   }
41
42   public State (BitSet acc, int equivId) {
43     transitions = new LinkedList();
44     accepting = acc;
45     safety_acceptance = false;
46     representativeId = equivId;
47   }
48
49   public State () {
50     transitions = new LinkedList();
51     accepting = null;
52     safety_acceptance = false;
53   }
54
55   public State (int equivId) {
56     transitions = new LinkedList();
57     accepting = null;
58     safety_acceptance = false;
59     representativeId = equivId;
60   }
61
62   /* public boolean isAccepting()
63      {
64      return accepting;
65      }
66    */

67   public void FSPoutput () {
68     ListIterator iter = transitions.listIterator(0);
69     Transition nextTrans;
70     boolean first_trans = true;
71
72     while (iter.hasNext()) {
73       nextTrans = (Transition) iter.next();
74
75       if (first_trans) {
76         System.out.print("(");
77         first_trans = false;
78       } else {
79         System.out.print("|");
80       }
81
82       nextTrans.FSPoutput();
83     }
84   }
85
86   public void SMoutput (gov.nasa.ltl.graph.Node[] nodes,
87                         gov.nasa.ltl.graph.Node node) {
88     ListIterator iter = transitions.listIterator(0);
89     Transition nextTrans;
90     boolean first_trans = true;
91
92     while (iter.hasNext()) {
93       nextTrans = (Transition) iter.next();
94       nextTrans.SMoutput(nodes, node);
95     }
96   }
97
98   public boolean accepts (int i) {
99     return (!(accepting.get(i)));
100
101     // because in my accepting array 0 corresponds to accepting
102
}
103
104   // <2do> pcm - CodeGuide Sapphire bug - need to explicitly qualify Transition
105
// or it's mocking its use in Node
106
public void add (Transition trans) {
107     transitions.add(trans);
108   }
109
110   public int compareTo (Object JavaDoc f) {
111     if (this == f) {
112       return 0;
113     } else {
114       return 1;
115     }
116   }
117
118   public int get_representativeId () {
119     return representativeId;
120   }
121
122   public boolean is_safe () {
123     return safety_acceptance;
124   }
125
126   public void set_representativeId (int id) {
127     representativeId = id;
128   }
129
130   public void step (Hashtable ProgramState, TreeSet newStates,
131                     State[] automaton) {
132     ListIterator iter = transitions.listIterator(0);
133     Transition nextTrans;
134
135     while (iter.hasNext()) {
136       nextTrans = (Transition) iter.next();
137
138       if (nextTrans.enabled(ProgramState)) {
139         newStates.add(automaton[nextTrans.goesTo()]);
140       }
141     }
142   }
143
144   public void update_acc (BitSet acc) {
145     accepting = acc;
146   }
147
148   public void update_acc (BitSet acc, int equivId) {
149     accepting = acc;
150     representativeId = equivId;
151   }
152
153   public void update_safety_acc (boolean val) {
154     safety_acceptance = val;
155   }
156 }
Popular Tags