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 2006/12/23 12:51:55 UTC
svn commit: r489884 -
/xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java
Author: adelmelle
Date: Sat Dec 23 03:51:54 2006
New Revision: 489884
URL: http://svn.apache.org/viewvc?view=rev&rev=489884
Log:
Adaptation of MarkerAttribute cache to use WeakHashMap
Modified:
xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java
Modified: xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java?view=diff&rev=489884&r1=489883&r2=489884
==============================================================================
--- xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java (original)
+++ xmlgraphics/fop/branches/fop-0_93/src/java/org/apache/fop/fo/flow/Marker.java Sat Dec 23 03:51:54 2006
@@ -196,13 +196,8 @@
name = attributes.getLocalName(i);
value = attributes.getValue(i);
- if (namespace == null || "".equals(namespace)) {
- this.attribs[i] =
- MarkerAttribute.getFOAttributeInstance(name, value);
- } else {
- this.attribs[i] =
- new MarkerAttribute(namespace, qname, name, value);
- }
+ this.attribs[i] =
+ MarkerAttribute.getInstance(namespace, qname, name, value);
}
}
@@ -374,8 +369,8 @@
*/
private static final class MarkerAttribute {
- private static Map foAttributeCache =
- Collections.synchronizedMap(new java.util.HashMap());
+ private static Map attributeCache =
+ Collections.synchronizedMap(new java.util.WeakHashMap());
protected String namespace;
protected String qname;
@@ -406,26 +401,40 @@
* @return the single MarkerAttribute instance corresponding to
* the name/value-pair
*/
- private static MarkerAttribute getFOAttributeInstance(
+ private static MarkerAttribute getInstance(
+ String namespace, String qname,
String name, String value) {
- MarkerAttribute newInstance = null;
- Map valueCache;
- if (!foAttributeCache.containsKey(name)) {
- newInstance = new MarkerAttribute(null, name, name, value);
- valueCache = Collections.synchronizedMap(
- new java.util.HashMap());
- valueCache.put(value, newInstance);
- foAttributeCache.put(name, valueCache);
- } else {
- valueCache = (Map) foAttributeCache.get(name);
- if (valueCache.containsKey(value)) {
- newInstance = (MarkerAttribute) valueCache.get(value);
- } else {
- newInstance = new MarkerAttribute(null, name, name, value);
- valueCache.put(value, newInstance);
- }
+ MarkerAttribute newInstance =
+ new MarkerAttribute(namespace, qname, name, value);
+ if (attributeCache.containsKey(newInstance)) {
+ return (MarkerAttribute) attributeCache.get(newInstance);
+ } else {
+ attributeCache.put(newInstance, newInstance);
+ return newInstance;
+ }
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object o) {
+ if (o instanceof MarkerAttribute) {
+ MarkerAttribute attr = (MarkerAttribute) o;
+ return ((attr.namespace == this.namespace)
+ || (attr.namespace != null
+ && attr.namespace.equals(this.namespace)))
+ && ((attr.qname == this.qname)
+ || (attr.qname != null
+ && attr.qname.equals(this.qname)))
+ && ((attr.name == this.name)
+ || (attr.name != null
+ && attr.name.equals(this.name)))
+ && ((attr.value == this.value)
+ || (attr.value != null
+ && attr.value.equals(this.value)));
+ } else {
+ return false;
}
- return newInstance;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org