PageRenderTime 277ms CodeModel.GetById 35ms RepoModel.GetById 6ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/formula/NamePtg.java

http://github.com/openmicroscopy/bioformats
Java | 123 lines | 60 code | 15 blank | 48 comment | 2 complexity | cb6196b4ba3422f8de7250a99a35ac3b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.record.formula;
  38. import loci.poi.util.LittleEndian;
  39. import loci.poi.hssf.model.Workbook;
  40. import loci.poi.hssf.record.NameRecord;
  41. import loci.poi.hssf.record.RecordInputStream;
  42. /**
  43. *
  44. * @author andy
  45. * @author Jason Height (jheight at chariot dot net dot au)
  46. */
  47. public class NamePtg
  48. extends Ptg
  49. {
  50. public final static short sid = 0x23;
  51. private final static int SIZE = 5;
  52. private short field_1_label_index;
  53. private short field_2_zero; // reserved must be 0
  54. boolean xtra=false;
  55. private NamePtg() {
  56. //Required for clone methods
  57. }
  58. /** Creates new NamePtg */
  59. public NamePtg(String name, Workbook book)
  60. {
  61. final short n = (short) (book.getNumNames() + 1);
  62. NameRecord rec;
  63. for (short i = 1; i < n; i++) {
  64. rec = book.getNameRecord(i - 1);
  65. if (name.equals(rec.getNameText())) {
  66. field_1_label_index = i;
  67. return;
  68. }
  69. }
  70. rec = new NameRecord();
  71. rec.setNameText(name);
  72. rec.setNameTextLength((byte) name.length());
  73. book.addName(rec);
  74. field_1_label_index = n;
  75. }
  76. /** Creates new NamePtg */
  77. public NamePtg(RecordInputStream in)
  78. {
  79. //field_1_ixti = LittleEndian.getShort(data, offset);
  80. field_1_label_index = in.readShort();
  81. field_2_zero = in.readShort();
  82. //if (data[offset+6]==0) xtra=true;
  83. }
  84. public void writeBytes(byte [] array, int offset)
  85. {
  86. array[offset+0]= (byte) (sid + ptgClass);
  87. LittleEndian.putShort(array,offset+1,field_1_label_index);
  88. LittleEndian.putShort(array,offset+3, field_2_zero);
  89. }
  90. public int getSize()
  91. {
  92. return SIZE;
  93. }
  94. public String toFormulaString(Workbook book)
  95. {
  96. NameRecord rec = book.getNameRecord(field_1_label_index - 1);
  97. return rec.getNameText();
  98. }
  99. public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
  100. public Object clone() {
  101. NamePtg ptg = new NamePtg();
  102. ptg.field_1_label_index = field_1_label_index;
  103. ptg.field_2_zero = field_2_zero;
  104. return ptg;
  105. }
  106. }