commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Groß (JIRA) <>
Subject [jira] [Commented] (IMAGING-159) There should be a Parameters class
Date Thu, 29 Jan 2015 22:14:38 GMT


Michael Groß commented on IMAGING-159:

I made a fork from the github repository and created three new classes: org.apache.commons.imaging.Parameter
(which is supposed to replace ImagingConstants if my proposal is accepted) and org.apache.commons.imaging.ParameterObject
which is the requested parameter object class. The new code is located as shown above.

ParameterObject is an immutable object. If we really need to remove some parameters I would
add some code to return a new instance without the requested parameters if needed (saw this
somewhere in the code). The ParameterObject is build using a Builder so one can say

ParameterObject testObject =
            .setInt(Parameter.PARAM_KEY_EXIF, 21)

There is a class ParameterObjectTest among the test classes for org.apache.commons.imaging
which demonstrates this. One may place checks for the parameter values when stored as demonstrated

I added only code to store int and BinaryConstant objects. It's easy to add code for more
types. If my proposal is accepted I could start to change the existing code to use the parameter
object. I wish you a nice day!

> There should be a Parameters class
> ----------------------------------
>                 Key: IMAGING-159
>                 URL:
>             Project: Commons Imaging
>          Issue Type: Improvement
>          Components: imaging.*
>            Reporter: Benedikt Ritter
>             Fix For: Patch Needed
> Currently options for image I/O are defined as Maps. The leads to the problem that our
code has to validate parameter types when they are used:
> {code:java}
> final Object value = params.get(PARAM_KEY_COMPRESSION);
> if (value != null) {
>   if (!(value instanceof Number)) {
>     throw new ImageWriteException(
>       "Invalid compression parameter, must be numeric: "
>          + value);
>   }
>   compression = ((Number) value).intValue();
> }
> {code}
> This can be simplified if we define a Parameters class that provides additional methods
like {{public int getInt(String key)}}. The implementation could then look up the value from
the map through an exception if it is null or not a number.

This message was sent by Atlassian JIRA

View raw message