KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: IntConfigParam.java,v 1.25 2006/11/06 20:36:56 linda Exp $
7  */

8
9 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 JavaDoc DEBUG_NAME = IntConfigParam.class.getName();
17
18     private Integer JavaDoc min;
19     private Integer JavaDoc max;
20
21     public IntConfigParam(String JavaDoc configName,
22                           Integer JavaDoc minVal,
23                           Integer JavaDoc maxVal,
24                           Integer JavaDoc defaultValue,
25                           boolean mutable,
26                           boolean forReplication,
27                           String JavaDoc description) {
28         // defaultValue must not be null
29
super(configName, defaultValue.toString(), mutable,
30               forReplication, description);
31         min = minVal;
32         max = maxVal;
33     }
34
35     /*
36      * Self validate. Check mins and maxs
37      */

38     private void validate(Integer JavaDoc value)
39     throws IllegalArgumentException JavaDoc {
40
41         if (value != null) {
42             if (min != null) {
43                 if (value.compareTo(min) < 0) {
44                     throw new IllegalArgumentException JavaDoc
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 JavaDoc
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 JavaDoc value)
68         throws IllegalArgumentException JavaDoc {
69
70         try {
71             validate(new Integer JavaDoc(value));
72         } catch (NumberFormatException JavaDoc e) {
73             throw new IllegalArgumentException JavaDoc
74         (DEBUG_NAME + ": " + value + " not valid value for " + name);
75         }
76     }
77
78     public String JavaDoc getExtraDescription() {
79         StringBuffer JavaDoc minMaxDesc = new StringBuffer JavaDoc();
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