2 /* ====================================================================
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================== */
23 * Created on October 1, 2001, 8:01 PM
25 package org
.apache
.poi
.hssf
.record
;
27 import org
.apache
.poi
.util
.LittleEndian
;
28 import org
.apache
.poi
.hssf
.record
.Record
;
31 * Contains a numeric cell value. <P>
32 * REFERENCE: PG 334 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
33 * @author Andrew C. Oliver (acoliver at apache dot org)
34 * @author Jason Height (jheight at chariot dot net dot au)
38 public class NumberRecord
40 implements CellValueRecordInterface
, Comparable
42 public static final short sid
= 0x203;
43 //private short field_1_row;
44 private int field_1_row
;
45 private short field_2_col
;
46 private short field_3_xf
;
47 private double field_4_value
;
49 /** Creates new NumberRecord */
55 * Constructs a Number record and sets its fields appropriately.
57 * @param in the RecordInputstream to read the record from
60 public NumberRecord(RecordInputStream in
)
66 * @param in the RecordInputstream to read the record from
69 protected void fillFields(RecordInputStream in
)
71 //field_1_row = LittleEndian.getShort(data, 0 + offset);
72 field_1_row
= in
.readUShort();
73 field_2_col
= in
.readShort();
74 field_3_xf
= in
.readShort();
75 field_4_value
= in
.readDouble();
78 //public void setRow(short row)
79 public void setRow(int row
)
84 public void setColumn(short col
)
90 * set the index to the ExtendedFormat
91 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
92 * @param xf index to the XF record
95 public void setXFIndex(short xf
)
101 * set the value for the cell
103 * @param value double representing the value
106 public void setValue(double value
)
108 field_4_value
= value
;
111 //public short getRow()
117 public short getColumn()
123 * get the index to the ExtendedFormat
124 * @see org.apache.poi.hssf.record.ExtendedFormatRecord
125 * @return index to the XF record
128 public short getXFIndex()
134 * get the value for the cell
136 * @return double representing the value
139 public double getValue()
141 return field_4_value
;
144 public String
toString()
146 StringBuffer buffer
= new StringBuffer();
148 buffer
.append("[NUMBER]\n");
149 buffer
.append(" .row = ")
150 .append(Integer
.toHexString(getRow())).append("\n");
151 buffer
.append(" .col = ")
152 .append(Integer
.toHexString(getColumn())).append("\n");
153 buffer
.append(" .xfindex = ")
154 .append(Integer
.toHexString(getXFIndex())).append("\n");
155 buffer
.append(" .value = ").append(getValue())
157 buffer
.append("[/NUMBER]\n");
158 return buffer
.toString();
162 * called by the class that is responsible for writing this sucker.
163 * Subclasses should implement this so that their data is passed back in a
166 * @return byte array containing instance data
169 public int serialize(int offset
, byte [] data
)
171 LittleEndian
.putShort(data
, 0 + offset
, sid
);
172 LittleEndian
.putShort(data
, 2 + offset
, ( short ) 14);
173 //LittleEndian.putShort(data, 4 + offset, getRow());
174 LittleEndian
.putShort(data
, 4 + offset
, ( short ) getRow());
175 LittleEndian
.putShort(data
, 6 + offset
, getColumn());
176 LittleEndian
.putShort(data
, 8 + offset
, getXFIndex());
177 LittleEndian
.putDouble(data
, 10 + offset
, getValue());
178 return getRecordSize();
181 public int getRecordSize()
187 * called by constructor, should throw runtime exception in the event of a
188 * record passed with a differing ID.
190 * @param id alleged id for this record
193 protected void validateSid(short id
)
197 throw new RecordFormatException("NOT A Number RECORD");
201 public short getSid()
206 public boolean isBefore(CellValueRecordInterface i
)
208 if (this.getRow() > i
.getRow())
212 if ((this.getRow() == i
.getRow())
213 && (this.getColumn() > i
.getColumn()))
217 if ((this.getRow() == i
.getRow())
218 && (this.getColumn() == i
.getColumn()))
225 public boolean isAfter(CellValueRecordInterface i
)
227 if (this.getRow() < i
.getRow())
231 if ((this.getRow() == i
.getRow())
232 && (this.getColumn() < i
.getColumn()))
236 if ((this.getRow() == i
.getRow())
237 && (this.getColumn() == i
.getColumn()))
244 public boolean isEqual(CellValueRecordInterface i
)
246 return ((this.getRow() == i
.getRow())
247 && (this.getColumn() == i
.getColumn()));
250 public boolean isInValueSection()
255 public boolean isValue()
260 public int compareTo(Object obj
)
262 CellValueRecordInterface loc
= ( CellValueRecordInterface
) obj
;
264 if ((this.getRow() == loc
.getRow())
265 && (this.getColumn() == loc
.getColumn()))
269 if (this.getRow() < loc
.getRow())
273 if (this.getRow() > loc
.getRow())
277 if (this.getColumn() < loc
.getColumn())
281 if (this.getColumn() > loc
.getColumn())
288 public boolean equals(Object obj
)
290 if (!(obj
instanceof CellValueRecordInterface
))
294 CellValueRecordInterface loc
= ( CellValueRecordInterface
) obj
;
296 if ((this.getRow() == loc
.getRow())
297 && (this.getColumn() == loc
.getColumn()))
304 public Object
clone() {
305 NumberRecord rec
= new NumberRecord();
306 rec
.field_1_row
= field_1_row
;
307 rec
.field_2_col
= field_2_col
;
308 rec
.field_3_xf
= field_3_xf
;
309 rec
.field_4_value
= field_4_value
;