PageRenderTime 84ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/DeltaRecord.java

http://github.com/openmicroscopy/bioformats
Java | 146 lines | 64 code | 22 blank | 60 comment | 2 complexity | e5db5baa233dac0bea1225af537cf11c 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;
  38. import loci.poi.util.LittleEndian;
  39. /**
  40. * Title: Delta Record<P>
  41. * Description: controls the accuracy of the calculations<P>
  42. * REFERENCE: PG 303 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  43. * @author Andrew C. Oliver (acoliver at apache dot org)
  44. * @author Jason Height (jheight at chariot dot net dot au)
  45. * @version 2.0-pre
  46. */
  47. public class DeltaRecord
  48. extends Record
  49. {
  50. public final static short sid = 0x10;
  51. public final static double DEFAULT_VALUE = 0.0010; // should be .001
  52. // a double is an IEEE 8-byte float...damn IEEE and their goofy standards an
  53. // ambiguous numeric identifiers
  54. private double field_1_max_change;
  55. public DeltaRecord()
  56. {
  57. }
  58. /**
  59. * Constructs a Delta record and sets its fields appropriately.
  60. * @param in the RecordInputstream to read the record from
  61. */
  62. public DeltaRecord(RecordInputStream in)
  63. {
  64. super(in);
  65. }
  66. protected void validateSid(short id)
  67. {
  68. if (id != sid)
  69. {
  70. throw new RecordFormatException("NOT A DELTA RECORD");
  71. }
  72. }
  73. protected void fillFields(RecordInputStream in)
  74. {
  75. field_1_max_change = in.readDouble();
  76. }
  77. /**
  78. * set the maximum change
  79. * @param maxChange - maximum rounding error
  80. */
  81. public void setMaxChange(double maxChange)
  82. {
  83. field_1_max_change = maxChange;
  84. }
  85. /**
  86. * get the maximum change
  87. * @return maxChange - maximum rounding error
  88. */
  89. public double getMaxChange()
  90. {
  91. return field_1_max_change;
  92. }
  93. public String toString()
  94. {
  95. StringBuffer buffer = new StringBuffer();
  96. buffer.append("[DELTA]\n");
  97. buffer.append(" .maxchange = ").append(getMaxChange())
  98. .append("\n");
  99. buffer.append("[/DELTA]\n");
  100. return buffer.toString();
  101. }
  102. public int serialize(int offset, byte [] data)
  103. {
  104. LittleEndian.putShort(data, 0 + offset, sid);
  105. LittleEndian.putShort(data, 2 + offset, ( short ) 0x8);
  106. LittleEndian.putDouble(data, 4 + offset, getMaxChange());
  107. return getRecordSize();
  108. }
  109. public int getRecordSize()
  110. {
  111. return 12;
  112. }
  113. public short getSid()
  114. {
  115. return sid;
  116. }
  117. public Object clone() {
  118. DeltaRecord rec = new DeltaRecord();
  119. rec.field_1_max_change = field_1_max_change;
  120. return rec;
  121. }
  122. }