KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > types > NumericResult


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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
17 package org.apache.cocoon.components.elementprocessor.types;
18
19 import java.io.IOException JavaDoc;
20
21 /**
22  * This class holds the result of a numeric conversion. The result is
23  * either a valid value, or an IOException that was created by the
24  * numeric converter
25  *
26  * @author Marc Johnson (marc_johnson27591@hotmail.com)
27  * @version CVS $Id: NumericResult.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29 public class NumericResult
30 {
31     private Number JavaDoc _value;
32     private IOException JavaDoc _exception;
33
34     /**
35      * Constructor
36      *
37      * @param value the numeric value
38      */

39
40     public NumericResult(final Number JavaDoc value) {
41         this();
42         _value = value;
43     }
44
45     /**
46      * Constructor
47      *
48      * @param exception the exception to be thrown
49      */

50
51     public NumericResult(final IOException JavaDoc exception) {
52         this();
53         _exception = exception;
54     }
55
56     private NumericResult() {
57         _value = null;
58         _exception = null;
59     }
60
61     /**
62      * Get the value, if possible, as an int
63      *
64      * @return the value, as an int
65      *
66      * @exception IOException if there was a problem converting the
67      * number
68      */

69
70     public int intValue() throws IOException JavaDoc {
71         return value().intValue();
72     }
73
74     /**
75      * Get the value, if possible, as a double
76      *
77      * @return the value, as a double
78      *
79      * @exception IOException if there was a problem converting the
80      * number
81      */

82
83     public double doubleValue() throws IOException JavaDoc {
84         return value().doubleValue();
85     }
86
87     private Number JavaDoc value() throws IOException JavaDoc {
88         if (_exception != null) {
89             throw _exception;
90         }
91         return _value;
92     }
93 } // end public class NumericResult
94
Popular Tags