    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/framework/util/ParameterList.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036
    037    package org.deegree.framework.util;
    038
    039    import java.util.ArrayList;
    040    import java.util.HashMap;
    041
    042    /**
    043     * The interface defines the access to a list of paramters that can be used as submitted parameters to methods that may
    044     * receive an variable list of parameters.
    045     *
    046     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    047     * @author last edited by: $Author: mschneider $
    048     *
    049     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    050     */
    051    final public class ParameterList {
    052
    053        private HashMap<String, Parameter> params = new HashMap<String, Parameter>();
    054
    055        private ArrayList<String> keys = new ArrayList<String>( 100 );
    056
    057        /**
    058         * returns the parameter that matches the submitted name. if no parameter can be found <tt>null</tt> will be
    059         * returned.
    060         *
    061         * @param name
    062         * @return name parameter
    063         */
    064        public Parameter getParameter( String name ) {
    065            return params.get( name );
    066        }
    067
    068        /**
    069         * adds a new <tt>Parameter</tt> to the list
    070         *
    071         * @param name
    072         * @param value
    073         *
    074         */
    075        public void addParameter( String name, Object value ) {
    076            Parameter p = new Parameter( name, value );
    077            addParameter( p );
    078        }
    079
    080        /**
    081         * adds a new <tt>Parameter</tt> to the list
    082         *
    083         * @param param
    084         */
    085        public void addParameter( Parameter param ) {
    086            params.put( param.getName(), param );
    087            keys.add( param.getName() );
    088        }
    089
    090        /**
    091         * returns all <tt>Parameter</tt>s contained within the list as array. it is guarenteered that the arrays isn't
    092         * <tt>null</tt>
    093         *
    094         * @return returns an array with all Parameters from the list.
    095         */
    096        public Parameter[] getParameters() {
    097            Parameter[] p = new Parameter[keys.size()];
    098            int i = 0;
    099            for ( String key : keys ) {
    100                p[i++] = params.get( key );
    101            }
    102            return p;
    103        }
    104
    105        /**
    106         * returns an array of all <tt>Parameter</tt>s names. it is guarenteered that the arrays isn't <tt>null</tt>
    107         *
    108         * @return parameter names
    109         */
    110        public String[] getParameterNames() {
    111            String[] s = new String[keys.size()];
    112            return keys.toArray( s );
    113        }
    114
    115        /**
    116         * returns an array of all <tt>Parameter</tt>s values. it is guarenteered that the arrays isn't <tt>null</tt>
    117         *
    118         * @return parameter values
    119         */
    120        public Object[] getParameterValues() {
    121            Object[] o = new Object[keys.size()];
    122            for ( int i = 0; i < o.length; i++ ) {
    123                Parameter p = params.get( keys.get( i ) );
    124                o[i] = p.getValue();
    125            }
    126            return o;
    127        }
    128
    129        /**
    130         * removes a parameter from the list
    131         *
    132         * @param name
    133         *            name of the parameter
    134         * @return nemd parameter
    135         */
    136        public Parameter removeParameter( String name ) {
    137            keys.remove( name );
    138            return params.remove( name );
    139        }
    140
    141        /**
    142         * @return string representation
    143         */
    144        @Override
    145        public String toString() {
    146            String ret = null;
    147            ret = "params = " + params + "\n";
    148            return ret;
    149        }
    150
    151    }