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.

NumberRecord.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * NUMBER (0x0203) Contains a numeric cell value.
  22. */
  23. public final class NumberRecord extends CellRecord {
  24. public static final short sid = 0x0203;
  25. private double field_4_value;
  26. /** Creates new NumberRecord */
  27. public NumberRecord() {}
  28. public NumberRecord(NumberRecord other) {
  29. super(other);
  30. field_4_value = other.field_4_value;
  31. }
  32. /**
  33. * @param in the RecordInputstream to read the record from
  34. */
  35. public NumberRecord(RecordInputStream in) {
  36. super(in);
  37. field_4_value = in.readDouble();
  38. }
  39. /**
  40. * set the value for the cell
  41. *
  42. * @param value double representing the value
  43. */
  44. public void setValue(double value){
  45. field_4_value = value;
  46. }
  47. /**
  48. * get the value for the cell
  49. *
  50. * @return double representing the value
  51. */
  52. public double getValue(){
  53. return field_4_value;
  54. }
  55. @Override
  56. protected String getRecordName() {
  57. return "NUMBER";
  58. }
  59. @Override
  60. protected void serializeValue(LittleEndianOutput out) {
  61. out.writeDouble(getValue());
  62. }
  63. @Override
  64. protected int getValueDataSize() {
  65. return 8;
  66. }
  67. @Override
  68. public short getSid() {
  69. return sid;
  70. }
  71. @Override
  72. public NumberRecord copy() {
  73. return new NumberRecord(this);
  74. }
  75. @Override
  76. public HSSFRecordTypes getGenericRecordType() {
  77. return HSSFRecordTypes.NUMBER;
  78. }
  79. @Override
  80. public Map<String, Supplier<?>> getGenericProperties() {
  81. return GenericRecordUtil.getGenericProperties(
  82. "base", super::getGenericProperties,
  83. "value", this::getValue
  84. );
  85. }
  86. }