PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

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