PageRenderTime 113ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 330 lines | 181 code | 42 blank | 107 comment | 34 complexity | bbf1c9ed447f6ee0462a495afa5038ec 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. * BlankRecord.java
  39. *
  40. * Created on December 10, 2001, 12:07 PM
  41. */
  42. package loci.poi.hssf.record;
  43. import loci.poi.util.LittleEndian;
  44. /**
  45. * Title: Blank cell record <P>
  46. * Description: Represents a column in a row with no value but with styling.<P>
  47. * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  48. * @author Andrew C. Oliver (acoliver at apache dot org)
  49. * @author Jason Height (jheight at chariot dot net dot au)
  50. * @version 2.0-pre
  51. */
  52. public class BlankRecord
  53. extends Record
  54. implements CellValueRecordInterface, Comparable
  55. {
  56. public final static short sid = 0x201;
  57. //private short field_1_row;
  58. private int field_1_row;
  59. private short field_2_col;
  60. private short field_3_xf;
  61. /** Creates a new instance of BlankRecord */
  62. public BlankRecord()
  63. {
  64. }
  65. /**
  66. * Constructs a BlankRecord and sets its fields appropriately
  67. * @param in the RecordInputstream to read the record from
  68. */
  69. public BlankRecord(RecordInputStream in)
  70. {
  71. super(in);
  72. }
  73. protected void fillFields(RecordInputStream in)
  74. {
  75. //field_1_row = LittleEndian.getShort(data, 0 + offset);
  76. field_1_row = in.readUShort();
  77. field_2_col = in.readShort();
  78. field_3_xf = in.readShort();
  79. }
  80. /**
  81. * called by constructor, should throw runtime exception in the event of a
  82. * record passed with a differing ID.
  83. *
  84. * @param id alleged id for this record
  85. */
  86. protected void validateSid(short id)
  87. {
  88. if (id != sid)
  89. {
  90. throw new RecordFormatException("NOT A BLANKRECORD!");
  91. }
  92. }
  93. /**
  94. * set the row this cell occurs on
  95. * @param row the row this cell occurs within
  96. */
  97. //public void setRow(short row)
  98. public void setRow(int row)
  99. {
  100. field_1_row = row;
  101. }
  102. /**
  103. * get the row this cell occurs on
  104. *
  105. * @return the row
  106. */
  107. //public short getRow()
  108. public int getRow()
  109. {
  110. return field_1_row;
  111. }
  112. /**
  113. * get the column this cell defines within the row
  114. *
  115. * @return the column
  116. */
  117. public short getColumn()
  118. {
  119. return field_2_col;
  120. }
  121. /**
  122. * set the index of the extended format record to style this cell with
  123. *
  124. * @param xf - the 0-based index of the extended format
  125. * @see loci.poi.hssf.record.ExtendedFormatRecord
  126. */
  127. public void setXFIndex(short xf)
  128. {
  129. field_3_xf = xf;
  130. }
  131. /**
  132. * get the index of the extended format record to style this cell with
  133. *
  134. * @return extended format index
  135. */
  136. public short getXFIndex()
  137. {
  138. return field_3_xf;
  139. }
  140. /**
  141. * set the column this cell defines within the row
  142. *
  143. * @param col the column this cell defines
  144. */
  145. public void setColumn(short col)
  146. {
  147. field_2_col = col;
  148. }
  149. public boolean isBefore(CellValueRecordInterface i)
  150. {
  151. if (this.getRow() > i.getRow())
  152. {
  153. return false;
  154. }
  155. if ((this.getRow() == i.getRow())
  156. && (this.getColumn() > i.getColumn()))
  157. {
  158. return false;
  159. }
  160. if ((this.getRow() == i.getRow())
  161. && (this.getColumn() == i.getColumn()))
  162. {
  163. return false;
  164. }
  165. return true;
  166. }
  167. public boolean isAfter(CellValueRecordInterface i)
  168. {
  169. if (this.getRow() < i.getRow())
  170. {
  171. return false;
  172. }
  173. if ((this.getRow() == i.getRow())
  174. && (this.getColumn() < i.getColumn()))
  175. {
  176. return false;
  177. }
  178. if ((this.getRow() == i.getRow())
  179. && (this.getColumn() == i.getColumn()))
  180. {
  181. return false;
  182. }
  183. return true;
  184. }
  185. public boolean isEqual(CellValueRecordInterface i)
  186. {
  187. return ((this.getRow() == i.getRow())
  188. && (this.getColumn() == i.getColumn()));
  189. }
  190. public boolean isInValueSection()
  191. {
  192. return true;
  193. }
  194. public boolean isValue()
  195. {
  196. return true;
  197. }
  198. /**
  199. * return the non static version of the id for this record.
  200. */
  201. public short getSid()
  202. {
  203. return sid;
  204. }
  205. public String toString()
  206. {
  207. StringBuffer buffer = new StringBuffer();
  208. buffer.append("[BLANK]\n");
  209. buffer.append("row = ").append(Integer.toHexString(getRow()))
  210. .append("\n");
  211. buffer.append("col = ").append(Integer.toHexString(getColumn()))
  212. .append("\n");
  213. buffer.append("xf = ")
  214. .append(Integer.toHexString(getXFIndex())).append("\n");
  215. buffer.append("[/BLANK]\n");
  216. return buffer.toString();
  217. }
  218. /**
  219. * called by the class that is responsible for writing this sucker.
  220. * Subclasses should implement this so that their data is passed back in a
  221. * byte array.
  222. *
  223. * @return byte array containing instance data
  224. */
  225. public int serialize(int offset, byte [] data)
  226. {
  227. LittleEndian.putShort(data, 0 + offset, sid);
  228. LittleEndian.putShort(data, 2 + offset, ( short ) 6);
  229. //LittleEndian.putShort(data, 4 + offset, getRow());
  230. LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
  231. LittleEndian.putShort(data, 6 + offset, getColumn());
  232. LittleEndian.putShort(data, 8 + offset, getXFIndex());
  233. return getRecordSize();
  234. }
  235. public int getRecordSize()
  236. {
  237. return 10;
  238. }
  239. public int compareTo(Object obj)
  240. {
  241. CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
  242. if ((this.getRow() == loc.getRow())
  243. && (this.getColumn() == loc.getColumn()))
  244. {
  245. return 0;
  246. }
  247. if (this.getRow() < loc.getRow())
  248. {
  249. return -1;
  250. }
  251. if (this.getRow() > loc.getRow())
  252. {
  253. return 1;
  254. }
  255. if (this.getColumn() < loc.getColumn())
  256. {
  257. return -1;
  258. }
  259. if (this.getColumn() > loc.getColumn())
  260. {
  261. return 1;
  262. }
  263. return -1;
  264. }
  265. public boolean equals(Object obj)
  266. {
  267. if (!(obj instanceof CellValueRecordInterface))
  268. {
  269. return false;
  270. }
  271. CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
  272. if ((this.getRow() == loc.getRow())
  273. && (this.getColumn() == loc.getColumn()))
  274. {
  275. return true;
  276. }
  277. return false;
  278. }
  279. public Object clone() {
  280. BlankRecord rec = new BlankRecord();
  281. rec.field_1_row = field_1_row;
  282. rec.field_2_col = field_2_col;
  283. rec.field_3_xf = field_3_xf;
  284. return rec;
  285. }
  286. }