View Javadoc
1   /*
2    * Copyright 2004 Diogo Quintela (dquintela@users.sourceforge.net)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.whatsnew.options;
17  
18  /***
19   * <p>
20   * An Option value
21   * </p>
22   *
23   * @author <a href="mailto:dquintela@users.sourceforge.net">Diogo Quintela</a>
24   * @version $Id: OptionValue.java,v 1.1 2004/05/13 01:22:30 dquintela Exp $
25   */
26  public class OptionValue {
27      /*** The option value */
28      private Object value;
29  
30      /***
31       * Creates a new OptionValue object.
32       *
33       * @param value The option value
34       *
35       * @throws NullPointerException if (value == null)
36       */
37      public OptionValue(Object value) {
38          if (value == null) {
39              throw new NullPointerException();
40          }
41          this.value = value;
42      }
43  
44      /***
45       * Get as Boolean
46       *
47       * @return Option Value
48       */
49      public Boolean getBoolean() {
50          return (Boolean) value;
51      }
52  
53      /***
54       * Get as Double
55       *
56       * @return Option Value
57       */
58      public Double getDouble() {
59          return (Double) value;
60      }
61  
62      /***
63       * Get as Integer
64       *
65       * @return Option Value
66       */
67      public Integer getInteger() {
68          return (Integer) value;
69      }
70  
71      /***
72       * Get as Long
73       *
74       * @return Option Value
75       */
76      public Long getLong() {
77          return (Long) value;
78      }
79  
80      /***
81       * Get as Number
82       *
83       * @return Option Value
84       */
85      public Number getNumber() {
86          return (Number) value;
87      }
88  
89      /***
90       * Get as String
91       *
92       * @return Option Value
93       */
94      public String getString() {
95          return value.toString();
96      }
97  
98      /***
99       * Get as boolean
100      *
101      * @return Option Value
102      */
103     public boolean booleanValue() {
104         return getBoolean().booleanValue();
105     }
106 
107     /***
108      * Get as double
109      *
110      * @return Option Value
111      */
112     public double doubleValue() {
113         return getNumber().doubleValue();
114     }
115 
116     /***
117      * Get as int
118      *
119      * @return Option Value
120      */
121     public int intValue() {
122         return getNumber().intValue();
123     }
124 }
125 // EOF