You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by bu...@apache.org on 2011/02/01 22:49:59 UTC

DO NOT REPLY [Bug 50703] New: [PATCH] Parametrize PropertyCache

https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

           Summary: [PATCH] Parametrize PropertyCache
           Product: Fop
           Version: 1.1dev
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: fo tree
        AssignedTo: fop-dev@xmlgraphics.apache.org
        ReportedBy: adelmelle@apache.org


Created an attachment (id=26590)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26590)
proposed patch

Attached patch parametrizes fop.fo.properties.PropertyCache.
As a result, all the different public fetch() overloads can be rolled into one,
and suddenly this class seems to have the potential for more general usage. Any
class offering reliable implementations for equals() and hashCode() is now a
candidate to store its canonical instances in the cache.

The idiom becomes:

PropertyCache<Type> cache = new PropertyCache<Type>(Type.class);

The constructor parameter is still needed, as I could not immediately find a
way to derive the class name (for debugging) from the type parameter. Don't
know if there even is one... At any rate, the correspondence between
constructor and type parameter is enforced by the constructor, so it would not
be possible to write:

new PropertyCache<TypeA>(TypeB.class)

not even if TypeB is a subclass of TypeA.

If I judge correctly, applying this patch by itself should, at worst, cause a
few unchecked warnings to pop up in the fo.properties package. Locally, I have
already adapted all the properties that use it (and added a few new classes),
but I kept these changes out of the patch for now, to focus on the main change.

Suggestions welcome. Would it be useful outside of the fo.properties package as
well? Could it migrate to fop.util?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 50703] [PATCH] Parametrize PropertyCache

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

--- Comment #1 from Jeremias Maerki <je...@apache.org> 2011-02-02 03:20:24 EST ---
Makes sense.

Not sure that's what you're looking for but you can add this to PropertyCache:

    public static <T> PropertyCache<T> createFor(Class<T> c) {
        return new PropertyCache<T>(c);
    }

Then later:

    private static final PropertyCache<FontFamilyProperty> CACHE
        = PropertyCache.createFor(FontFamilyProperty.class);

I don't think it makes sense to move out PropertyCache just yet. I wouldn't do
this before we have another use case outside that package.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 50703] [PATCH] Parametrize PropertyCache

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

Alex Giotis <al...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 50703] [PATCH] Parametrize PropertyCache

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

Alex Giotis <al...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Alex Giotis <al...@gmail.com> 2012-03-22 18:44:59 UTC ---
This suggested change on PropertyCache was included in #46962
http://svn.apache.org/viewvc?rev=1303891&view=rev

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 50703] [PATCH] Parametrize PropertyCache

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

--- Comment #2 from Andreas L. Delmelle <ad...@apache.org> 2011-02-02 15:58:50 EST ---

> Not sure that's what you're looking for but you can add this to PropertyCache:
> 
>     public static <T> PropertyCache<T> createFor(Class<T> c) {
>         return new PropertyCache<T>(c);
>     }

Good suggestion. That would at least slightly shorten the creation statements
in the various property classes.

Comes very close, but what I was actually looking for was a way to leave out
the constructor parameter completely, and in the constructor, infer the Class
from the type parameter T, so something in the direction of

  this.runtimeType = T.class;

Quite impossible, obviously, given the implementation of generics. In the end,
T only exists for the compiler...

The idiom would then just be very standard:
  PropertyCache<FontFamilyProperty> CACHE
    = new PropertyCache<FontFamilyProperty>();

(and as of Java 7, IIC, even more concise:
  PropertyCache<FontFamilyProperty> CACHE = new PropertyCache<>();
)

The more I think about it, the more I am tempted to go for just dropping the
parameter, or maybe providing it only as an alternate constructor. Ultimately,
it's only use is for debugging. I had added this, but must admit, I have never
really used it...

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 50703] [PATCH] Parametrize PropertyCache

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50703

Andreas L. Delmelle <ad...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #26590|application/octet-stream    |text/plain
          mime type|                            |
  Attachment #26590|0                           |1
           is patch|                            |

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.