/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * This package contains documentation from OpenGIS specifications. * OpenGIS consortium's work is fully acknowledged here. */ package org.geotools.referencing; import java.util.AbstractMap; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.opengis.referencing.datum.Datum; import org.opengis.referencing.ReferenceSystem; import org.opengis.referencing.IdentifiedObject; import org.opengis.referencing.operation.CoordinateOperation; import org.geotools.util.MapEntry; import org.geotools.referencing.operation.AbstractCoordinateOperation; /** * An immutable map fetching all properties from the specified identified object. Calls * to {@code get} methods are forwarded to the appropriate {@link IdentifiedObject} method. * * @since 2.1 * @source $URL$ * @version $Id$ * @author Martin Desruisseaux (IRD) */ final class Properties extends AbstractMap { /** * The object where all properties come from. */ private final IdentifiedObject info; /** * The entries set. Will be constructed only when first needed. */ private transient Set> entries; /** * Creates new properties from the specified identified object. */ public Properties(final IdentifiedObject info) { this.info = info; AbstractIdentifiedObject.ensureNonNull("info", info); } /** * Returns true if this map contains a mapping for the specified key. */ @Override public boolean containsKey(final Object key) { return get(key) != null; } /** * Returns the value to which this map maps the specified key. * Returns null if the map contains no mapping for this key. */ @Override public Object get(final Object key) { if (key instanceof String) { final String s = ((String) key).trim(); for (int i=0; iThe index of each element in this array * must matches the index searched by {@link #get(int)}. * * @todo Add properties for {@link IdentifiedObject} sub-interfaces. */ private static final String[] KEYS = { /*[0]*/IdentifiedObject .NAME_KEY, /*[1]*/IdentifiedObject .IDENTIFIERS_KEY, /*[2]*/IdentifiedObject .ALIAS_KEY, /*[3]*/IdentifiedObject .REMARKS_KEY, /*[4]*/CoordinateOperation .SCOPE_KEY, // same in Datum and ReferenceSystem /*[5]*/CoordinateOperation .DOMAIN_OF_VALIDITY_KEY, // same in Datum and ReferenceSystem /*[6]*/CoordinateOperation .OPERATION_VERSION_KEY, /*[7]*/CoordinateOperation .COORDINATE_OPERATION_ACCURACY_KEY }; /** * Returns a set view of the mappings contained in this map. */ @Override public Set> entrySet() { if (entries == null) { entries = new HashSet>(Math.round(KEYS.length / 0.75f) + 1, 0.75f); for (int i=0; i(KEYS[i], value)); } } entries = Collections.unmodifiableSet(entries); } return entries; } }