Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 414E817593 for ; Fri, 30 Jan 2015 20:59:47 +0000 (UTC) Received: (qmail 82486 invoked by uid 500); 30 Jan 2015 20:59:46 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 79900 invoked by uid 500); 30 Jan 2015 20:59:39 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 76283 invoked by uid 99); 30 Jan 2015 20:59:35 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Jan 2015 20:59:35 +0000 Date: Fri, 30 Jan 2015 20:59:35 +0000 (UTC) From: =?utf-8?Q?Michael_Gro=C3=9F_=28JIRA=29?= To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (IMAGING-159) There should be a Parameters class MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IMAGING-159?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D142= 99220#comment-14299220 ]=20 Michael Gro=C3=9F commented on IMAGING-159: -------------------------------------- @[~britter] Don't worry, maybe [~ebourg] is right. The builder-pattern appr= oach requires the user to know/remember of which type a parameter value is = to get the value. I completed a second proposal at http://github.com/mgmechanics/commons-imaging/tree/IMAGING-159-POJO which uses the POJO/inheritance pattern as he pointed out. I did not apply = the new classes (org.apache.commons.imaging.ImagingParameters/~Jpeg/~Tiff) = but I am willing to do this when my patch is accepted. For some values I found default values, for some not. For PARAM_KEY_VERBOSE= I assumed Boolean.FALSE. If there are more default values, please let me k= now. Each default value means one isXyzPresent() method less. I avoid strictly to return null values. There are few people in Java-relate= d projects which doesn't know what an "NPE" (NullPointerException) is, so c= ommon is it. Lessons learned for me: If the value wasn't set when we try to= get it there is a RuntimeException. It should pop up during testing and we= will go there and fix it. You may ask via isXyzPresent() if a value was se= t so you never get the RuntimeException. "if (xyz =3D=3D null)" would mean = to know that null means "this parameter didn't got a value yet". "if isXyzP= resent()" seems to be more obvious. Its merely a lesson I learned. > 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 pro= blem that our code has to validate parameter types when they are used: > {code:java} > final Object value =3D params.get(PARAM_KEY_COMPRESSION); > if (value !=3D null) { > if (!(value instanceof Number)) { > throw new ImageWriteException( > "Invalid compression parameter, must be numeric: " > + value); > } > compression =3D ((Number) value).intValue(); > } > {code} > This can be simplified if we define a Parameters class that provides addi= tional methods like {{public int getInt(String key)}}. The implementation c= ould 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)