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.

Hyphenation.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 org.apache.poi.hwpf.model.types.HRESIAbstractType;
  17. import org.apache.poi.hwpf.usermodel.CharacterProperties;
  18. import org.apache.poi.util.Internal;
  19. import org.apache.poi.util.LittleEndian;
  20. /**
  21. * Hyphenation. Substructure of the {@link CharacterProperties}.
  22. *
  23. * @author Sergey Vladimirov ( vlsergey {at} gmail {dot} com )
  24. */
  25. @Internal
  26. public final class Hyphenation extends HRESIAbstractType implements Cloneable
  27. {
  28. public Hyphenation()
  29. {
  30. super();
  31. }
  32. public Hyphenation( short hres )
  33. {
  34. byte[] data = new byte[2];
  35. LittleEndian.putShort( data, 0, hres );
  36. fillFields( data, 0 );
  37. }
  38. public Hyphenation clone()
  39. {
  40. try
  41. {
  42. return (Hyphenation) super.clone();
  43. }
  44. catch ( CloneNotSupportedException e )
  45. {
  46. throw new RuntimeException( e );
  47. }
  48. }
  49. @Override
  50. public boolean equals( Object obj )
  51. {
  52. if ( this == obj )
  53. return true;
  54. if ( obj == null )
  55. return false;
  56. if ( getClass() != obj.getClass() )
  57. return false;
  58. Hyphenation other = (Hyphenation) obj;
  59. if ( field_1_hres != other.field_1_hres )
  60. return false;
  61. if ( field_2_chHres != other.field_2_chHres )
  62. return false;
  63. return true;
  64. }
  65. public short getValue()
  66. {
  67. byte[] data = new byte[2];
  68. serialize( data, 0 );
  69. return LittleEndian.getShort( data );
  70. }
  71. @Override
  72. public int hashCode()
  73. {
  74. final int prime = 31;
  75. int result = 1;
  76. result = prime * result + field_1_hres;
  77. result = prime * result + field_2_chHres;
  78. return result;
  79. }
  80. public boolean isEmpty()
  81. {
  82. return field_1_hres == 0 && field_2_chHres == 0;
  83. }
  84. @Override
  85. public String toString()
  86. {
  87. if ( isEmpty() )
  88. return "[HRESI] EMPTY";
  89. return super.toString();
  90. }
  91. }