1 package gov.nasa.jpf.jvm.choice; 21 22 import gov.nasa.jpf.Config; 23 import gov.nasa.jpf.JPFException; 24 import gov.nasa.jpf.jvm.IntChoiceGenerator; 25 import gov.nasa.jpf.jvm.JVM; 26 27 28 32 public class IntIntervalGenerator extends IntChoiceGenerator { 33 34 int min, max; 35 int next; 36 int delta; 37 38 private void init () { 39 if (delta == 0) { 40 throw new JPFException ("IntIntervalGenerator delta value is 0"); 41 } 42 43 if (min > max) { 44 int t = max; 45 max = min; 46 min = t; 47 } 48 49 if (delta > 0) { 50 next = min - delta; 51 } else { 52 next = max + delta; 53 } 54 } 55 56 public IntIntervalGenerator (int min, int max, int delta) { 57 super("int"); 58 59 this.min = min; 60 this.max = max; 61 this.delta = delta; 62 63 init(); 64 } 65 66 public IntIntervalGenerator (int min, int max) { 67 this(min, max, 1); 68 } 69 70 public IntIntervalGenerator (Config conf, String id) { 71 super(id); 72 min = conf.getInt( id + ".min"); 73 max = conf.getInt( id + ".max"); 74 delta = conf.getInt( id + ".delta", 1); 75 76 init(); 77 } 78 79 public int getNextChoice (JVM vm) { 80 return next; 81 } 82 83 public boolean hasMoreChoices (JVM vm) { 84 if (delta > 0) { 85 return (next < max); 86 } else { 87 return (next > min); 88 } 89 } 90 91 public void advance (JVM vm) { 92 next += delta; 93 } 94 } 95 | Popular Tags |