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.

PrecisionRecord.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * Defines whether to store with full precision or what's displayed by the gui
  22. * (meaning have really screwed up and skewed figures or only think you do!)
  23. *
  24. * @version 2.0-pre
  25. */
  26. public final class PrecisionRecord extends StandardRecord {
  27. public static final short sid = 0xE;
  28. private short field_1_precision;
  29. public PrecisionRecord() {}
  30. public PrecisionRecord(PrecisionRecord other) {
  31. super(other);
  32. field_1_precision = other.field_1_precision;
  33. }
  34. public PrecisionRecord(RecordInputStream in) {
  35. field_1_precision = in.readShort();
  36. }
  37. /**
  38. * set whether to use full precision or just skew all you figures all to hell.
  39. *
  40. * @param fullprecision - or not
  41. */
  42. public void setFullPrecision(boolean fullprecision) {
  43. field_1_precision = (short) (fullprecision ? 1 : 0);
  44. }
  45. /**
  46. * get whether to use full precision or just skew all you figures all to hell.
  47. *
  48. * @return fullprecision - or not
  49. */
  50. public boolean getFullPrecision()
  51. {
  52. return (field_1_precision == 1);
  53. }
  54. public void serialize(LittleEndianOutput out) {
  55. out.writeShort(field_1_precision);
  56. }
  57. protected int getDataSize() {
  58. return 2;
  59. }
  60. public short getSid()
  61. {
  62. return sid;
  63. }
  64. @Override
  65. public PrecisionRecord copy() {
  66. return new PrecisionRecord(this);
  67. }
  68. @Override
  69. public HSSFRecordTypes getGenericRecordType() {
  70. return HSSFRecordTypes.PRECISION;
  71. }
  72. @Override
  73. public Map<String, Supplier<?>> getGenericProperties() {
  74. return GenericRecordUtil.getGenericProperties("precision", this::getFullPrecision);
  75. }
  76. }