01: package org.incava.jagol;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: /**
07: * Represents an option that is an float.
08: */
09: public class FloatOption extends NonBooleanOption {
10: private Float value;
11:
12: public FloatOption(String longName, String description) {
13: this (longName, description, null);
14: }
15:
16: public FloatOption(String longName, String description, Float value) {
17: super (longName, description);
18: this .value = value;
19: }
20:
21: /**
22: * Returns the value. This is null if not set.
23: */
24: public Float getValue() {
25: return value;
26: }
27:
28: /**
29: * Sets the value.
30: */
31: public void setValue(Float value) {
32: this .value = value;
33: }
34:
35: /**
36: * Sets the value from the string, for a float type.
37: */
38: public void setValue(String value) throws InvalidTypeException {
39: tr.Ace.log("value: '" + value + "'");
40: try {
41: setValue(new Float(value));
42: } catch (NumberFormatException nfe) {
43: throw new InvalidTypeException(longName
44: + " expects float argument, not '" + value + "'");
45: }
46: }
47:
48: public String toString() {
49: return value == null ? "" : value.toString();
50: }
51:
52: protected String getType() {
53: return "float";
54: }
55:
56: }
|