KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > IntegerValue


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.formula;
21
22 import common.Logger;
23
24 import jxl.Cell;
25 import jxl.biff.IntegerHelper;
26
27 /**
28  * A cell reference in a formula
29  */

30 class IntegerValue extends NumberValue implements ParsedThing
31 {
32   /**
33    * The logger
34    */

35   private static Logger logger = Logger.getLogger(IntegerValue.class);
36
37   /**
38    * The value of this integer
39    */

40   private double value;
41
42   /**
43    * Flag which indicates whether or not this integer is out range
44    */

45   private boolean outOfRange;
46
47   /**
48    * Constructor
49    */

50   public IntegerValue()
51   {
52     outOfRange = false;
53   }
54
55   /**
56    * Constructor for an integer value being read from a string
57    */

58   public IntegerValue(String JavaDoc s)
59   {
60     try
61     {
62       value = Integer.parseInt(s);
63     }
64     catch (NumberFormatException JavaDoc e)
65     {
66       logger.warn(e, e);
67       value = 0;
68     }
69
70     short v = (short) value;
71     outOfRange = (value != v);
72   }
73
74   /**
75    * Reads the ptg data from the array starting at the specified position
76    *
77    * @param data the RPN array
78    * @param pos the current position in the array, excluding the ptg identifier
79    * @return the number of bytes read
80    */

81   public int read(byte[] data, int pos)
82   {
83     value = IntegerHelper.getInt(data[pos], data[pos+1]);
84
85     return 2;
86   }
87
88   /**
89    * Gets the token representation of this item in RPN
90    *
91    * @return the bytes applicable to this formula
92    */

93   byte[] getBytes()
94   {
95     byte[] data = new byte[3];
96     data[0] = Token.INTEGER.getCode();
97
98     IntegerHelper.getTwoBytes((int) value, data, 1);
99
100     return data;
101   }
102
103   /**
104    * Accessor for the value
105    *
106    * @return the value
107    */

108   public double getValue()
109   {
110     return value;
111   }
112
113   /**
114    * Accessor for the out of range flag
115    *
116    * @return TRUE if the value is out of range for an excel integer
117    */

118   boolean isOutOfRange()
119   {
120     return outOfRange;
121   }
122 }
123
Popular Tags