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.choice;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.vm.ChoiceGeneratorBase;
22 import gov.nasa.jpf.vm.DoubleChoiceGenerator;
25 * ChoiceGenerator instance that produces a simple 3 value enumeration
28 public class DoubleThresholdGenerator extends ChoiceGeneratorBase<Double> implements DoubleChoiceGenerator {
30 protected double[] values = new double[3];
33 public DoubleThresholdGenerator(Config conf, String id) {
36 values[0] = conf.getDouble(id + ".low");
37 values[1] = conf.getDouble(id + ".threshold");
38 values[2] = conf.getDouble(id + ".high");
43 public Double getChoice (int idx){
44 if (idx >= 0 && idx < 3){
47 throw new IllegalArgumentException("choice index out of range: " + idx);
52 public void reset () {
59 public boolean hasMoreChoices () {
60 return !isDone && (count < 2);
64 public Double getNextChoice () {
66 return new Double(values[count]);
68 return new Double(values[0]);
73 public void advance () {
79 public int getTotalNumberOfChoices () {
84 public int getProcessedNumberOfChoices () {
89 public String toString() {
90 StringBuilder sb = new StringBuilder(getClass().getName());
95 for (int i=0; i<3; i++) {
105 return sb.toString();
109 public DoubleThresholdGenerator randomize () {
110 for (int i = values.length - 1; i > 0; i--) {
111 int j = random.nextInt(i + 1);
112 double tmp = values[i];
113 values[i] = values[j];
120 public Class<Double> getChoiceType() {