KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > jagol > IntegerOption


1 package org.incava.jagol;
2
3 import java.io.*;
4 import java.util.*;
5
6
7 /**
8  * Represents an option that is an integer.
9  */

10 public class IntegerOption extends NonBooleanOption
11 {
12     private Integer JavaDoc value;
13     
14     public IntegerOption(String JavaDoc longName, String JavaDoc description)
15     {
16         this(longName, description, null);
17     }
18
19     public IntegerOption(String JavaDoc longName, String JavaDoc description, Integer JavaDoc value)
20     {
21         super(longName, description);
22         this.value = value;
23     }
24
25     /**
26      * Returns the value. This is null if not set.
27      */

28     public Integer JavaDoc getValue()
29     {
30         return value;
31     }
32
33     /**
34      * Sets the value.
35      */

36     public void setValue(Integer JavaDoc value)
37     {
38         this.value = value;
39     }
40
41     /**
42      * Sets the value from the string, for an integer type.
43      */

44     public void setValue(String JavaDoc value) throws InvalidTypeException
45     {
46         try {
47             setValue(new Integer JavaDoc(value));
48         }
49         catch (NumberFormatException JavaDoc nfe) {
50             throw new InvalidTypeException(getLongName() + " expects integer argument, not '" + value + "'");
51         }
52     }
53
54     public String JavaDoc toString()
55     {
56         return value == null ? "" : value.toString();
57     }
58
59     protected String JavaDoc getType()
60     {
61         return "integer";
62     }
63
64 }
65
Popular Tags