2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.Config;
23 * a pretty simple ChoiceGenerator that returns a boolean
24 * there is not much use in having a CG type interface (such as
25 * IntChoiceGenerator) since there is hardly a need for a generic type hierarchy
26 * of BooleanChoiceGenerator subtypes - what else can you do with true/false
28 public class BooleanChoiceGenerator extends ChoiceGeneratorBase<Boolean> {
30 // do we evaluate [false, true] or [true, false]
31 protected boolean falseFirst = true;
33 protected int count = -1;
34 protected boolean next;
36 public BooleanChoiceGenerator(Config conf, String id) {
39 falseFirst = conf.getBoolean("cg.boolean.false_first", true);
43 public BooleanChoiceGenerator (String id) {
48 public BooleanChoiceGenerator( String id, boolean falseFirst ){
51 this.falseFirst = falseFirst;
56 public boolean hasMoreChoices () {
57 return !isDone && (count < 1);
61 public Boolean getNextChoice () {
62 return next ? Boolean.TRUE : Boolean.FALSE;
66 public Class<Boolean> getChoiceType() {
71 public void advance () {
79 public Boolean getChoice (int idx){
81 return falseFirst ? Boolean.FALSE : Boolean.TRUE;
83 return falseFirst ? Boolean.TRUE : Boolean.FALSE;
85 throw new IllegalArgumentException("choice index out of range: " + idx);
90 public void reset () {
98 public int getTotalNumberOfChoices () {
103 public int getProcessedNumberOfChoices () {
107 // that is pretty stupid, but for the sake of consistency we make it available
108 Boolean[] getChoices(){
109 Boolean[] vals = new Boolean[2];
110 vals[0] = !falseFirst;
111 vals[1] = falseFirst;
116 // not much use to support reordering, we just have two elements so reverse() will do
118 public boolean isFalseFirst(){
123 * note this should only be called before the first advance since it resets
124 * the enumeration state
126 public void reverse(){
127 falseFirst = !falseFirst;
132 public String toString () {
133 StringBuilder sb = new StringBuilder(getClass().getName());
139 sb.append(",isCascaded:");
140 sb.append(isCascaded);
148 } else if (count == 0) {
160 return sb.toString();
164 public BooleanChoiceGenerator randomize () {
165 next = random.nextBoolean();