KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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