/*
* 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.cs;
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.geotools.referencing.AbstractIdentifiedObject;
/**
* A coordinate system made of two or more independent coordinate systems.
*
*
* Used with CRS type(s) |
*
* {@link org.geotools.referencing.crs.DefaultCompoundCRS Compound}
* |
*
* @since 2.1
*
* @source $URL$
* @version $Id$
* @author Martin Desruisseaux (IRD)
*/
public class DefaultCompoundCS extends AbstractCS {
/**
* Serial number for interoperability with different versions.
*/
private static final long serialVersionUID = -5726410275278843372L;
/**
* The coordinate systems.
*/
private final CoordinateSystem[] cs;
/**
* An immutable view of {@link #cs} as a list. Will be created only when first needed.
*/
private transient List asList;
/**
* Constructs a compound coordinate system. A name for this CS will
* be automatically constructed from the name of all specified CS.
*
* @param cs The set of coordinate syztem.
*/
public DefaultCompoundCS(CoordinateSystem[] cs) {
super(getName(cs=clone(cs)), getAxis(cs));
this.cs = cs;
}
/**
* Returns a clone of the specified array. This method would be bundle right
* into the constructor if RFE #4093999 was fixed.
*/
private static CoordinateSystem[] clone(CoordinateSystem[] cs) {
ensureNonNull("cs", cs);
cs = cs.clone();
for (int i=0; i getCoordinateSystems() {
if (asList == null) {
asList = Collections.unmodifiableList(Arrays.asList(cs));
}
return asList;
}
/**
* Compares this coordinate system with the specified object for equality.
*
* @param object The object to compare to {@code this}.
* @param compareMetadata {@code true} for performing a strict comparaison, or
* {@code false} for comparing only properties relevant to transformations.
* @return {@code true} if both objects are equal.
*/
@Override
public boolean equals(final AbstractIdentifiedObject object, final boolean compareMetadata) {
if (object == this) {
return true; // Slight optimization.
}
if (super.equals(object, compareMetadata)) {
final DefaultCompoundCS that = (DefaultCompoundCS) object;
return equals(this.cs, that.cs, compareMetadata);
}
return false;
}
}