01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: IntConfigParam.java,v 1.25.2.3 2008/01/07 15:14:09 cwl Exp $
07: */
08:
09: package com.sleepycat.je.config;
10:
11: /**
12: * A JE configuration parameter with an integer value.
13: */
14: public class IntConfigParam extends ConfigParam {
15:
16: private static final String DEBUG_NAME = IntConfigParam.class
17: .getName();
18:
19: private Integer min;
20: private Integer max;
21:
22: public IntConfigParam(String configName, Integer minVal,
23: Integer maxVal, Integer defaultValue, boolean mutable,
24: boolean forReplication, String description) {
25: // defaultValue must not be null
26: super (configName, defaultValue.toString(), mutable,
27: forReplication, description);
28: min = minVal;
29: max = maxVal;
30: }
31:
32: /*
33: * Self validate. Check mins and maxs
34: */
35: private void validate(Integer value)
36: throws IllegalArgumentException {
37:
38: if (value != null) {
39: if (min != null) {
40: if (value.compareTo(min) < 0) {
41: throw new IllegalArgumentException(DEBUG_NAME + ":"
42: + " param " + name + " doesn't validate, "
43: + value + " is less than min of " + min);
44: }
45: }
46: if (max != null) {
47: if (value.compareTo(max) > 0) {
48: throw new IllegalArgumentException(DEBUG_NAME + ":"
49: + " param " + name + " doesn't validate, "
50: + value + " is greater than max of " + max);
51: }
52: }
53: }
54: }
55:
56: public void validateValue(String value)
57: throws IllegalArgumentException {
58:
59: try {
60: validate(new Integer(value));
61: } catch (NumberFormatException e) {
62: throw new IllegalArgumentException(DEBUG_NAME + ": "
63: + value + " not valid value for " + name);
64: }
65: }
66:
67: public String getExtraDescription() {
68: StringBuffer minMaxDesc = new StringBuffer();
69: if (min != null) {
70: minMaxDesc.append("# minimum = ").append(min);
71: }
72: if (max != null) {
73: if (min != null) {
74: minMaxDesc.append("\n");
75: }
76: minMaxDesc.append("# maximum = ").append(max);
77: }
78: return minMaxDesc.toString();
79: }
80:
81: }
|