You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CellRecord.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.util.GenericRecordUtil;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Base class for all cell value records (implementors of {@link CellValueRecordInterface}).
  22. * Subclasses are expected to manage the cell data values (of various types).
  23. */
  24. public abstract class CellRecord extends StandardRecord implements CellValueRecordInterface {
  25. private int _rowIndex;
  26. private int _columnIndex;
  27. private int _formatIndex;
  28. protected CellRecord() {}
  29. protected CellRecord(CellRecord other) {
  30. super(other);
  31. _rowIndex = other.getRow();
  32. _columnIndex = other.getColumn();
  33. _formatIndex = other.getXFIndex();
  34. }
  35. protected CellRecord(RecordInputStream in) {
  36. _rowIndex = in.readUShort();
  37. _columnIndex = in.readUShort();
  38. _formatIndex = in.readUShort();
  39. }
  40. @Override
  41. public final void setRow(int row) {
  42. _rowIndex = row;
  43. }
  44. @Override
  45. public final void setColumn(short col) {
  46. _columnIndex = col;
  47. }
  48. /**
  49. * set the index to the ExtendedFormat
  50. *
  51. * @see org.apache.poi.hssf.record.ExtendedFormatRecord
  52. * @param xf index to the XF record
  53. */
  54. @Override
  55. public final void setXFIndex(short xf) {
  56. _formatIndex = xf;
  57. }
  58. @Override
  59. public final int getRow() {
  60. return _rowIndex;
  61. }
  62. @Override
  63. public final short getColumn() {
  64. return (short) _columnIndex;
  65. }
  66. /**
  67. * get the index to the ExtendedFormat
  68. *
  69. * @see org.apache.poi.hssf.record.ExtendedFormatRecord
  70. * @return index to the XF record
  71. */
  72. @Override
  73. public final short getXFIndex() {
  74. return (short) _formatIndex;
  75. }
  76. /**
  77. * Gets the debug info BIFF record type name (used by {@link #toString()}.
  78. *
  79. * @return the record type name
  80. */
  81. protected abstract String getRecordName();
  82. /**
  83. * writes out the value data for this cell record
  84. *
  85. * @param out the output
  86. */
  87. protected abstract void serializeValue(LittleEndianOutput out);
  88. /**
  89. * @return the size (in bytes) of the value data for this cell record
  90. */
  91. protected abstract int getValueDataSize();
  92. @Override
  93. public final void serialize(LittleEndianOutput out) {
  94. out.writeShort(getRow());
  95. out.writeShort(getColumn());
  96. out.writeShort(getXFIndex());
  97. serializeValue(out);
  98. }
  99. @Override
  100. protected final int getDataSize() {
  101. return 6 + getValueDataSize();
  102. }
  103. @Override
  104. public abstract CellRecord copy();
  105. @Override
  106. public Map<String, Supplier<?>> getGenericProperties() {
  107. return GenericRecordUtil.getGenericProperties(
  108. "row", this::getRow,
  109. "col", this::getColumn,
  110. "xfIndex", this::getXFIndex
  111. );
  112. }
  113. }