You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2007/07/20 01:31:58 UTC

svn commit: r557814 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java

Author: adelmelle
Date: Thu Jul 19 16:31:55 2007
New Revision: 557814

URL: http://svn.apache.org/viewvc?view=rev&rev=557814
Log:
Cache CharacterProperty

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java?view=diff&rev=557814&r1=557813&r2=557814
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java Thu Jul 19 16:31:55 2007
@@ -25,8 +25,8 @@
 /**
  * Superclass for properties that wrap a character value
  */
-public class CharacterProperty extends Property {
-
+public final class CharacterProperty extends Property {
+    
     /**
      * Inner class for creating instances of CharacterProperty
      */
@@ -42,19 +42,27 @@
         public Property make(PropertyList propertyList, String value,
                              FObj fo) {
             char c = value.charAt(0);
-            return new CharacterProperty(c);
+            return CharacterProperty.getInstance(c);
         }
 
-    }    // end Character.Maker
+    }
+
+    /** cache containing all canonical CharacterProperty instances */
+    private static final PropertyCache cache = new PropertyCache();
 
-    private char character;
+    private final char character;
 
     /**
      * @param character character value to be wrapped in this property
      */
-    public CharacterProperty(char character) {
+    private CharacterProperty(char character) {
         this.character = character;
     }
+    
+    public static CharacterProperty getInstance(char character) {
+        return (CharacterProperty) cache.fetch(
+                        new CharacterProperty(character));
+    }
 
     /**
      * @return this.character cast as an Object
@@ -75,6 +83,24 @@
      */
     public String getString() {
         return new Character(character).toString();
+    }
+
+    /** 
+     * {@inheritDoc}
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof CharacterProperty) {
+            return (((CharacterProperty)obj).character == this.character);
+        } else {
+            return false;
+        }
+    }
+
+    /** 
+     * {@inheritDoc}
+     */
+    public int hashCode() {
+        return (int) character;
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org