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.

ListData.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.hwpf.model;
  16. import java.util.Arrays;
  17. import org.apache.poi.util.Internal;
  18. @Internal
  19. public final class ListData
  20. {
  21. private ListLevel[] _levels;
  22. private LSTF _lstf;
  23. ListData( byte[] buf, int offset )
  24. {
  25. _lstf = new LSTF( buf, offset );
  26. if ( _lstf.isFSimpleList() )
  27. {
  28. _levels = new ListLevel[1];
  29. }
  30. else
  31. {
  32. _levels = new ListLevel[9];
  33. }
  34. }
  35. public ListData( int listID, boolean numbered )
  36. {
  37. _lstf = new LSTF();
  38. _lstf.setLsid( listID );
  39. _lstf.setRgistdPara( new short[9] );
  40. Arrays.fill( _lstf.getRgistdPara(), (short) StyleSheet.NIL_STYLE );
  41. _levels = new ListLevel[9];
  42. for ( int x = 0; x < _levels.length; x++ )
  43. {
  44. _levels[x] = new ListLevel( x, numbered );
  45. }
  46. }
  47. @Override
  48. public boolean equals( Object obj )
  49. {
  50. if ( this == obj )
  51. return true;
  52. if ( obj == null )
  53. return false;
  54. if ( getClass() != obj.getClass() )
  55. return false;
  56. ListData other = (ListData) obj;
  57. if ( !Arrays.equals( _levels, other._levels ) )
  58. return false;
  59. if ( _lstf == null )
  60. {
  61. if ( other._lstf != null )
  62. return false;
  63. }
  64. else if ( !_lstf.equals( other._lstf ) )
  65. return false;
  66. return true;
  67. }
  68. /**
  69. * Gets the level associated to a particular List at a particular index.
  70. *
  71. * @param index
  72. * 1-based index
  73. * @return a list level
  74. */
  75. public ListLevel getLevel( int index )
  76. {
  77. return _levels[index - 1];
  78. }
  79. public ListLevel[] getLevels()
  80. {
  81. return _levels;
  82. }
  83. public int getLevelStyle( int index )
  84. {
  85. return _lstf.getRgistdPara()[index];
  86. }
  87. public int getLsid()
  88. {
  89. return _lstf.getLsid();
  90. }
  91. @Override
  92. public int hashCode() {
  93. return Arrays.deepHashCode(new Object[]{_levels,_lstf});
  94. }
  95. public int numLevels()
  96. {
  97. return _levels.length;
  98. }
  99. int resetListID()
  100. {
  101. _lstf.setLsid( (int) ( Math.random() * System.currentTimeMillis() ) );
  102. return _lstf.getLsid();
  103. }
  104. public void setLevel( int index, ListLevel level )
  105. {
  106. _levels[index] = level;
  107. }
  108. public void setLevelStyle( int index, int styleIndex )
  109. {
  110. _lstf.getRgistdPara()[index] = (short) styleIndex;
  111. }
  112. public byte[] toByteArray()
  113. {
  114. return _lstf.serialize();
  115. }
  116. }