001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data;
017:
018: import java.net.URI;
019: import java.util.Arrays;
020: import org.opengis.filter.Filter;
021: import org.opengis.filter.sort.SortBy;
022: import org.opengis.referencing.crs.CoordinateReferenceSystem;
023: import org.geotools.factory.GeoTools;
024: import org.geotools.factory.Hints;
025:
026: /**
027: * Implementation for Query.FIDS.
028: *
029: * <p>
030: * This query is used to retrive FeatureIds. Query.FIDS is the only instance of
031: * this class.
032: * </p>
033: *
034: * <p>
035: * Example:
036: * </p>
037: * <pre><code>
038: * featureSource.getFeatures( Query.FIDS );
039: * </code></pre>
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/api/src/main/java/org/geotools/data/FIDSQuery.java $
041: */
042: class FIDSQuery implements Query {
043: static final String[] NO_PROPERTIES = new String[0];
044:
045: public String[] getPropertyNames() {
046: return NO_PROPERTIES;
047: }
048:
049: public boolean retrieveAllProperties() {
050: return false;
051: }
052:
053: public int getMaxFeatures() {
054: return DEFAULT_MAX; // consider Integer.MAX_VALUE
055: }
056:
057: public Filter getFilter() {
058: return Filter.INCLUDE;
059: }
060:
061: public String getTypeName() {
062: return null;
063: }
064:
065: public URI getNamespace() {
066: return NO_NAMESPACE;
067: }
068:
069: public String getHandle() {
070: return "Request Feature IDs";
071: }
072:
073: public String getVersion() {
074: return null;
075: }
076:
077: /**
078: * Hashcode based on propertyName, maxFeatures and filter.
079: *
080: * @return hascode for filter
081: */
082: public int hashCode() {
083: String[] n = getPropertyNames();
084:
085: return ((n == null) ? (-1) : ((n.length == 0) ? 0
086: : (n.length | n[0].hashCode())))
087: | getMaxFeatures()
088: | ((getFilter() == null) ? 0 : getFilter().hashCode())
089: | ((getTypeName() == null) ? 0 : getTypeName()
090: .hashCode())
091: | ((getVersion() == null) ? 0 : getVersion().hashCode())
092: | ((getCoordinateSystem() == null) ? 0
093: : getCoordinateSystem().hashCode())
094: | ((getCoordinateSystemReproject() == null) ? 0
095: : getCoordinateSystemReproject().hashCode());
096: }
097:
098: /**
099: * Equality based on propertyNames, maxFeatures, filter, typeName and
100: * version.
101: *
102: * <p>
103: * Changing the handle does not change the meaning of the Query.
104: * </p>
105: *
106: * @param obj Other object to compare against
107: *
108: * @return <code>true</code> if <code>obj</code> retrieves only FIDS
109: */
110: public boolean equals(Object obj) {
111: if ((obj == null) || !(obj instanceof Query)) {
112: return false;
113: }
114:
115: if (this == obj) {
116: return true;
117: }
118:
119: Query other = (Query) obj;
120:
121: return Arrays.equals(getPropertyNames(), other
122: .getPropertyNames())
123: && (retrieveAllProperties() == other
124: .retrieveAllProperties())
125: && (getMaxFeatures() == other.getMaxFeatures())
126: && ((getFilter() == null) ? (other.getFilter() == null)
127: : getFilter().equals(other.getFilter()))
128: && ((getTypeName() == null) ? (other.getTypeName() == null)
129: : getTypeName().equals(other.getTypeName()))
130: && ((getVersion() == null) ? (other.getVersion() == null)
131: : getVersion().equals(other.getVersion()))
132: && ((getCoordinateSystem() == null) ? (other
133: .getCoordinateSystem() == null)
134: : getCoordinateSystem().equals(
135: other.getCoordinateSystem()))
136: && ((getCoordinateSystemReproject() == null) ? (other
137: .getCoordinateSystemReproject() == null)
138: : getCoordinateSystemReproject().equals(
139: other.getCoordinateSystemReproject()));
140: }
141:
142: public String toString() {
143: return "Query.FIDS";
144: }
145:
146: /**
147: * Return <code>null</code> as FIDSQuery does not require a CS.
148: *
149: * @return <code>null</code> as override is not required.
150: *
151: * @see org.geotools.data.Query#getCoordinateSystem()
152: */
153: public CoordinateReferenceSystem getCoordinateSystem() {
154: return null;
155: }
156:
157: /**
158: * Return <code>null</code> as FIDSQuery does not require a CS.
159: *
160: * @return <code>null</code> as reprojection is not required.
161: *
162: * @see org.geotools.data.Query#getCoordinateSystemReproject()
163: */
164: public CoordinateReferenceSystem getCoordinateSystemReproject() {
165: return null;
166: }
167:
168: /**
169: * @return {@link SortBy#UNSORTED}.
170: */
171: public SortBy[] getSortBy() {
172: return SortBy.UNSORTED;
173: }
174:
175: /**
176: * Returns the GeoTools default hints {@link GeoTools#getDefaultHints()}
177: */
178: public Hints getHints() {
179: return GeoTools.getDefaultHints();
180: }
181: }
|