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.

IterationRecord.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.BitField;
  19. import org.apache.poi.util.BitFieldFactory;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. /**
  23. * Tells whether to iterate over formula calculations or not.
  24. * If a formula is dependent upon another formula's result.
  25. * (odd feature for something that can only have 32 elements in a formula!)
  26. */
  27. public final class IterationRecord extends StandardRecord {
  28. public static final short sid = 0x0011;
  29. private static final BitField iterationOn = BitFieldFactory.getInstance(0x0001);
  30. private int _flags;
  31. public IterationRecord(IterationRecord other) {
  32. super(other);
  33. _flags = other._flags;
  34. }
  35. public IterationRecord(boolean iterateOn) {
  36. _flags = iterationOn.setBoolean(0, iterateOn);
  37. }
  38. public IterationRecord(RecordInputStream in) {
  39. _flags = in.readShort();
  40. }
  41. /**
  42. * set whether or not to iterate for calculations
  43. * @param iterate or not
  44. */
  45. public void setIteration(boolean iterate) {
  46. _flags = iterationOn.setBoolean(_flags, iterate);
  47. }
  48. /**
  49. * get whether or not to iterate for calculations
  50. *
  51. * @return whether iterative calculations are turned off or on
  52. */
  53. public boolean getIteration() {
  54. return iterationOn.isSet(_flags);
  55. }
  56. public void serialize(LittleEndianOutput out) {
  57. out.writeShort(_flags);
  58. }
  59. protected int getDataSize() {
  60. return 2;
  61. }
  62. public short getSid() {
  63. return sid;
  64. }
  65. @Override
  66. public IterationRecord copy() {
  67. return new IterationRecord(this);
  68. }
  69. @Override
  70. public HSSFRecordTypes getGenericRecordType() {
  71. return HSSFRecordTypes.ITERATION;
  72. }
  73. @Override
  74. public Map<String, Supplier<?>> getGenericProperties() {
  75. return GenericRecordUtil.getGenericProperties(
  76. "flags", () -> _flags,
  77. "iteration", this::getIteration
  78. );
  79. }
  80. }