Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CharacterProperty.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.fo.FObj;
  20. import org.apache.fop.fo.PropertyList;
  21. /**
  22. * Superclass for properties that wrap a character value
  23. * TODO convert character value to int in order to denote unicode scalar value
  24. * instead of a single UTF-16 code element
  25. */
  26. public final class CharacterProperty extends Property {
  27. /**
  28. * Inner class for creating instances of CharacterProperty
  29. */
  30. public static class Maker extends PropertyMaker {
  31. /**
  32. * @param propId the id of the property for which a Maker should be created
  33. */
  34. public Maker(int propId) {
  35. super(propId);
  36. }
  37. /** {@inheritDoc} */
  38. public Property make(PropertyList propertyList, String value,
  39. FObj fo) {
  40. char c = value.charAt(0);
  41. return CharacterProperty.getInstance(c);
  42. }
  43. }
  44. /** cache containing all canonical CharacterProperty instances */
  45. private static final PropertyCache<CharacterProperty> CACHE
  46. = new PropertyCache<CharacterProperty>();
  47. private final char character;
  48. /**
  49. * @param character character value to be wrapped in this property
  50. */
  51. private CharacterProperty(char character) {
  52. this.character = character;
  53. }
  54. /**
  55. * Get character property instance for character.
  56. * @param character the character
  57. * @return the character property instance
  58. */
  59. public static CharacterProperty getInstance(char character) {
  60. return CACHE.fetch(new CharacterProperty(character));
  61. }
  62. /**
  63. * @return this.character cast as an Object
  64. */
  65. public Object getObject() {
  66. return character;
  67. }
  68. /**
  69. * @return this.character
  70. */
  71. public char getCharacter() {
  72. return this.character;
  73. }
  74. /**
  75. * @return this.character cast as a String
  76. */
  77. public String getString() {
  78. return Character.toString(character);
  79. }
  80. @Override
  81. public boolean equals(Object obj) {
  82. if (obj instanceof CharacterProperty) {
  83. return (character == ((CharacterProperty) obj).character);
  84. } else {
  85. return false;
  86. }
  87. }
  88. @Override
  89. public int hashCode() {
  90. return character;
  91. }
  92. }