source: osm/applications/editors/josm/plugins/opendata/includes/org/geotools/data/Query.java@ 28000

Last change on this file since 28000 was 28000, checked in by donvip, 12 years ago

Import new "opendata" JOSM plugin

File size: 28.9 KB
Line 
1/*
2 * GeoTools - The Open Source Java GIS Toolkit
3 * http://geotools.org
4 *
5 * (C) 2008, Open Source Geospatial Foundation (OSGeo)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation;
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 */
17package org.geotools.data;
18
19import java.net.URI;
20import java.util.ArrayList;
21import java.util.Arrays;
22import java.util.Collections;
23import java.util.List;
24
25import org.opengis.filter.Filter;
26import org.opengis.filter.FilterFactory;
27import org.opengis.filter.expression.PropertyName;
28import org.opengis.filter.sort.SortBy;
29import org.opengis.referencing.crs.CoordinateReferenceSystem;
30import org.geotools.factory.CommonFactoryFinder;
31import org.geotools.factory.Hints;
32
33/**
34 * Encapsulates a request for data, typically as:
35 * <pre><code>
36 * Query query = ...
37 * myFeatureSource.getFeatures(query);
38 * </code></pre>
39 *
40 * The query class is based on the Web Feature Server specification and offers a
41 * few interesting capabilities such as the ability to sort results and use a filter
42 * (similar to the WHERE clause in SQL).
43 * <p>
44 * Additional capabilities:
45 * <ul>
46 * <li>
47 * {@linkplain #setMaxFeatures(int)} and {@linkplain #setStartIndex(Integer)} can be used
48 * implement 'paging' through the data source's content. This is useful if, for example, the
49 * FeatureSource has an upper limit on the number of features it can return in a single
50 * request or you are working with limited memory.
51 * </li>
52 * <li>
53 * {@linkplain #setHandle(String)} can be used to give the query a mnemonic name
54 * which will appear in error reporing and logs.
55 * </li>
56 * <li>
57 * {@linkplain #setCoordinateSystem(CoordinateReferenceSystem)} is used to to specify the
58 * coordinate system that retrieved features will be "forced" into.
59 * This is often used to correct a feature source when the application and the data
60 * format have different ideas about the coordinate system (for example, the "axis order"
61 * issue).
62 * </li>
63 * <li>
64 * {@linkplain #setCoordinateSystemReproject(CoordinateReferenceSystem)} is used to ask for
65 * the retrieved features to be reproejcted.
66 * </li>
67 * </ul>
68 *
69 * Vendor specific:
70 * <ul>
71 * <li>{@linkplain setHints(Hints)} is used to specify venfor specific capabilities
72 * provided by a feature source implementation.
73 * </li>
74 * </ul>
75 * Example:<pre><code>
76 * Filter filter = CQL.toFilter("NAME like '%land'");
77 * Query query = new Query( "countries", filter );
78 *
79 * FeatureCollection features = featureSource.getFeatures( query );
80 * </code></pre>
81 *
82 * @author Chris Holmes
83 *
84 * @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Query.java $
85 * @version $Id: Query.java 37280 2011-05-24 07:53:02Z mbedward $
86 */
87public class Query {
88 /**
89 * Constant (actually null) used to represent no namespace restrictions on the returned result, should be considered ANY_URI
90 */
91 public static final URI NO_NAMESPACE = null;
92
93 /** So getMaxFeatures does not return null we use a very large number. */
94 public static final int DEFAULT_MAX = Integer.MAX_VALUE;
95
96 /**
97 * Implements a query that will fetch all features from a datasource. This
98 * query should retrieve all properties, with no maxFeatures, no
99 * filtering, and the default featureType.
100 */
101 public static final Query ALL = new ALLQuery();
102
103 /**
104 * A constant (empty String array) that can be used with
105 * {@linkplain #setPropertyNames(String[])} to indicate that no
106 * properties are to be retrieved.
107 * <p>
108 * Note the query will still return a result - limited to FeatureIDs.
109 * </p>
110 */
111 public static final String[] NO_NAMES = new String[0];
112
113 /**
114 * A constant (value {@code null}) that can be used with
115 * {@linkplain #setPropertyNames(String[])} to indicate that all properties
116 * are to be retrieved.
117 */
118 public static final String[] ALL_NAMES = null;
119
120 /**
121 * A constant (value {@code null}) that can be used with
122 * {@linkplain #setProperties(Collection<PropertyName>)} to indicate that all properties
123 * are to be retrieved.
124 */
125 public static final List<PropertyName> ALL_PROPERTIES = null;
126
127 /** The properties to fetch */
128 protected List<PropertyName> properties;
129
130 /** The maximum numbers of features to fetch */
131 protected int maxFeatures = Query.DEFAULT_MAX;
132
133 /** The index of the first feature to process */
134 protected Integer startIndex = null;
135
136 /** The filter to constrain the request. */
137 protected Filter filter = Filter.INCLUDE;
138
139 /** The typeName to get */
140 protected String typeName;
141
142 /** The namespace to get */
143 protected URI namespace =Query.NO_NAMESPACE;
144
145 /** The handle associated with this query. */
146 protected String handle;
147
148 /** Coordinate System associated with this query */
149 protected CoordinateReferenceSystem coordinateSystem;
150
151 /** Reprojection associated associated with this query */
152 protected CoordinateReferenceSystem coordinateSystemReproject;
153
154 /** Sorting for the query */
155 protected SortBy[] sortBy;
156
157 /** The version according to WFS 1.0 and 1.1 specs */
158 protected String version;
159
160 /** The hints to be used during query execution */
161 protected Hints hints;
162
163 /**
164 * Default constructor. Use setter methods to configure the Query
165 * before use (the default Query will retrieve all features).
166 */
167 public Query() {
168 // no arg
169 }
170
171 /**
172 * Constructor.
173 *
174 * @param typeName the name of the featureType to retrieve
175 */
176 public Query( String typeName ){
177 this( typeName, Filter.INCLUDE );
178 }
179
180 /**
181 * Constructor.
182 *
183 * @param typeName the name of the featureType to retrieve.
184 * @param filter the OGC filter to constrain the request.
185 */
186 public Query(String typeName, Filter filter) {
187 this( typeName, filter, Query.ALL_NAMES );
188 }
189
190 /**
191 * Constructor.
192 *
193 * @param typeName the name of the featureType to retrieve.
194 * @param filter the OGC filter to constrain the request.
195 * @param properties an array of the properties to fetch.
196 */
197 public Query(String typeName, Filter filter, String[] properties) {
198 this( typeName, null, filter, Query.DEFAULT_MAX, properties, null );
199 }
200
201 /**
202 * Constructor.
203 *
204 * @param typeName the name of the featureType to retrieve.
205 * @param filter the OGC filter to constrain the request.
206 * @param maxFeatures the maximum number of features to be returned.
207 * @param propNames an array of the properties to fetch.
208 * @param handle the name to associate with this query.
209 */
210 public Query(String typeName, Filter filter, int maxFeatures,
211 String[] propNames, String handle) {
212 this(typeName, null, filter, maxFeatures, propNames, handle );
213 }
214
215 /**
216 * Constructor.
217 *
218 * @param typeName the name of the featureType to retrieve.
219 * @param namespace Namespace for provided typeName, or null if unspecified
220 * @param filter the OGC filter to constrain the request.
221 * @param maxFeatures the maximum number of features to be returned.
222 * @param propNames an array of the properties to fetch.
223 * @param handle the name to associate with the query.
224 */
225 public Query( String typeName, URI namespace, Filter filter, int maxFeatures,
226 String[] propNames, String handle) {
227 this.typeName = typeName;
228 this.filter = filter;
229 this.namespace = namespace;
230 this.maxFeatures = maxFeatures;
231 this.handle = handle;
232 setPropertyNames(propNames);
233 }
234
235 /**
236 * Constructor.
237 *
238 * @param typeName the name of the featureType to retrieve.
239 * @param namespace Namespace for provided typeName, or null if unspecified
240 * @param filter the OGC filter to constrain the request.
241 * @param maxFeatures the maximum number of features to be returned.
242 * @param properties a list of the property names to fetch.
243 * @param handle the name to associate with the query.
244 */
245 public Query( String typeName, URI namespace, Filter filter, int maxFeatures,
246 List<PropertyName> propNames, String handle) {
247 this.typeName = typeName;
248 this.filter = filter;
249 this.namespace = namespace;
250 this.maxFeatures = maxFeatures;
251 this.handle = handle;
252 this.properties = propNames==null? null : new ArrayList<PropertyName>(propNames);
253 }
254
255 /**
256 * Copy contructor.
257 *
258 * @param query the query to copy
259 */
260 public Query(Query query) {
261 this(query.getTypeName(), query.getNamespace(), query.getFilter(), query.getMaxFeatures(),
262 query.getProperties(), query.getHandle());
263 this.sortBy = query.getSortBy();
264 this.coordinateSystem = query.getCoordinateSystem();
265 this.coordinateSystemReproject = query.getCoordinateSystemReproject();
266 this.version = query.getVersion();
267 this.hints = query.getHints();
268 this.startIndex = query.getStartIndex();
269 }
270
271 /**
272 * Get the names of the properties that this Query will retrieve as part of
273 * the returned {@linkplain org.geotools.feature.FeatureCollection}.
274 *
275 * @return the attributes to be used in the returned FeatureCollection.
276 *
277 * @see #retrieveAllProperties()
278 *
279 * @task REVISIT: make a FidProperties object, instead of an array size 0.
280 * I think Query.FIDS fills this role to some degree.
281 * Query.FIDS.equals( filter ) would meet this need?
282 */
283 public String[] getPropertyNames() {
284 if (properties == null) {
285 return null;
286 }
287
288 String[] propertyNames = new String[properties.size()];
289 for (int i=0; i< properties.size(); i++) {
290 PropertyName propertyName = properties.get(i);
291 if( propertyName != null){
292 String xpath = propertyName.getPropertyName();
293 propertyNames[i] = xpath;
294 }
295 }
296 return propertyNames;
297 }
298
299 /**
300 * Set the names of the properties that this Query should retrieve as part of
301 * the returned {@linkplain org.geotools.feature.FeatureCollection}.
302 * As well as an array of names, the following constants can be used:
303 * <ul>
304 * <li>
305 * {@linkplain #ALL_NAMES} to retrieve all properties.
306 * </li>
307 * <li>
308 * {@linkplain #NO_NAMES} to indicate no properties are required, just feature IDs.
309 * </li>
310 * </ul>
311 * The available properties can be determined with {@linkplain FeatureSource#getSchema()}.
312 * If properties that are not part of the source's schema are requested
313 * an exception will be thrown.
314 *
315 * @param propNames the names of the properties to retrieve or one of
316 * {@linkplain #ALL_NAMES} or {@linkplain #NO_NAMES}.
317 */
318 public void setPropertyNames(String[] propNames) {
319 if (propNames == null) {
320 properties = ALL_PROPERTIES;
321 return;
322 }
323
324 final FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
325 properties = new ArrayList<PropertyName>(propNames.length);
326 for (int i=0; i< propNames.length; i++) {
327 String xpath = propNames[i];
328 if(xpath != null ){
329 properties.add(ff.property(xpath));
330 }
331 }
332 }
333
334 /**
335 * Get the names of the properties that this Query will retrieve values for
336 * as part of the returned {@linkplain org.geotools.feature.FeatureCollection}.
337 *
338 * @return the xpath expressions to be used in the returned FeatureCollection.
339 *
340 * @see #retrieveAllProperties()
341 */
342 public List<PropertyName> getProperties() {
343 if (properties == ALL_PROPERTIES) {
344 return ALL_PROPERTIES;
345 }
346 return Collections.<PropertyName>unmodifiableList(properties) ;
347 }
348
349 /**
350 * Set the names of the properties that this Query should retrieve as part of
351 * the returned {@linkplain org.geotools.feature.FeatureCollection}.
352 * <p>
353 * The available properties can be determined with {@linkplain FeatureSource#getSchema()}.
354 * If properties that are not part of the source's schema are requested
355 * an exception will be thrown.
356 *
357 * @param propNames the names of the properties to retrieve or
358 * {@linkplain #ALL_NAMES}; an empty List can be passed in to
359 * indicate that only feature IDs should be retrieved
360 *
361 * @task REVISIT: This syntax is really obscure. Consider having an fid or
362 * featureID propertyName that datasource implementors look for
363 * instead of looking to see if the list size is 0.
364 */
365 public void setPropertyNames(List<String> propNames) {
366 if (propNames == null) {
367 this.properties = ALL_PROPERTIES;
368 return;
369 }
370
371 final FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
372
373 properties = new ArrayList<PropertyName>(propNames.size());
374 for (int i=0; i< propNames.size(); i++) {
375 String xpath = propNames.get(i);
376 if(xpath != null ){
377 properties.add(ff.property(xpath));
378 }
379 }
380 }
381
382 /**
383 * Convenience method to determine if the query should retrieve all
384 * properties defined in the schema of the feature data source. This
385 * is equivalent to testing if {@linkplain #getPropertyNames()} returns
386 * {@linkplain #ALL_NAMES}.
387 *
388 * @return true if all properties will be retrieved by this Query; false
389 * otherwise
390 */
391 public boolean retrieveAllProperties() {
392 return properties == null;
393 }
394
395 /**
396 * Get the maximum number of features that will be retrieved by this
397 * Query.
398 * <p>
399 * Note: This is the only method that is not directly out of the Query element in
400 * the WFS specification. It is instead a part of a GetFeature request, which can
401 * hold one or more queries. But each of those in turn will need a
402 * maxFeatures, so it is needed here.
403 * </p>
404 * <p>
405 * If the value returned here is max integer then the number of features
406 * should not be limited.
407 *
408 * @return the maximum number of features that will be retrieved by
409 * this query
410 */
411 public int getMaxFeatures() {
412 return this.maxFeatures;
413 }
414
415 /**
416 * Check if this query allows an unlimited number of features to be returned.
417 * <p>
418 * @return true maxFeatures is less then zero, or equal to Integer.MAX_VALUE.
419 */
420 public boolean isMaxFeaturesUnlimited(){
421 return maxFeatures < 0 || maxFeatures == Integer.MAX_VALUE;
422 }
423
424 /**
425 * Sets the maximum number of features that should be retrieved by this query.
426 * The default is to retrieve all features.
427 *
428 * @param maxFeatures the maximum number of features to retrieve
429 */
430 public void setMaxFeatures(int maxFeatures) {
431 this.maxFeatures = maxFeatures;
432 }
433
434 /**
435 * Get the index of the first feature to retrieve.
436 *
437 * @return the index of the first feature to retrieve or {@code null}
438 * if no start index is defined.
439 */
440 public Integer getStartIndex(){
441 return this.startIndex;
442 }
443
444 /**
445 * Set the index of the first feature to retrieve. This can be used in
446 * conjuction with {@linkplain #setMaxFeatures(int) } to 'page' through
447 * a feature data source.
448 *
449 * @param startIndex index of the first feature to retrieve or {@code null}
450 * to indicate no start index
451 *
452 * @throws IllegalArgumentException if startIndex is less than 0
453 */
454 public void setStartIndex(Integer startIndex){
455 if(startIndex != null && startIndex.intValue() < 0){
456 throw new IllegalArgumentException("startIndex shall be a positive integer: " + startIndex);
457 }
458 this.startIndex = startIndex;
459 }
460
461 /**
462 * Gets the filter used to define constraints on the features that will be
463 * retrieved by this Query.
464 *
465 * @return The filter that defines constraints on the query.
466 */
467 public Filter getFilter() {
468 return this.filter;
469 }
470
471 /**
472 * Sets the filter to constrain the features that will be retrieved by
473 * this Query. If no filter is set all features will be retrieved (taking
474 * into account any bounds set via {@linkplain #setMaxFeatures(int) } and
475 * {@linkplain #setStartIndex(java.lang.Integer) }).
476 * <p>
477 * The default is {@linkplain Filter#INCLUDE}.
478 *
479 * @param filter the OGC filter which features must pass through to
480 * be retrieved by this Query.
481 */
482 public void setFilter(Filter filter) {
483 this.filter = filter;
484 }
485
486 /**
487 * Get the name of the feature type to be queried.
488 *
489 * @return the name of the feature type to be returned with this query.
490 */
491 public String getTypeName() {
492 return this.typeName;
493 }
494
495 /**
496 * Sets the name of the feature type to be queried. If no typename is specified,
497 * then the data source's default type will be used. When working with sources
498 * such as shapefiles that only support one feature type this method can be ignored.
499 *
500 * @param typeName the name of the featureType to retrieve.
501 */
502 public void setTypeName(String typeName) {
503 this.typeName = typeName;
504 }
505
506 /**
507 * Get the namespace of the feature type to be queried.
508 *
509 * @return the gml namespace of the feature type to be returned with this
510 * query
511 */
512 public URI getNamespace() {
513 return namespace;
514 }
515
516 /**
517 * Set the namespace of the feature type to be queried.
518 *
519 * @return the gml namespace of the feature type to be returned with this
520 * query
521 */
522 public void setNamespace(URI namespace) {
523 this.namespace = namespace;
524 }
525
526 /**
527 * Get the handle (mnemonic name) that will be associated with this Query.
528 * The handle is used in logging and error reporting.
529 *
530 * @return the name to refer to this query.
531 */
532 public String getHandle() {
533 return this.handle;
534 }
535
536 /**
537 * Set the handle (mnemonic name) that will be associated with this Query.
538 * The handle is used in logging and error reporting.
539 *
540 * @param handle the name to refer to this query.
541 */
542 public void setHandle(String handle) {
543 this.handle = handle;
544 }
545
546 /**
547 * From WFS Spec: The version attribute is included in order to
548 * accommodate systems that support feature versioning. A value of {@linkplain #ALL}
549 * indicates that all versions of a feature should be fetched. Otherwise
550 * an integer, n, can be specified to return the n th version of a
551 * feature. The version numbers start at '1' which is the oldest version.
552 * If a version value larger than the largest version is specified then
553 * the latest version is return. The default action shall be for the query
554 * to return the latest version. Systems that do not support versioning
555 * can ignore the parameter and return the only version that they have.
556 *
557 * @return the version of the feature to return, or null for latest.
558 */
559 public String getVersion() {
560 return version;
561 }
562
563 /**
564 * Set the version of features to retrieve where this is supported by the
565 * data source being queried.
566 * @param version
567 * @see #getVersion() getVersion() for explanation
568 * @since 2.4
569 */
570 public void setVersion(String version) {
571 this.version = version;
572 }
573
574 /**
575 * Get the coordinate system that applies to features retrieved by this Query.
576 * By default this is the coordinate system of the features in the data source
577 * but this can be overriden via {@linkplain #setCoordinateSystem( CoordinateReferenceSystem )}.
578 *
579 * @return The coordinate system to be returned for Features from this
580 * Query (override the set coordinate system).
581 */
582 public CoordinateReferenceSystem getCoordinateSystem() {
583 return coordinateSystem;
584 }
585
586 /**
587 * Set the coordinate system to apply to features retrieved by this Query.
588 * <p>
589 * This denotes a request to <b>temporarily</b> override the coordinate system
590 * contained in the feature data source being queried. The same coordinate
591 * values will be used, but the features retrieved will appear in this
592 * Coordinate System.
593 *
594 * <p>
595 * This change is not persistant and only applies to the features
596 * returned by this Query. If used in conjunction with {@link #getCoordinateSystemReproject()}
597 * the reprojection will occur from {@link #getCoordinateSystem()} to
598 * {@link #getCoordinateSystemReproject()}.
599 * </p>
600 *
601 * @param system the coordinate system to apply to features retrieved by this Query
602 */
603 public void setCoordinateSystem(CoordinateReferenceSystem system) {
604 coordinateSystem = system;
605 }
606
607 /**
608 * If reprojection has been requested, this returns the coordinate system
609 * that features retrieved by this Query will be reprojected into.
610 *
611 * @return the coordinate system that features will be reprojected into (if set)
612 *
613 * @see #setCoordinateSystemReproject( CoordinateReferenceSystem )
614 */
615 public CoordinateReferenceSystem getCoordinateSystemReproject() {
616 return coordinateSystemReproject;
617 }
618
619 /**
620 * Request that features retrieved by this Query be reprojected into the
621 * given coordinate system.
622 * <p>
623 * If used in conjunction with {@link #setCoordinateSystem(CoordinateReferenceSystem)}
624 * the reprojection will occur from the overridden coordinate system to the system
625 * specified here.
626 *
627 * @return the coordinate system that features should be reprojected into
628 */
629 public void setCoordinateSystemReproject(CoordinateReferenceSystem system) {
630 coordinateSystemReproject = system;
631 }
632
633 /**
634 * SortBy results according to indicated property and order.
635 * <p>
636 * SortBy is part of the Filter 1.1 specification, it is referenced
637 * by WFS1.1 and Catalog 2.0.x specifications and is used to organize
638 * results.
639 * </p>
640 * The SortBy's are ment to be applied in order:
641 * <ul>
642 * <li>SortBy( year, ascending )
643 * <li>SortBy( month, decsending )
644 * </ul>
645 * Would produce something like: <pre><code>
646 * [year=2002 month=4],[year=2002 month=3],[year=2002 month=2],
647 * [year=2002 month=1],[year=2003 month=12],[year=2002 month=4],
648 * </code></pre>
649 * </p>
650 * <p>
651 *
652 * SortBy should be considered at the same level of abstraction as Filter,
653 * and like Filter you may sort using properties not listed in
654 * getPropertyNames.
655 * </p>
656 *
657 * <p>
658 * At a technical level the interface SortBy2 is used to indicate the
659 * additional requirements of a GeoTools implementation. The pure
660 * WFS 1.1 specification itself is limited to SortBy.
661 * </p>
662 *
663 * @return SortBy array or order of application
664 */
665 public SortBy[] getSortBy() {
666 return sortBy;
667 }
668
669 /**
670 * Sets the sort by information.
671 *
672 */
673 public void setSortBy(SortBy[] sortBy) {
674 this.sortBy = sortBy;
675 }
676
677 /**
678 * Get hints that have been set to control the query execution.
679 *
680 * @return hints that are set (may be empty)
681 *
682 * @see #setHints(Hints) setHints(Hints) for more explanation
683 */
684 public Hints getHints() {
685 if(hints == null){
686 hints = new Hints(Collections.EMPTY_MAP);
687 }
688 return hints;
689 }
690
691 /**
692 * Set hints to control the query execution.
693 * <p>
694 * Hints can control such things as:
695 * <ul>
696 * <li> the GeometryFactory to be used
697 * <li> a generalization distance to be applied
698 * <li> the fetch size to be used in JDBC queries
699 * </ul>
700 * The set of hints supported can be found by calling
701 * {@linkplain org.geotools.data.FeatureSource#getSupportedHints() }.
702 * <p>
703 * Note: Data sources may ignore hints (depending on their values) and no
704 * mechanism currently exists to discover which hints where actually used
705 * during the query's execution.
706 * @see Hints#FEATURE_DETACHED
707 * @see Hints#JTS_GEOMETRY_FACTORY
708 * @see Hints#JTS_COORDINATE_SEQUENCE_FACTORY
709 * @see Hints#JTS_PRECISION_MODEL
710 * @see Hints#JTS_SRID
711 * @see Hints#GEOMETRY_DISTANCE
712 * @see Hints#FEATURE_2D
713 *
714 * @param hints the hints to apply
715 */
716 public void setHints(Hints hints) {
717 this.hints = hints;
718 }
719
720 /**
721 * Hashcode based on all parameters other than the handle.
722 *
723 * @return hascode for this Query
724 */
725 @Override
726 public int hashCode() {
727 String[] n = getPropertyNames();
728
729 return ((n == null) ? (-1)
730 : ((n.length == 0) ? 0 : (n.length
731 | n[0].hashCode()))) | getMaxFeatures()
732 | ((getFilter() == null) ? 0 : getFilter().hashCode())
733 | ((getTypeName() == null) ? 0 : getTypeName().hashCode())
734 | ((getVersion() == null) ? 0 : getVersion().hashCode())
735 | ((getCoordinateSystem() == null) ? 0 : getCoordinateSystem().hashCode())
736 | ((getCoordinateSystemReproject() == null) ? 0 : getCoordinateSystemReproject().hashCode())
737 | getStartIndex();
738 }
739
740 /**
741 * Equality based on all query parameters other than the handle.
742 *
743 * @param obj Other object to compare against
744 *
745 * @return true if this Query matches the other object; false otherwise
746 */
747 @Override
748 public boolean equals(Object obj) {
749 if ((obj == null) || !(obj instanceof Query)) {
750 return false;
751 }
752 if (this == obj) return true;
753 Query other = (Query) obj;
754
755 return Arrays.equals(getPropertyNames(), other.getPropertyNames())
756 && (retrieveAllProperties() == other.retrieveAllProperties())
757 && (getMaxFeatures() == other.getMaxFeatures())
758 && ((getFilter() == null) ? (other.getFilter() == null)
759 : getFilter().equals(other.getFilter()))
760 && ((getTypeName() == null) ? (other.getTypeName() == null)
761 : getTypeName().equals(other.getTypeName()))
762 && ((getVersion() == null) ? (other.getVersion() == null)
763 : getVersion().equals(other.getVersion()))
764 && ((getCoordinateSystem() == null) ? (other.getCoordinateSystem() == null)
765 : getCoordinateSystem().equals(other.getCoordinateSystem()))
766 && ((getCoordinateSystemReproject() == null) ? (other.getCoordinateSystemReproject() == null)
767 : getCoordinateSystemReproject().equals(other.getCoordinateSystemReproject()))
768 && (getStartIndex() == other.getStartIndex())
769 && (getHints() == null ? (other.getHints() == null) : getHints().equals(other.getHints()));
770 }
771
772 /**
773 * Return a string representation of this Query.
774 *
775 * @return a string representation of this Query
776 */
777 @Override
778 public String toString() {
779 StringBuffer returnString = new StringBuffer("Query:");
780
781 if (handle != null) {
782 returnString.append(" [" + handle + "]");
783 }
784
785 returnString.append("\n feature type: " + typeName);
786
787 if (filter != null) {
788 returnString.append("\n filter: " + filter.toString());
789 }
790
791 returnString.append("\n [properties: ");
792
793 if ((properties == null) || (properties.size() == 0)) {
794 returnString.append(" ALL ]");
795 } else {
796 for (int i = 0; i < properties.size(); i++) {
797 returnString.append(properties.get(i));
798
799 if (i < (properties.size() - 1)) {
800 returnString.append(", ");
801 }
802 }
803
804 returnString.append("]");
805 }
806
807 if(sortBy != null && sortBy.length > 0) {
808 returnString.append("\n [sort by: ");
809 for (int i = 0; i < sortBy.length; i++) {
810 returnString.append(sortBy[i].getPropertyName().getPropertyName());
811 returnString.append(" ");
812 returnString.append(sortBy[i].getSortOrder().name());
813
814 if (i < (sortBy.length - 1)) {
815 returnString.append(", ");
816 }
817 }
818
819 returnString.append("]");
820 }
821
822 return returnString.toString();
823 }
824}
Note: See TracBrowser for help on using the repository browser.