001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: *
005: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
006: * (C) 2005, Institut de Recherche pour le Développement
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation;
011: * version 2.1 of the License.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: */
018: package org.geotools.referencing.operation.projection;
019:
020: // J2SE dependencies
021: import java.util.Iterator;
022: import java.util.Collection;
023:
024: // OpenGIS dependencies
025: import org.opengis.parameter.ParameterDescriptor;
026:
027: // Geotools dependencies
028: import org.geotools.parameter.DefaultParameterDescriptor;
029: import org.geotools.referencing.operation.MathTransformProvider; // For javadoc
030:
031: /**
032: * A parameter descriptor identical to the supplied one except for the
033: * default value. The constructor expects a model created by one of the
034: * {@linkplain MathTransformProvider#createDescriptor(Identifier[],double,double,double,Unit)
035: * provider methods}, usually using some neutral default value. For example the base class for
036: * map projection providers defines a set of
037: * {@linkplain org.geotools.referencing.operation.projection.MapProjection.Provider#SEMI_MAJOR
038: * commonly used parameter descriptors}. However some map projections are specific to a
039: * particular area (for example the {@linkplain NewZealandMapGrid New Zealand map grid}
040: * and may wish to override the neutral default values with some default value appropriate
041: * for that area.
042: *
043: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/projection/ModifiedParameterDescriptor.java $
044: * @version $Id: ModifiedParameterDescriptor.java 22474 2006-10-31 00:58:59Z desruisseaux $
045: * @author Martin Desruisseaux
046: */
047: final class ModifiedParameterDescriptor extends
048: DefaultParameterDescriptor {
049: /**
050: * For compatibility with different versions during deserialization.
051: */
052: private static final long serialVersionUID = -616587615222354457L;
053:
054: /**
055: * The original parameter descriptor. Used for comparaisons purpose only.
056: */
057: private final ParameterDescriptor original;
058:
059: /**
060: * The new default value.
061: */
062: private final Double defaultValue;
063:
064: /**
065: * Creates a parameter descriptor wrapping the specified one with the specified
066: * default value.
067: */
068: public ModifiedParameterDescriptor(
069: final ParameterDescriptor original,
070: final double defaultValue) {
071: super (original);
072: this .original = original;
073: this .defaultValue = new Double(defaultValue);
074: }
075:
076: /**
077: * Returns the default value for the parameter.
078: */
079: public Object getDefaultValue() {
080: return defaultValue;
081: }
082:
083: /**
084: * Returns {@code true} if the specified collection contains the specified descriptor. Invoking
085: * this method is similar to invoking {@code set.contains(descriptor)}, except that instance of
086: * {@link ModifiedParameterDescriptor} are unwrapped to their original descriptor. The drawback
087: * is that this method is slower than {@code set.contains(descriptor)}, so it should be invoked
088: * only if the former fails.
089: */
090: public static boolean contains(final Collection set,
091: ParameterDescriptor descriptor) {
092: if (descriptor instanceof ModifiedParameterDescriptor) {
093: descriptor = ((ModifiedParameterDescriptor) descriptor).original;
094: }
095: for (final Iterator it = set.iterator(); it.hasNext();) {
096: ParameterDescriptor candidate = (ParameterDescriptor) it
097: .next();
098: if (candidate instanceof ModifiedParameterDescriptor) {
099: candidate = ((ModifiedParameterDescriptor) candidate).original;
100: }
101: if (descriptor.equals(candidate)) {
102: return true;
103: }
104: }
105: assert !set.contains(descriptor);
106: return false;
107: }
108: }
|