@@ -0,0 +1,2700 @@
+import java.lang.ref.WeakReference;%0Aimport java.util.WeakHashMap;%0Aimport java.util.Collections;%0Aimport java.util.EnumSet;%0Aimport java.util.Set;%0Aimport java.awt.Color;%0Apublic final class FontData %7B%0A    enum FontEffect %7B%0A        BOLD, ITALIC, SUPERSCRIPT, SUBSCRIPT, STRIKETHROUGH%0A    %7D%0A    /**%0A     * A weak hash map will drop unused references to FontData.%0A     * Values have to be wrapped in WeakReferences, %0A     * because value objects in weak hash map are held by strong references.%0A     */%0A    private static final WeakHashMap%3CFontData, WeakReference%3CFontData%3E%3E FLY_WEIGHT_DATA =%0A        new WeakHashMap%3CFontData, WeakReference%3CFontData%3E%3E();%0A    private final int pointSize;%0A    private final String fontFace;%0A    private final Color color;%0A    private final Set%3CFontEffect%3E effects;%0A    private FontData(int pointSize, String fontFace, Color color, EnumSet%3CFontEffect%3E effects) %7B%0A        this.pointSize = pointSize;%0A        this.fontFace = fontFace;%0A        this.color = color;%0A        this.effects = Collections.unmodifiableSet(effects);%0A    %7D%0A    public static FontData create(int pointSize, String fontFace, Color color,%0A        FontEffect... effects) %7B%0A        EnumSet%3CFontEffect%3E effectsSet = EnumSet.noneOf(FontEffect.class);%0A        for (FontEffect fontEffect : effects) %7B%0A            effectsSet.add(fontEffect);%0A        %7D%0A        // We are unconcerned with object creation cost, we are reducing overall memory consumption%0A        FontData data = new FontData(pointSize, fontFace, color, effectsSet);%0A        FontData result = null;%0A        // Retrieve previously created instance with the given values if it (still) exists%0A        WeakReference%3CFontData%3E ref = FLY_WEIGHT_DATA.get(data);%0A        if (ref != null) %7B%0A            result = ref.get();%0A        %7D%0A        // Store new font data instance if no matching instance exists%0A        if(result == null)%7B      %09%0A            FLY_WEIGHT_DATA.put(data, new WeakReference%3CFontData%3E (data));%0A            result = data;%0A        %7D%0A        // return the single immutable copy with the given values%0A        return result;%0A    %7D%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        if (obj instanceof FontData) %7B%0A            if (obj == this) %7B%0A                return true;%0A            %7D%0A            FontData other = (FontData) obj;%0A            return other.pointSize == pointSize && other.fontFace.equals(fontFace)%0A                && other.color.equals(color) && other.effects.equals(effects);%0A        %7D%0A        return false;%0A    %7D%0A    @Override%0A    public int hashCode() %7B%0A        return (pointSize * 37 + effects.hashCode() * 13) * fontFace.hashCode();%0A    %7D%0A    // Getters for the font data, but no setters. FontData is immutable.%0A%7D%0A

Create Flyweight.java