1 8 9 package com.sleepycat.je.config; 10 11 14 public class IntConfigParam extends ConfigParam { 15 16 private static final String DEBUG_NAME = IntConfigParam.class.getName(); 17 18 private Integer min; 19 private Integer max; 20 21 public IntConfigParam(String configName, 22 Integer minVal, 23 Integer maxVal, 24 Integer defaultValue, 25 boolean mutable, 26 boolean forReplication, 27 String description) { 28 super(configName, defaultValue.toString(), mutable, 30 forReplication, description); 31 min = minVal; 32 max = maxVal; 33 } 34 35 38 private void validate(Integer value) 39 throws IllegalArgumentException { 40 41 if (value != null) { 42 if (min != null) { 43 if (value.compareTo(min) < 0) { 44 throw new IllegalArgumentException 45 (DEBUG_NAME + ":" + 46 " param " + name + 47 " doesn't validate, " + 48 value + 49 " is less than min of "+ 50 min); 51 } 52 } 53 if (max != null) { 54 if (value.compareTo(max) > 0) { 55 throw new IllegalArgumentException 56 (DEBUG_NAME + ":" + 57 " param " + name + 58 " doesn't validate, " + 59 value + 60 " is greater than max of " + 61 max); 62 } 63 } 64 } 65 } 66 67 public void validateValue(String value) 68 throws IllegalArgumentException { 69 70 try { 71 validate(new Integer (value)); 72 } catch (NumberFormatException e) { 73 throw new IllegalArgumentException 74 (DEBUG_NAME + ": " + value + " not valid value for " + name); 75 } 76 } 77 78 public String getExtraDescription() { 79 StringBuffer minMaxDesc = new StringBuffer (); 80 if (min != null) { 81 minMaxDesc.append("# minimum = ").append(min); 82 } 83 if (max != null) { 84 if (min != null) { 85 minMaxDesc.append("\n"); 86 } 87 minMaxDesc.append("# maximum = ").append(max); 88 } 89 return minMaxDesc.toString(); 90 } 91 92 } 93 | Popular Tags |