KickJava   Java API By Example, From Geeks To Geeks.

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


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 StringValues extends AbstractValues
17 {
18
19    /** The String array. */
20    private String JavaDoc[] values;
21
22    public StringValues(String JavaDoc[] values)
23    {
24       if (values == null)
25       {
26          throw new IllegalArgumentException JavaDoc();
27       }
28       this.values = values;
29    }
30
31    public StringValues(String JavaDoc value)
32    {
33       if (value == null)
34       {
35          throw new IllegalArgumentException JavaDoc();
36       }
37       this.values = new String JavaDoc[]{value};
38    }
39
40    public StringValues()
41    {
42       this.values = new String JavaDoc[1];
43    }
44
45    public String JavaDoc asString()
46    {
47       if (isNull())
48       {
49          return null;
50       }
51       return values[0];
52    }
53
54    public int asInt() throws NullConversionException, FormatConversionException
55    {
56       if (isNull())
57       {
58          throw new NullConversionException();
59       }
60       return Helper.toInt(values[0]);
61    }
62
63    public boolean asBoolean() throws NullConversionException, FormatConversionException
64    {
65       if (isNull())
66       {
67          throw new NullConversionException();
68       }
69       return Helper.toBoolean(values[0]);
70    }
71
72    public String JavaDoc[] asStringArray()
73    {
74       return values;
75    }
76
77    public int[] asIntArray() throws NullConversionException, FormatConversionException
78    {
79       int[] valuesAsInt = new int[values.length];
80       for (int i = 0;i < values.length;i++)
81       {
82          valuesAsInt[i] = Helper.toInt(values[i]);
83       }
84       return valuesAsInt;
85    }
86
87    public boolean[] asBooleanArray() throws NullConversionException, FormatConversionException
88    {
89       boolean[] valuesAsBoolean = new boolean[values.length];
90       for (int i = 0;i < values.length;i++)
91       {
92          valuesAsBoolean[i] = Helper.toBoolean(values[i]);
93       }
94       return valuesAsBoolean;
95    }
96
97    protected Object JavaDoc[] getObjects()
98    {
99       return values;
100    }
101 }
102
Popular Tags