KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > config > ShortConfigParam


1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2005
5 * Sleepycat Software. All rights reserved.
6 *
7 * $Id: ShortConfigParam.java,v 1.19 2004/12/22 14:11:29 linda Exp $
8 */

9
10 package com.sleepycat.je.config;
11
12 /**
13  * A JE configuration parameter with an short value.
14  */

15 public class ShortConfigParam extends ConfigParam {
16     
17     private static final String DEBUG_NAME =
18         ShortConfigParam.class.getName();
19
20     private Short min;
21     private Short max;
22
23     ShortConfigParam(String configName,
24                      Short minVal,
25                      Short maxVal,
26                      Short defaultValue,
27                      boolean mutable,
28                      String description) {
29         // defaultValue must not be null
30
super(configName, defaultValue.toString(), mutable, description);
31
32         min = minVal;
33         max = maxVal;
34     }
35
36     /*
37      * Self validate. Check mins and maxs.
38      */

39     private void validate(Short value)
40     throws IllegalArgumentException {
41
42         if (value != null) {
43             if (min != null) {
44                 if (value.compareTo(min) < 0) {
45                     throw new IllegalArgumentException
46             (DEBUG_NAME + ":" +
47              " param " + name +
48              " doesn't validate, " + value +
49              " is less than min of " + min);
50                 }
51             }
52             if (max != null) {
53                 if (value.compareTo(max) > 0) {
54                     throw new IllegalArgumentException
55             (DEBUG_NAME + ":" +
56              " param " + name +
57              " doesn't validate, " + value +
58              " is greater than max of " +
59              max);
60                 }
61             }
62         }
63     }
64
65     public void validateValue(String value)
66         throws IllegalArgumentException {
67
68         try {
69             validate(new Short(value));
70         }
71         catch (NumberFormatException e) {
72             throw new IllegalArgumentException
73         (DEBUG_NAME + ": " + value +
74          " 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