PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/aggregates/FormulaRecordAggregate.java

http://github.com/openmicroscopy/bioformats
Java | 219 lines | 115 code | 37 blank | 67 comment | 5 complexity | fa845485a51e4538ffbac8c3b6be9a3c 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.aggregates;
  38. import loci.poi.hssf.record.*;
  39. /**
  40. * The formula record aggregate is used to join together the formula record and it's
  41. * (optional) string record and (optional) Shared Formula Record (template reads, excel optimization).
  42. *
  43. * @author Glen Stampoultzis (glens at apache.org)
  44. */
  45. public class FormulaRecordAggregate
  46. extends Record
  47. implements CellValueRecordInterface, Comparable
  48. {
  49. public final static short sid = -2000;
  50. private FormulaRecord formulaRecord;
  51. private StringRecord stringRecord;
  52. public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord )
  53. {
  54. this.formulaRecord = formulaRecord;
  55. this.stringRecord = stringRecord;
  56. }
  57. protected void validateSid( short id )
  58. {
  59. }
  60. protected void fillFields( RecordInputStream in )
  61. {
  62. }
  63. /**
  64. * called by the class that is responsible for writing this sucker.
  65. * Subclasses should implement this so that their data is passed back in a
  66. * byte array.
  67. *
  68. * @param offset to begin writing at
  69. * @param data byte array containing instance data
  70. * @return number of bytes written
  71. */
  72. public int serialize( int offset, byte[] data )
  73. {
  74. int pos = offset;
  75. pos += formulaRecord.serialize(pos, data);
  76. if (stringRecord != null)
  77. {
  78. pos += stringRecord.serialize(pos, data);
  79. }
  80. return pos - offset;
  81. }
  82. /**
  83. * gives the current serialized size of the record. Should include the sid and reclength (4 bytes).
  84. */
  85. public int getRecordSize()
  86. {
  87. int size = formulaRecord.getRecordSize() + (stringRecord == null ? 0 : stringRecord.getRecordSize());
  88. return size;
  89. }
  90. /**
  91. * return the non static version of the id for this record.
  92. */
  93. public short getSid()
  94. {
  95. return sid;
  96. }
  97. public void setStringRecord( StringRecord stringRecord )
  98. {
  99. this.stringRecord = stringRecord;
  100. }
  101. public void setFormulaRecord( FormulaRecord formulaRecord )
  102. {
  103. this.formulaRecord = formulaRecord;
  104. }
  105. public FormulaRecord getFormulaRecord()
  106. {
  107. return formulaRecord;
  108. }
  109. public StringRecord getStringRecord()
  110. {
  111. return stringRecord;
  112. }
  113. public boolean isEqual(CellValueRecordInterface i)
  114. {
  115. return formulaRecord.isEqual( i );
  116. }
  117. public boolean isAfter(CellValueRecordInterface i)
  118. {
  119. return formulaRecord.isAfter( i );
  120. }
  121. public boolean isBefore(CellValueRecordInterface i)
  122. {
  123. return formulaRecord.isBefore( i );
  124. }
  125. public short getXFIndex()
  126. {
  127. return formulaRecord.getXFIndex();
  128. }
  129. public void setXFIndex(short xf)
  130. {
  131. formulaRecord.setXFIndex( xf );
  132. }
  133. public void setColumn(short col)
  134. {
  135. formulaRecord.setColumn( col );
  136. }
  137. public void setRow(int row)
  138. {
  139. formulaRecord.setRow( row );
  140. }
  141. public short getColumn()
  142. {
  143. return formulaRecord.getColumn();
  144. }
  145. public int getRow()
  146. {
  147. return formulaRecord.getRow();
  148. }
  149. public int compareTo(Object o)
  150. {
  151. return formulaRecord.compareTo( o );
  152. }
  153. public boolean equals(Object obj)
  154. {
  155. return formulaRecord.equals( obj );
  156. }
  157. public String toString()
  158. {
  159. return formulaRecord.toString();
  160. }
  161. /**
  162. * @see java.lang.Object#clone()
  163. */
  164. public Object clone() {
  165. StringRecord clonedString = (stringRecord == null) ? null : (StringRecord)stringRecord.clone();
  166. return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), clonedString);
  167. }
  168. /*
  169. * Setting to true so that this value does not abort the whole ValueAggregation
  170. * (non-Javadoc)
  171. * @see loci.poi.hssf.record.Record#isInValueSection()
  172. */
  173. public boolean isInValueSection() {
  174. return true;
  175. }
  176. public String getStringValue() {
  177. if(stringRecord==null) return null;
  178. return stringRecord.getString();
  179. }
  180. }