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.

EnumNumber.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.properties;
  19. import org.apache.fop.datatypes.Numeric;
  20. import org.apache.fop.datatypes.PercentBaseContext;
  21. import org.apache.fop.fo.expr.PropertyException;
  22. import org.apache.fop.util.CompareUtil;
  23. /**
  24. * A number quantity in XSL which is specified as an enum, such as "no-limit".
  25. */
  26. public final class EnumNumber extends Property implements Numeric {
  27. /** cache holding all canonical EnumNumber instances */
  28. private static final PropertyCache<EnumNumber> CACHE
  29. = new PropertyCache<EnumNumber>();
  30. private final EnumProperty enumProperty;
  31. /**
  32. * Constructor
  33. * @param enumProperty the base EnumProperty
  34. */
  35. private EnumNumber(Property enumProperty) {
  36. this.enumProperty = (EnumProperty) enumProperty;
  37. }
  38. /**
  39. * Returns the canonical EnumNumber instance corresponding
  40. * to the given Property
  41. *
  42. * @param enumProperty the base EnumProperty
  43. * @return the canonical instance
  44. */
  45. public static EnumNumber getInstance(Property enumProperty) {
  46. return CACHE.fetch(new EnumNumber((EnumProperty) enumProperty));
  47. }
  48. /** {@inheritDoc} */
  49. public int getEnum() {
  50. return enumProperty.getEnum();
  51. }
  52. /** {@inheritDoc} */
  53. public String getString() {
  54. return enumProperty.toString();
  55. }
  56. /** {@inheritDoc} */
  57. public Object getObject() {
  58. return enumProperty.getObject();
  59. }
  60. @Override
  61. public boolean equals(Object obj) {
  62. if (this == obj) {
  63. return true;
  64. }
  65. if (!(obj instanceof EnumNumber)) {
  66. return false;
  67. }
  68. EnumNumber other = (EnumNumber) obj;
  69. return CompareUtil.equal(enumProperty, other.enumProperty);
  70. }
  71. /** {@inheritDoc} */
  72. @Override
  73. public int hashCode() {
  74. return enumProperty.hashCode();
  75. }
  76. /** {@inheritDoc} */
  77. public int getDimension() {
  78. return 0;
  79. }
  80. /**
  81. * {@inheritDoc}
  82. * Always <code>true</code> for instances of this type
  83. */
  84. public boolean isAbsolute() {
  85. return true;
  86. }
  87. /**
  88. * {@inheritDoc}
  89. * logs an error, because it's not supposed to be called
  90. */
  91. public double getNumericValue(PercentBaseContext context) throws PropertyException {
  92. log.error("getNumericValue() called on " + enumProperty + " number");
  93. return 0;
  94. }
  95. /**
  96. * {@inheritDoc}
  97. * logs an error, because it's not supposed to be called
  98. */
  99. public int getValue(PercentBaseContext context) {
  100. log.error("getValue() called on " + enumProperty + " number");
  101. return 0;
  102. }
  103. /**
  104. * {@inheritDoc}
  105. * logs an error, because it's not supposed to be called
  106. */
  107. public int getValue() {
  108. log.error("getValue() called on " + enumProperty + " number");
  109. return 0;
  110. }
  111. /**
  112. * {@inheritDoc}
  113. * logs an error, because it's not supposed to be called
  114. */
  115. public double getNumericValue() {
  116. log.error("getNumericValue() called on " + enumProperty + " number");
  117. return 0;
  118. }
  119. /**
  120. * {@inheritDoc}
  121. */
  122. public Numeric getNumeric() {
  123. return this;
  124. }
  125. }