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