commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Groß (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (IMAGING-159) There should be a Parameters class
Date Thu, 29 Jan 2015 22:15:35 GMT

    [ https://issues.apache.org/jira/browse/IMAGING-159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14297804#comment-14297804
] 

Michael Groß edited comment on IMAGING-159 at 1/29/15 10:15 PM:
----------------------------------------------------------------

http://github.com/mgmechanics/commons-imaging/tree/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

{noformat}
ParameterObject testObject = ParameterObject.build()
            .setInt(Parameter.PARAM_KEY_EXIF, 21)
            .setBinaryConstant(Parameter.PARAM_KEY_STRICT,
                    JpegConstants.JFIF0_SIGNATURE)
            .get();

           testObject.getInt(Parameter.PARAM_KEY_EXIF); // => 21
          testObject.getBinaryConstant(Parameter.PARAM_KEY_STRICT).get(0); // => 0x4a
{noformat}

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
too.

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!


was (Author: mgmechanics):
http://github.com/mgmechanics/commons-imaging/tree/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

{noformat}
ParameterObject testObject = ParameterObject.build()
            .setInt(Parameter.PARAM_KEY_EXIF, 21)
            .setBinaryConstant(Parameter.PARAM_KEY_STRICT,
                    JpegConstants.JFIF0_SIGNATURE)
            .get();
{noformat}

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
too.

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: https://issues.apache.org/jira/browse/IMAGING-159
>             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
(v6.3.4#6332)

Mime
View raw message