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.

CRNRecord.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.ss.formula.constant.ConstantValueParser;
  19. import org.apache.poi.util.GenericRecordUtil;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * This record stores the contents of an external cell or cell range
  23. */
  24. public final class CRNRecord extends StandardRecord {
  25. public static final short sid = 0x005A;
  26. private int field_1_last_column_index;
  27. private int field_2_first_column_index;
  28. private int field_3_row_index;
  29. private Object[] field_4_constant_values;
  30. public CRNRecord(CRNRecord other) {
  31. super(other);
  32. field_1_last_column_index = other.field_1_last_column_index;
  33. field_2_first_column_index = other.field_2_first_column_index;
  34. field_3_row_index = other.field_3_row_index;
  35. // field_4_constant_values are instances of Double, Boolean, String, ErrorCode,
  36. // i.e. they are immutable and can their references can be simply cloned
  37. field_4_constant_values = (other.field_4_constant_values == null) ? null : other.field_4_constant_values.clone();
  38. }
  39. public CRNRecord(RecordInputStream in) {
  40. field_1_last_column_index = in.readUByte();
  41. field_2_first_column_index = in.readUByte();
  42. field_3_row_index = in.readShort();
  43. int nValues = field_1_last_column_index - field_2_first_column_index + 1;
  44. field_4_constant_values = ConstantValueParser.parse(in, nValues);
  45. }
  46. public int getNumberOfCRNs() {
  47. return field_1_last_column_index;
  48. }
  49. protected int getDataSize() {
  50. return 4 + ConstantValueParser.getEncodedSize(field_4_constant_values);
  51. }
  52. public void serialize(LittleEndianOutput out) {
  53. out.writeByte(field_1_last_column_index);
  54. out.writeByte(field_2_first_column_index);
  55. out.writeShort(field_3_row_index);
  56. ConstantValueParser.encode(out, field_4_constant_values);
  57. }
  58. /**
  59. * return the non static version of the id for this record.
  60. */
  61. public short getSid() {
  62. return sid;
  63. }
  64. @Override
  65. public CRNRecord copy() {
  66. return new CRNRecord(this);
  67. }
  68. @Override
  69. public HSSFRecordTypes getGenericRecordType() {
  70. return HSSFRecordTypes.CRN;
  71. }
  72. @Override
  73. public Map<String, Supplier<?>> getGenericProperties() {
  74. return GenericRecordUtil.getGenericProperties(
  75. "row", () -> field_3_row_index,
  76. "firstColumn", () -> field_2_first_column_index,
  77. "lastColumn", () -> field_1_last_column_index,
  78. "constantValues", () -> field_4_constant_values
  79. );
  80. }
  81. }