KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > choice > TwoIntChoice


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

20 /*
21  * Created on Sep 7, 2005
22  *
23  * TODO To change the template for this generated file go to
24  * Window - Preferences - Java - Code Style - Code Templates
25  */

26 package gov.nasa.jpf.jvm.choice;
27
28 import gov.nasa.jpf.Config;
29 import gov.nasa.jpf.jvm.IntChoiceGenerator;
30 import gov.nasa.jpf.jvm.JVM;
31
32 /**
33  * @author jpenix
34  *
35  * designed to choose return values from a function calls
36  */

37 public class TwoIntChoice extends IntChoiceGenerator {
38
39     int firstValue = 100;
40     int secondValue = 200;
41
42     String JavaDoc firstMsg = "pass";
43     String JavaDoc secondMsg = "fail";
44     
45     int state = -1;
46     
47     public TwoIntChoice(Config conf, String JavaDoc id) {
48           super(id);
49           firstValue = conf.getInt( id + ".firstValue");
50           firstMsg = conf.getString( id + ".firstMessage");
51           secondValue = conf.getInt( id + ".secondValue");
52           secondMsg = conf.getString( id + ".secondMessage");
53     }
54     
55     /* (non-Javadoc)
56      * @see gov.nasa.jpf.jvm.IntChoiceGenerator#getNextChoice()
57      */

58     public int getNextChoice(JVM vm) {
59         int ret;
60         switch (state){
61             case 0: {
62                 ret = firstValue;
63                 vm.println(firstMsg);
64                 break;
65             }
66             case 1: {
67                 ret = secondValue;
68                 vm.println(secondMsg);
69                 break;
70             }
71             default: {
72                 ret = 99;
73             }
74         }
75         return ret;
76     }
77
78     /* (non-Javadoc)
79      * @see gov.nasa.jpf.jvm.ChoiceGenerator#hasMoreChoices()
80      */

81     public boolean hasMoreChoices(JVM vm) {
82         return state < 1;
83     }
84
85     /* (non-Javadoc)
86      * @see gov.nasa.jpf.jvm.ChoiceGenerator#advance(gov.nasa.jpf.jvm.JVM)
87      */

88     public void advance(JVM vm) {
89         state++;
90         //vm.println("advancing to state "+state);
91
}
92
93 }
94
Popular Tags