001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/model/feature/DefaultFeatureCollection.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstraße 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 package org.deegree.model.feature; 044 045 import java.io.Serializable; 046 import java.util.ArrayList; 047 import java.util.Iterator; 048 import java.util.List; 049 050 import org.deegree.datatypes.QualifiedName; 051 import org.deegree.io.datastore.PropertyPathResolvingException; 052 import org.deegree.model.feature.schema.FeatureType; 053 import org.deegree.model.spatialschema.Envelope; 054 import org.deegree.model.spatialschema.GeometryException; 055 import org.deegree.ogcbase.PropertyPath; 056 057 /** 058 * This interface provides services for the management of groups of features. These groups can come 059 * into being for a number of reasons: e.g. a project as a whole, for the scope of a query, as the 060 * result of a query or arbitrarily selected by a user for some common manipulation. A feature's 061 * membership of a particular FeatureCollection does not necessarily imply any relationship with 062 * other member features. Composite or compound features which own constituent member Features (e.g. 063 * an Airport composed of Terminals, Runways, Aprons, Hangars, etc) may also support the 064 * FeatureCollection interface to provide a generic means for clients to access constituent members 065 * without needing to be aware of the internal implementation details of the compound feature. 066 * <p> 067 * ----------------------------------------------------------------------- 068 * </p> 069 * 070 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 071 * @version $Revision: 11341 $ $Date: 2008-04-22 12:08:33 +0200 (Di, 22 Apr 2008) $ 072 */ 073 class DefaultFeatureCollection extends AbstractFeatureCollection implements Serializable { 074 075 private List<Feature> collection = null; 076 077 private Envelope envelope = null; 078 079 DefaultFeatureCollection( String id, int initialCapacity ) { 080 super( id ); 081 collection = new ArrayList<Feature>( initialCapacity ); 082 } 083 084 /** 085 * constructor for initializing a featur collection with an id and an array of features. 086 */ 087 DefaultFeatureCollection( String id, Feature[] feature ) { 088 this( id, feature.length ); 089 for ( int i = 0; i < feature.length; i++ ) { 090 add( feature[i] ); 091 } 092 } 093 094 /* 095 * (non-Javadoc) 096 * 097 * @see org.deegree.model.feature.FeatureCollection#clear() 098 */ 099 public void clear() { 100 collection.clear(); 101 } 102 103 /** 104 * returns the FeatureType of this Feature(Collection) 105 */ 106 public FeatureType getFeatureType() { 107 return this.featureType; 108 } 109 110 /** 111 * returns an array of all features 112 */ 113 public Feature[] toArray() { 114 return collection.toArray( new Feature[collection.size()] ); 115 } 116 117 /** 118 * returns an <tt>Iterator</tt> on the feature contained in a collection 119 * 120 * @return an <tt>Iterator</tt> on the feature contained in a collection 121 */ 122 public Iterator<Feature> iterator() { 123 return collection.iterator(); 124 } 125 126 /** 127 * returns the feature that is assigned to the submitted index. If the submitted value for 128 * <tt>index</tt> is smaller 0 and larger then the number features within the 129 * featurecollection-1 an exeption will be thrown. 130 */ 131 public Feature getFeature( int index ) { 132 return collection.get( index ); 133 } 134 135 /** 136 * returns the feature that is assigned to the submitted id. If no valid feature could be found 137 * an <tt>Object[]</tt> with zero length will be returned. 138 */ 139 public Feature getFeature( String id ) { 140 Feature feature = null; 141 for ( int i = 0; i < collection.size(); i++ ) { 142 feature = collection.get( i ); 143 if ( feature.getId().equals( id ) ) { 144 break; 145 } 146 } 147 return feature; 148 } 149 150 /** 151 * removes the submitted feature from the collection 152 */ 153 public Feature remove( Feature feature ) { 154 int index = collection.indexOf( feature ); 155 return remove( index ); 156 } 157 158 /** 159 * removes a feature identified by its index from the feature collection. The removed feature 160 * will be returned. If the submitted value for <tt>index</tt> is smaller 0 and larger then 161 * the number features within the featurecollection-1 an ArrayIndexOutOfBoundsExcpetion will 162 * raise 163 */ 164 public Feature remove( int index ) { 165 return collection.remove( index ); 166 } 167 168 /** 169 * Appends a feature to the collection. If the submitted feature doesn't matches the feature 170 * type defined for all features within the collection an exception will be thrown. 171 */ 172 public void add( Feature feature ) { 173 collection.add( feature ); 174 } 175 176 /** 177 * returns the number of features within the collection 178 */ 179 public int size() { 180 return collection.size(); 181 } 182 183 public void setProperty( FeatureProperty property, int index ) { 184 // TODO Auto-generated method stub 185 } 186 187 public void addProperty( FeatureProperty property ) { 188 // TODO Auto-generated method stub 189 } 190 191 public void removeProperty( QualifiedName propertyName ) { 192 // TODO Auto-generated method stub 193 } 194 195 public void replaceProperty( FeatureProperty oldProperty, FeatureProperty newProperty ) { 196 // TODO Auto-generated method stub 197 } 198 199 /** 200 * returns the envelope / boundingbox of the feature collection 201 */ 202 @Override 203 public synchronized Envelope getBoundedBy() 204 throws GeometryException { 205 206 Envelope combinedEnvelope = this.envelope; 207 208 if ( combinedEnvelope == null && this.collection.size() > 0 ) { 209 for ( int i = 0; i < this.collection.size(); i++ ) { 210 Envelope nextFeatureEnvelope = this.collection.get( i ).getBoundedBy(); 211 if ( combinedEnvelope == null ) { 212 combinedEnvelope = nextFeatureEnvelope; 213 } else if ( nextFeatureEnvelope != null ) { 214 combinedEnvelope = combinedEnvelope.merge( nextFeatureEnvelope ); 215 } 216 } 217 this.envelope = combinedEnvelope; 218 } 219 return combinedEnvelope; 220 } 221 222 @Override 223 public void setEnvelopesUpdated(){ 224 this.envelope = null; 225 } 226 227 @Override 228 public String toString() { 229 String ret = null; 230 ret = "collection = " + collection + "\n"; 231 return ret; 232 } 233 234 public FeatureProperty getDefaultProperty( PropertyPath path ) 235 throws PropertyPathResolvingException { 236 // TODO Auto-generated method stub 237 return null; 238 } 239 240 }