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.

PropertyModifier.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.Objects;
  17. import org.apache.poi.common.Duplicatable;
  18. import org.apache.poi.util.BitField;
  19. import org.apache.poi.util.Internal;
  20. import org.apache.poi.util.Removal;
  21. @Internal
  22. public final class PropertyModifier implements Duplicatable {
  23. /**
  24. * <li>"Set to 0 for variant 1" <li>"Set to 1 for variant 2"
  25. */
  26. private static final BitField _fComplex = new BitField( 0x0001 );
  27. /**
  28. * "Index to a grpprl stored in CLX portion of file"
  29. */
  30. private static final BitField _figrpprl = new BitField( 0xfffe );
  31. /**
  32. * "Index to entry into rgsprmPrm"
  33. */
  34. private static final BitField _fisprm = new BitField( 0x00fe );
  35. /**
  36. * "sprm's operand"
  37. */
  38. private static final BitField _fval = new BitField( 0xff00 );
  39. private short value;
  40. public PropertyModifier( short value ) {
  41. this.value = value;
  42. }
  43. public PropertyModifier( PropertyModifier other ) {
  44. value = other.value;
  45. }
  46. @Override
  47. @SuppressWarnings("squid:S2975")
  48. @Deprecated
  49. @Removal(version = "5.0.0")
  50. protected PropertyModifier clone() {
  51. return copy();
  52. }
  53. @Override
  54. public PropertyModifier copy() {
  55. return new PropertyModifier(this);
  56. }
  57. @Override
  58. public boolean equals( Object obj )
  59. {
  60. if ( this == obj )
  61. return true;
  62. if ( obj == null )
  63. return false;
  64. if ( getClass() != obj.getClass() )
  65. return false;
  66. PropertyModifier other = (PropertyModifier) obj;
  67. if ( value != other.value )
  68. return false;
  69. return true;
  70. }
  71. /**
  72. * "Index to a grpprl stored in CLX portion of file"
  73. */
  74. public short getIgrpprl()
  75. {
  76. if ( !isComplex() )
  77. throw new IllegalStateException( "Not complex" );
  78. return _figrpprl.getShortValue( value );
  79. }
  80. public short getIsprm()
  81. {
  82. if ( isComplex() )
  83. throw new IllegalStateException( "Not simple" );
  84. return _fisprm.getShortValue( value );
  85. }
  86. public short getVal()
  87. {
  88. if ( isComplex() )
  89. throw new IllegalStateException( "Not simple" );
  90. return _fval.getShortValue( value );
  91. }
  92. public short getValue()
  93. {
  94. return value;
  95. }
  96. @Override
  97. public int hashCode() {
  98. return Objects.hash(value);
  99. }
  100. public boolean isComplex()
  101. {
  102. return _fComplex.isSet( value );
  103. }
  104. @Override
  105. public String toString()
  106. {
  107. StringBuilder stringBuilder = new StringBuilder();
  108. stringBuilder.append( "[PRM] (complex: " );
  109. stringBuilder.append( isComplex() );
  110. stringBuilder.append( "; " );
  111. if ( isComplex() )
  112. {
  113. stringBuilder.append( "igrpprl: " );
  114. stringBuilder.append( getIgrpprl() );
  115. stringBuilder.append( "; " );
  116. }
  117. else
  118. {
  119. stringBuilder.append( "isprm: " );
  120. stringBuilder.append( getIsprm() );
  121. stringBuilder.append( "; " );
  122. stringBuilder.append( "val: " );
  123. stringBuilder.append( getVal() );
  124. stringBuilder.append( "; " );
  125. }
  126. stringBuilder.append( ")" );
  127. return stringBuilder.toString();
  128. }
  129. }