KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: LongConfigParam.java,v 1.24 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 LongConfigParam extends ConfigParam {
15     
16     private static final String JavaDoc DEBUG_NAME = LongConfigParam.class.getName();
17
18     private Long JavaDoc min;
19     private Long JavaDoc max;
20
21     LongConfigParam(String JavaDoc configName,
22                     Long JavaDoc minVal,
23                     Long JavaDoc maxVal,
24                     Long JavaDoc defaultValue,
25                     boolean mutable,
26                     boolean forReplication,
27                     String JavaDoc description) {
28
29         // defaultValue must not be null
30
super(configName, defaultValue.toString(), mutable,
31               forReplication, description);
32         min = minVal;
33         max = maxVal;
34     }
35
36     /*
37      * Self validate. Check mins and maxs
38      */

39     private void validate(Long JavaDoc value)
40     throws IllegalArgumentException JavaDoc {
41
42         if (value != null) {
43             if (min != null) {
44                 if (value.compareTo(min) < 0) {
45                     throw new IllegalArgumentException JavaDoc
46             (DEBUG_NAME + ":" +
47              " param " + name +
48              " doesn't validate, " +
49              value +
50              " is less than min of "
51              + min);
52                 }
53             }
54             if (max != null) {
55                 if (value.compareTo(max) > 0) {
56                     throw new IllegalArgumentException JavaDoc
57             (DEBUG_NAME + ":" +
58              " param " + name +
59              " doesn't validate, " +
60              value +
61              " is greater than max "+
62              " of " + max);
63                 }
64             }
65         }
66     }
67
68     public void validateValue(String JavaDoc value)
69         throws IllegalArgumentException JavaDoc {
70
71         try {
72             validate(new Long JavaDoc(value));
73         } catch (NumberFormatException JavaDoc e) {
74             throw new IllegalArgumentException JavaDoc
75         (DEBUG_NAME + ": " + value + " not valid value for " + name);
76         }
77     }
78
79     public String JavaDoc getExtraDescription() {
80         StringBuffer JavaDoc minMaxDesc = new StringBuffer JavaDoc();
81         if (min != null) {
82             minMaxDesc.append("# minimum = ").append(min);
83         }
84         if (max != null) {
85             if (min != null) {
86                 minMaxDesc.append("\n");
87             }
88             minMaxDesc.append("# maximum = ").append(max);
89         }
90         return minMaxDesc.toString();
91     }
92 }
93
Popular Tags