Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TabIdRecord.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * Contains an array of sheet id's. Sheets always keep their ID regardless of what their name is.
  22. */
  23. public final class TabIdRecord extends StandardRecord {
  24. public static final short sid = 0x013D;
  25. private static final short[] EMPTY_SHORT_ARRAY = { };
  26. private short[] _tabids;
  27. public TabIdRecord() {
  28. _tabids = EMPTY_SHORT_ARRAY;
  29. }
  30. public TabIdRecord(TabIdRecord other) {
  31. super(other);
  32. _tabids = (other._tabids == null) ? null : other._tabids.clone();
  33. }
  34. public TabIdRecord(RecordInputStream in) {
  35. int nTabs = in.remaining() / 2;
  36. _tabids = new short[nTabs];
  37. for (int i = 0; i < _tabids.length; i++) {
  38. _tabids[i] = in.readShort();
  39. }
  40. }
  41. /**
  42. * set the tab array. (0,1,2).
  43. * @param array of tab id's {0,1,2}
  44. */
  45. public void setTabIdArray(short[] array) {
  46. _tabids = array.clone();
  47. }
  48. public void serialize(LittleEndianOutput out) {
  49. for (short tabid : _tabids) {
  50. out.writeShort(tabid);
  51. }
  52. }
  53. public int getTabIdSize() {
  54. return _tabids.length;
  55. }
  56. public short getTabIdAt(int index) {
  57. return _tabids[index];
  58. }
  59. protected int getDataSize() {
  60. return _tabids.length * 2;
  61. }
  62. public short getSid() {
  63. return sid;
  64. }
  65. @Override
  66. public TabIdRecord copy() {
  67. return new TabIdRecord(this);
  68. }
  69. @Override
  70. public HSSFRecordTypes getGenericRecordType() {
  71. return HSSFRecordTypes.TAB_ID;
  72. }
  73. @Override
  74. public Map<String, Supplier<?>> getGenericProperties() {
  75. return GenericRecordUtil.getGenericProperties("elements", () -> _tabids);
  76. }
  77. }