KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > common > value > IntegerValue


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.common.value;
10
11
12 /**
13  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
14  * @version $Revision: 1.1.1.1 $
15  */

16 public class IntegerValue extends AbstractValue
17 {
18
19    private static final Integer JavaDoc[] EMPTY_ARRAY_INTEGER = new Integer JavaDoc[0];
20
21    private Integer JavaDoc value;
22
23    public IntegerValue()
24    {
25       this.value = null;
26    }
27
28    public IntegerValue(String JavaDoc value)
29    {
30       if (value == null)
31       {
32          throw new IllegalArgumentException JavaDoc();
33       }
34       try
35       {
36          this.value = new Integer JavaDoc(value);
37       }
38       catch (NumberFormatException JavaDoc e)
39       {
40          throw new IllegalArgumentException JavaDoc();
41       }
42    }
43
44    public IntegerValue(int _value)
45    {
46       this.value = new Integer JavaDoc(_value);
47    }
48
49    public IntegerValue(Integer JavaDoc value)
50    {
51       if (value == null)
52       {
53          throw new IllegalArgumentException JavaDoc();
54       }
55       this.value = value;
56    }
57
58    public String JavaDoc asString()
59    {
60       return String.valueOf(value);
61    }
62
63    public int asInt() throws NullConversionException, FormatConversionException
64    {
65       if (value == null)
66       {
67          throw new NullConversionException();
68       }
69       return value.intValue();
70    }
71
72    public Object JavaDoc asObject()
73    {
74       return value;
75    }
76
77    public Object JavaDoc[] asObjectArray()
78    {
79       if (isNull())
80       {
81          return EMPTY_ARRAY_INTEGER;
82       }
83       return new Integer JavaDoc[]{value};
84    }
85 }
86
Popular Tags