PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/BoolErrRecord.java

http://github.com/openmicroscopy/bioformats
Java | 406 lines | 233 code | 51 blank | 122 comment | 41 complexity | 1e5d946f2d083b80a5832b1d60cf576a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. /*
  38. * BoolErrRecord.java
  39. *
  40. * Created on January 19, 2002, 9:30 AM
  41. */
  42. package loci.poi.hssf.record;
  43. import loci.poi.util.LittleEndian;
  44. /**
  45. * Creates new BoolErrRecord. <P>
  46. * REFERENCE: PG ??? Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  47. * @author Michael P. Harhen
  48. * @author Jason Height (jheight at chariot dot net dot au)
  49. * @version 2.0-pre
  50. */
  51. public class BoolErrRecord
  52. extends Record
  53. implements CellValueRecordInterface, Comparable
  54. {
  55. public final static short sid = 0x205;
  56. //private short field_1_row;
  57. private int field_1_row;
  58. private short field_2_column;
  59. private short field_3_xf_index;
  60. private byte field_4_bBoolErr;
  61. private byte field_5_fError;
  62. /** Creates new BoolErrRecord */
  63. public BoolErrRecord()
  64. {
  65. }
  66. /**
  67. * Constructs a BoolErr record and sets its fields appropriately.
  68. *
  69. * @param in the RecordInputstream to read the record from
  70. */
  71. public BoolErrRecord(RecordInputStream in)
  72. {
  73. super(in);
  74. }
  75. /**
  76. * @param in the RecordInputstream to read the record from
  77. */
  78. protected void fillFields(RecordInputStream in)
  79. {
  80. //field_1_row = LittleEndian.getShort(data, 0 + offset);
  81. field_1_row = in.readUShort();
  82. field_2_column = in.readShort();
  83. field_3_xf_index = in.readShort();
  84. field_4_bBoolErr = in.readByte();
  85. field_5_fError = in.readByte();
  86. }
  87. //public void setRow(short row)
  88. public void setRow(int row)
  89. {
  90. field_1_row = row;
  91. }
  92. public void setColumn(short col)
  93. {
  94. field_2_column = col;
  95. }
  96. /**
  97. * set the index to the ExtendedFormat
  98. * @see loci.poi.hssf.record.ExtendedFormatRecord
  99. * @param xf index to the XF record
  100. */
  101. public void setXFIndex(short xf)
  102. {
  103. field_3_xf_index = xf;
  104. }
  105. /**
  106. * set the boolean value for the cell
  107. *
  108. * @param value representing the boolean value
  109. */
  110. public void setValue(boolean value)
  111. {
  112. field_4_bBoolErr = value ? ( byte ) 1
  113. : ( byte ) 0;
  114. field_5_fError = ( byte ) 0;
  115. }
  116. /**
  117. * set the error value for the cell
  118. *
  119. * @param value error representing the error value
  120. * this value can only be 0,7,15,23,29,36 or 42
  121. * see bugzilla bug 16560 for an explanation
  122. */
  123. public void setValue(byte value)
  124. {
  125. if ( (value==0)||(value==7)||(value==15)||(value==23)||(value==29)||(value==36)||(value==42)) {
  126. field_4_bBoolErr = value;
  127. field_5_fError = ( byte ) 1;
  128. } else {
  129. throw new RuntimeException("Error Value can only be 0,7,15,23,29,36 or 42. It cannot be "+value);
  130. }
  131. }
  132. //public short getRow()
  133. public int getRow()
  134. {
  135. return field_1_row;
  136. }
  137. public short getColumn()
  138. {
  139. return field_2_column;
  140. }
  141. /**
  142. * get the index to the ExtendedFormat
  143. * @see loci.poi.hssf.record.ExtendedFormatRecord
  144. * @return index to the XF record
  145. */
  146. public short getXFIndex()
  147. {
  148. return field_3_xf_index;
  149. }
  150. /**
  151. * get the value for the cell
  152. *
  153. * @return boolean representing the boolean value
  154. */
  155. public boolean getBooleanValue()
  156. {
  157. return (field_4_bBoolErr != 0);
  158. }
  159. /**
  160. * get the error value for the cell
  161. *
  162. * @return byte representing the error value
  163. */
  164. public byte getErrorValue()
  165. {
  166. return field_4_bBoolErr;
  167. }
  168. /**
  169. * Indicates whether the call holds a boolean value
  170. *
  171. * @return boolean true if the cell holds a boolean value
  172. */
  173. public boolean isBoolean()
  174. {
  175. return (field_5_fError == ( byte ) 0);
  176. }
  177. /**
  178. * manually indicate this is an error rather than a boolean
  179. */
  180. public void setError(boolean val) {
  181. field_5_fError = (byte) (val == false ? 0 : 1);
  182. }
  183. /**
  184. * Indicates whether the call holds an error value
  185. *
  186. * @return boolean true if the cell holds an error value
  187. */
  188. public boolean isError()
  189. {
  190. return (field_5_fError != ( byte ) 0);
  191. }
  192. public String toString()
  193. {
  194. StringBuffer buffer = new StringBuffer();
  195. buffer.append("[BOOLERR]\n");
  196. buffer.append(" .row = ")
  197. .append(Integer.toHexString(getRow())).append("\n");
  198. buffer.append(" .col = ")
  199. .append(Integer.toHexString(getColumn())).append("\n");
  200. buffer.append(" .xfindex = ")
  201. .append(Integer.toHexString(getXFIndex())).append("\n");
  202. if (isBoolean())
  203. {
  204. buffer.append(" .booleanValue = ").append(getBooleanValue())
  205. .append("\n");
  206. }
  207. else
  208. {
  209. buffer.append(" .errorValue = ").append(getErrorValue())
  210. .append("\n");
  211. }
  212. buffer.append("[/BOOLERR]\n");
  213. return buffer.toString();
  214. }
  215. /**
  216. * called by the class that is responsible for writing this sucker.
  217. * Subclasses should implement this so that their data is passed back in a
  218. * byte array.
  219. *
  220. * @return byte array containing instance data
  221. */
  222. public int serialize(int offset, byte [] data)
  223. {
  224. LittleEndian.putShort(data, 0 + offset, sid);
  225. LittleEndian.putShort(data, 2 + offset, ( short ) 8);
  226. //LittleEndian.putShort(data, 4 + offset, getRow());
  227. LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
  228. LittleEndian.putShort(data, 6 + offset, getColumn());
  229. LittleEndian.putShort(data, 8 + offset, getXFIndex());
  230. data[ 10 + offset ] = field_4_bBoolErr;
  231. data[ 11 + offset ] = field_5_fError;
  232. return getRecordSize();
  233. }
  234. public int getRecordSize()
  235. {
  236. return 12;
  237. }
  238. /**
  239. * called by constructor, should throw runtime exception in the event of a
  240. * record passed with a differing ID.
  241. *
  242. * @param id alleged id for this record
  243. */
  244. protected void validateSid(short id)
  245. {
  246. if (id != BoolErrRecord.sid)
  247. {
  248. throw new RecordFormatException("Not a valid BoolErrRecord");
  249. }
  250. }
  251. public short getSid()
  252. {
  253. return sid;
  254. }
  255. public boolean isBefore(CellValueRecordInterface i)
  256. {
  257. if (this.getRow() > i.getRow())
  258. {
  259. return false;
  260. }
  261. if ((this.getRow() == i.getRow())
  262. && (this.getColumn() > i.getColumn()))
  263. {
  264. return false;
  265. }
  266. if ((this.getRow() == i.getRow())
  267. && (this.getColumn() == i.getColumn()))
  268. {
  269. return false;
  270. }
  271. return true;
  272. }
  273. public boolean isAfter(CellValueRecordInterface i)
  274. {
  275. if (this.getRow() < i.getRow())
  276. {
  277. return false;
  278. }
  279. if ((this.getRow() == i.getRow())
  280. && (this.getColumn() < i.getColumn()))
  281. {
  282. return false;
  283. }
  284. if ((this.getRow() == i.getRow())
  285. && (this.getColumn() == i.getColumn()))
  286. {
  287. return false;
  288. }
  289. return true;
  290. }
  291. public boolean isEqual(CellValueRecordInterface i)
  292. {
  293. return ((this.getRow() == i.getRow())
  294. && (this.getColumn() == i.getColumn()));
  295. }
  296. public boolean isInValueSection()
  297. {
  298. return true;
  299. }
  300. public boolean isValue()
  301. {
  302. return true;
  303. }
  304. public int compareTo(Object obj)
  305. {
  306. CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
  307. if ((this.getRow() == loc.getRow())
  308. && (this.getColumn() == loc.getColumn()))
  309. {
  310. return 0;
  311. }
  312. if (this.getRow() < loc.getRow())
  313. {
  314. return -1;
  315. }
  316. if (this.getRow() > loc.getRow())
  317. {
  318. return 1;
  319. }
  320. if (this.getColumn() < loc.getColumn())
  321. {
  322. return -1;
  323. }
  324. if (this.getColumn() > loc.getColumn())
  325. {
  326. return 1;
  327. }
  328. return -1;
  329. }
  330. public boolean equals(Object obj)
  331. {
  332. if (!(obj instanceof CellValueRecordInterface))
  333. {
  334. return false;
  335. }
  336. CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
  337. if ((this.getRow() == loc.getRow())
  338. && (this.getColumn() == loc.getColumn()))
  339. {
  340. return true;
  341. }
  342. return false;
  343. }
  344. public Object clone() {
  345. BoolErrRecord rec = new BoolErrRecord();
  346. rec.field_1_row = field_1_row;
  347. rec.field_2_column = field_2_column;
  348. rec.field_3_xf_index = field_3_xf_index;
  349. rec.field_4_bBoolErr = field_4_bBoolErr;
  350. rec.field_5_fError = field_5_fError;
  351. return rec;
  352. }
  353. }