34 private static final double ADDITIONAL_TEST_DOUBLE_NEGATIVE = -1.5; 35 private static final double ADDITIONAL_TEST_DOUBLE_ZERO = 0.0; 36 private static final double ADDITIONAL_TEST_DOUBLE_POSITIVE = 1.75; 37 38 /** 39 * Mininum option value 40 */ 41 private double min; 42 /** 43 * Maximum option value 44 */ 45 private double max; 46 47 /** 48 * Initialize double option with passed name 49 * 50 * @param name name of the option 51 */ 52 DoubleJVMOption(String name) { 53 this.name = name; 54 } 55 56 /** 57 * Initialize double option with passed name, min and max values 58 * 59 * @param name name of the option 60 * @param min minimum value of the option 61 * @param max maximum value of the option 62 */ 63 public DoubleJVMOption(String name, double min, double max) { 64 this(name); 65 this.min = min; 66 this.max = max; 67 } 68 69 /** 70 * Set new minimum option value 71 * 72 * @param min new minimum value 73 */ 74 @Override 75 void setMin(String min) { 76 this.min = new Double(min); 77 } 78 79 /** 80 * Get string with minimum value of the option 81 * 82 * @return string with minimum value of the option 83 */ 84 @Override 85 String getMin() { 86 return String.format("%f", min); 87 } 88 89 /** 90 * Set new maximum option value 91 * 92 * @param max new maximum value 93 */ 94 @Override 95 void setMax(String max) { 96 this.max = new Double(max); 97 } 98 99 /** 100 * Get string with maximum value of the option 101 * 102 * @return string with maximum value of the option 103 */ 104 @Override 105 String getMax() { 106 return String.format("%f", max); 107 } 108 109 /** 110 * Return list of strings with valid option values which used for testing 111 * using jcmd, attach and etc. 112 * 113 * @return list of strings which contain valid values for option 114 */ 115 @Override 116 protected List<String> getValidValues() { 117 List<String> validValues = new ArrayList<>(); 118 119 validValues.add(String.format("%f", min)); 120 validValues.add(String.format("%f", max)); 121 122 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_NEGATIVE) < 0) 123 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_NEGATIVE) > 0)) { 124 validValues.add(String.format("%f", ADDITIONAL_TEST_DOUBLE_NEGATIVE)); 125 } 126 127 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_ZERO) < 0) 128 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_ZERO) > 0)) { 129 validValues.add(String.format("%f", ADDITIONAL_TEST_DOUBLE_ZERO)); 130 } 131 132 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_POSITIVE) < 0) 133 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_POSITIVE) > 0)) { 134 validValues.add(String.format("%f", ADDITIONAL_TEST_DOUBLE_POSITIVE)); 135 } 136 137 return validValues; 138 } 139 140 /** 141 * Return list of strings with invalid option values which used for testing 142 * using jcmd, attach and etc. 143 * 144 * @return list of strings which contain invalid values for option 145 */ 146 @Override 147 protected List<String> getInvalidValues() { 148 List<String> invalidValues = new ArrayList<>(); 149 150 if (Double.compare(min, Double.MIN_VALUE) != 0) { 151 if ((Double.compare(min, 0.0) > 0) 152 && (Double.isNaN(min * 0.999) == false)) { 153 invalidValues.add(String.format("%f", min * 0.999)); 154 } else if ((Double.compare(min, 0.0) < 0) 155 && (Double.isNaN(min * 1.001) == false)) { 156 invalidValues.add(String.format("%f", min * 1.001)); 157 } 158 } 159 160 if (Double.compare(max, Double.MAX_VALUE) != 0) { 161 if ((Double.compare(max, 0.0) > 0) 162 && (Double.isNaN(max * 1.001) == false)) { 163 invalidValues.add(String.format("%f", max * 1.001)); 164 } else if ((Double.compare(max, 0.0) < 0) 165 && (Double.isNaN(max * 0.999) == false)) { 166 invalidValues.add(String.format("%f", max * 0.999)); 167 } 168 } 169 170 return invalidValues; 171 } 172 173 /** 174 * Return expected error message for option with value "value" when it used 175 * on command line with passed value 176 * 177 * @param value option value 178 * @return expected error message 179 */ 180 @Override 181 protected String getErrorMessageCommandLine(String value) { 182 String errorMsg; 183 184 if (withRange) { 185 /* Option have defined range in VM */ 186 errorMsg = "is outside the allowed range"; | 34 private static final double ADDITIONAL_TEST_DOUBLE_NEGATIVE = -1.5; 35 private static final double ADDITIONAL_TEST_DOUBLE_ZERO = 0.0; 36 private static final double ADDITIONAL_TEST_DOUBLE_POSITIVE = 1.75; 37 38 /** 39 * Mininum option value 40 */ 41 private double min; 42 /** 43 * Maximum option value 44 */ 45 private double max; 46 47 /** 48 * Initialize double option with passed name 49 * 50 * @param name name of the option 51 */ 52 DoubleJVMOption(String name) { 53 this.name = name; 54 min = Double.MIN_VALUE; 55 max = Double.MAX_VALUE; 56 } 57 58 /** 59 * Initialize double option with passed name, min and max values 60 * 61 * @param name name of the option 62 * @param min minimum value of the option 63 * @param max maximum value of the option 64 */ 65 public DoubleJVMOption(String name, double min, double max) { 66 this(name); 67 this.min = min; 68 this.max = max; 69 } 70 71 /** 72 * Set new minimum option value 73 * 74 * @param min new minimum value 75 */ 76 @Override 77 void setMin(String min) { 78 this.min = new Double(min); 79 } 80 81 /** 82 * Get string with minimum value of the option 83 * 84 * @return string with minimum value of the option 85 */ 86 @Override 87 String getMin() { 88 return formatValue(min); 89 } 90 91 /** 92 * Set new maximum option value 93 * 94 * @param max new maximum value 95 */ 96 @Override 97 void setMax(String max) { 98 this.max = new Double(max); 99 } 100 101 /** 102 * Get string with maximum value of the option 103 * 104 * @return string with maximum value of the option 105 */ 106 @Override 107 String getMax() { 108 return formatValue(max); 109 } 110 111 private String formatValue(double value) { 112 return String.format("%f", value); 113 } 114 115 /** 116 * Return list of strings with valid option values which used for testing 117 * using jcmd, attach and etc. 118 * 119 * @return list of strings which contain valid values for option 120 */ 121 @Override 122 protected List<String> getValidValues() { 123 List<String> validValues = new ArrayList<>(); 124 125 validValues.add(formatValue(min)); 126 validValues.add(formatValue(max)); 127 128 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_NEGATIVE) < 0) 129 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_NEGATIVE) > 0)) { 130 validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_NEGATIVE)); 131 } 132 133 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_ZERO) < 0) 134 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_ZERO) > 0)) { 135 validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_ZERO)); 136 } 137 138 if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_POSITIVE) < 0) 139 && (Double.compare(max, ADDITIONAL_TEST_DOUBLE_POSITIVE) > 0)) { 140 validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_POSITIVE)); 141 } 142 143 return validValues; 144 } 145 146 /** 147 * Return list of strings with invalid option values which used for testing 148 * using jcmd, attach and etc. 149 * 150 * @return list of strings which contain invalid values for option 151 */ 152 @Override 153 protected List<String> getInvalidValues() { 154 List<String> invalidValues = new ArrayList<>(); 155 156 if (withRange) { 157 /* Return invalid values only for options which have defined range in VM */ 158 if (Double.compare(min, Double.MIN_VALUE) != 0) { 159 if ((Double.compare(min, 0.0) > 0) 160 && (Double.isNaN(min * 0.999) == false)) { 161 invalidValues.add(formatValue(min * 0.999)); 162 } else if ((Double.compare(min, 0.0) < 0) 163 && (Double.isNaN(min * 1.001) == false)) { 164 invalidValues.add(formatValue(min * 1.001)); 165 } 166 } 167 168 if (Double.compare(max, Double.MAX_VALUE) != 0) { 169 if ((Double.compare(max, 0.0) > 0) 170 && (Double.isNaN(max * 1.001) == false)) { 171 invalidValues.add(formatValue(max * 1.001)); 172 } else if ((Double.compare(max, 0.0) < 0) 173 && (Double.isNaN(max * 0.999) == false)) { 174 invalidValues.add(formatValue(max * 0.999)); 175 } 176 } 177 } 178 179 return invalidValues; 180 } 181 182 /** 183 * Return expected error message for option with value "value" when it used 184 * on command line with passed value 185 * 186 * @param value option value 187 * @return expected error message 188 */ 189 @Override 190 protected String getErrorMessageCommandLine(String value) { 191 String errorMsg; 192 193 if (withRange) { 194 /* Option have defined range in VM */ 195 errorMsg = "is outside the allowed range"; |