*/
public static class Maker extends ListProperty.Maker {
- /** {@inheritDoc} */
+ /**
+ * Construct an instance of a Maker for the given property.
+ *
+ * @param propId The Constant ID of the property to be made.
+ */
public Maker(int propId) {
super(propId);
}
* Returns a {@link org.apache.fop.datatypes.PercentBase} whose
* <code>getDimension()</code> returns 1.
*/
- public PercentBase getPercentBase() {
+ public PercentBase getPercentBase(PropertyList pl) {
return new PercentBase() {
/** {@inheritDoc} */
public int getBaseLength(PercentBaseContext context) throws PropertyException {
}
/** cache containing all canonical CharacterProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(CharacterProperty.class);
private final char character;
public final class ColorProperty extends Property {
/** cache holding canonical ColorProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(ColorProperty.class);
/**
* The color represented by this property.
*
* @param foUserAgent FOP user agent
* @param value RGB value as String to be parsed
+ * @return the canonical ColorProperty instance corresponding
+ * to the given value
* @throws PropertyException if the value can't be parsed
* @see ColorUtil#parseColorString(FOUserAgent, String)
*/
ColorProperty instance = new ColorProperty(
ColorUtil.parseColorString(
foUserAgent, value));
- return (ColorProperty) cache.fetch(instance);
+ return (ColorProperty)cache.fetch(instance);
}
- /**
- * Returns an instance of a color property given a color
- * @param color the color value
- * @return the color property
- */
- public static ColorProperty getInstance(Color color) {
- return (ColorProperty) cache.fetch(new ColorProperty(color));
- }
-
/**
* Create a new ColorProperty with a given color.
*
/** cache holding canonical CommonFont instances (only those with
* absolute font-size and font-size-adjust) */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(CommonFont.class);
/**
* Class holding canonical instances of bundles of the
protected static final class CachedCommonFont {
/** cache holding all canonical instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(CachedCommonFont.class);
private int hash = 0;
/** Logger */
protected static Log log = LogFactory.getLog(CommonHyphenation.class);
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(CommonHyphenation.class);
private int hash = 0;
public final class EnumNumber extends Property implements Numeric {
/** cache holding all canonical EnumNumber instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(EnumNumber.class);
private final EnumProperty enumProperty;
public final class EnumProperty extends Property {
/** cache holding all canonical EnumProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(EnumProperty.class);
/**
* Inner class for creating EnumProperty instances
public static final String MPT = "mpt";
/** cache holding all canonical FixedLength instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(FixedLength.class);
/** canonical zero-length instance */
public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, FixedLength.MPT, 1.0f);
public final class FontFamilyProperty extends ListProperty {
/** cache holding all canonical FontFamilyProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(FontFamilyProperty.class);
private int hash = 0;
public final class KeepProperty extends Property implements CompoundDatatype {
/** class holding all canonical KeepProperty instances*/
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(KeepProperty.class);
private boolean isCachedValue = false;
private Property withinLine;
}
/** cache holding all canonical NumberProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(NumberProperty.class);
private final Number number;
/** the table of hash-buckets */
private CacheEntry[] table = new CacheEntry[8];
- boolean[] votesForRehash = new boolean[SEGMENT_MASK + 1];
+ private Class runtimeType;
+
+ final boolean[] votesForRehash = new boolean[SEGMENT_MASK + 1];
/* same hash function as used by java.util.HashMap */
private static int hash(Object x) {
/* Wrapper objects to synchronize on */
private final class CacheSegment {
private int count = 0;
- private ReferenceQueue staleEntries = new ReferenceQueue();
+ private volatile ReferenceQueue staleEntries = new ReferenceQueue();
}
- private final void cleanSegment(int segmentIndex) {
+ private void cleanSegment(int segmentIndex) {
CacheEntry entry;
CacheSegment segment = segments[segmentIndex];
int bucketIndex;
}
synchronized (votesForRehash) {
if (oldCount > segment.count) {
- if (votesForRehash[segmentIndex]) {
- votesForRehash[segmentIndex] = false;
- }
+ votesForRehash[segmentIndex] = false;
return;
- } else {
- /* cleanup had no effect */
- if (!votesForRehash[segmentIndex]) {
- /* first time for this segment */
- votesForRehash[segmentIndex] = true;
- int voteCount = 0;
- for (int i = SEGMENT_MASK + 1; --i >= 0; ) {
- if (votesForRehash[i]) {
- voteCount++;
- }
+ }
+ /* cleanup had no effect */
+ if (!votesForRehash[segmentIndex]) {
+ /* first time for this segment */
+ votesForRehash[segmentIndex] = true;
+ int voteCount = 0;
+ for (int i = SEGMENT_MASK + 1; --i >= 0; ) {
+ if (votesForRehash[i]) {
+ voteCount++;
}
- if (voteCount > SEGMENT_MASK / 4) {
- rehash(SEGMENT_MASK);
- /* reset votes */
- for (int i = SEGMENT_MASK + 1; --i >= 0;) {
- votesForRehash[i] = false;
- }
-
+ }
+ if (voteCount > SEGMENT_MASK / 4) {
+ rehash(SEGMENT_MASK);
+ /* reset votes */
+ for (int i = SEGMENT_MASK + 1; --i >= 0;) {
+ votesForRehash[i] = false;
}
+
}
}
}
* cleanup will be performed to try and remove obsolete
* entries.
*/
- private final void put(Object o) {
+ private void put(Object o) {
int hash = hash(o);
CacheSegment segment = segments[hash & SEGMENT_MASK];
/* Gets a cached instance. Returns null if not found */
- private final Object get(Object o) {
+ private Object get(Object o) {
int hash = hash(o);
int index = hash & (table.length - 1);
* extends the cache and redistributes the entries.
*
*/
- private final void rehash(int index) {
+ private void rehash(int index) {
CacheSegment seg = segments[index];
synchronized (seg) {
}
/**
- * Default constructor.
+ * Default constructor.
+ *
+ * @param c Runtime type of the objects that will be stored in the cache
*/
- public PropertyCache() {
+ public PropertyCache(Class c) {
for (int i = SEGMENT_MASK + 1; --i >= 0;) {
segments[i] = new CacheSegment();
}
+ this.runtimeType = c;
}
/**
* @param obj the Object to check for
* @return the cached instance
*/
- private final Object fetch(Object obj) {
+ private Object fetch(Object obj) {
if (obj == null) {
return null;
}
return (CommonFont) fetch((Object) cf);
}
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return super.toString() + "[runtimeType=" + this.runtimeType + "]";
+ }
+
+
}
value = str;
}
}
- return new StringProperty(value);
+ return StringProperty.getInstance(value);
}
- } // end String.Maker
+ }
/** cache containing all canonical StringProperty instances */
- private static final PropertyCache cache = new PropertyCache();
+ private static final PropertyCache cache = new PropertyCache(StringProperty.class);
+
+ /** canonical instance for empty strings */
+ public static final StringProperty EMPTY_STRING_PROPERTY = new StringProperty("");
private final String str;
* @return the canonical instance
*/
public static StringProperty getInstance(String str) {
- return (StringProperty)cache.fetch(
- new StringProperty(str));
+ if ("".equals(str) || str == null) {
+ return EMPTY_STRING_PROPERTY;
+ } else {
+ return (StringProperty)cache.fetch(
+ new StringProperty(str));
+ }
}
- /**
- * @return the Object equivalent of this property
- */
+ /** @return the Object equivalent of this property */
public Object getObject() {
return this.str;
}
- /**
- * @return the String equivalent of this property
- */
+ /** @return the String equivalent of this property */
public String getString() {
return this.str;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
if (obj instanceof StringProperty) {
StringProperty sp = (StringProperty)obj;
return (sp.str == this.str
|| sp.str.equals(this.str));
- } else {
- return false;
}
+ return false;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode() {
return str.hashCode();
}