001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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 java.util.Collections;
021: import org.opengis.filter.Filter;
022: import org.opengis.filter.sort.SortBy;
023: import org.opengis.referencing.crs.CoordinateReferenceSystem;
024: import org.geotools.factory.GeoTools;
025: import org.geotools.factory.Hints;
026:
027: /**
028: * Implementation of Query.ALL.
029: *
030: * <p>
031: * This query is used to retrive all Features. Query.ALL is the only instance
032: * of this class.
033: * </p>
034: *
035: * <p>
036: * Example:
037: * </p>
038: * <pre><code>
039: * featureSource.getFeatures( Query.FIDS );
040: * </code></pre>
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/api/src/main/java/org/geotools/data/ALLQuery.java $
042: */
043: class ALLQuery implements Query {
044: public final String[] getPropertyNames() {
045: return null;
046: }
047:
048: public final boolean retrieveAllProperties() {
049: return true;
050: }
051:
052: public final int getMaxFeatures() {
053: return DEFAULT_MAX; // consider Integer.MAX_VALUE
054: }
055:
056: public final Filter getFilter() {
057: return Filter.INCLUDE;
058: }
059:
060: public final String getTypeName() {
061: return null;
062: }
063:
064: public URI getNamespace() {
065: return NO_NAMESPACE;
066: }
067:
068: public final String getHandle() {
069: return "Request All Features";
070: }
071:
072: public final String getVersion() {
073: return null;
074: }
075:
076: /**
077: * Hashcode based on propertyName, maxFeatures and filter.
078: *
079: * @return hascode for filter
080: */
081: public int hashCode() {
082: String[] n = getPropertyNames();
083:
084: return ((n == null) ? (-1) : ((n.length == 0) ? 0
085: : (n.length | n[0].hashCode())))
086: | getMaxFeatures()
087: | ((getFilter() == null) ? 0 : getFilter().hashCode())
088: | ((getTypeName() == null) ? 0 : getTypeName()
089: .hashCode())
090: | ((getVersion() == null) ? 0 : getVersion().hashCode())
091: | ((getCoordinateSystem() == null) ? 0
092: : getCoordinateSystem().hashCode())
093: | ((getCoordinateSystemReproject() == null) ? 0
094: : getCoordinateSystemReproject().hashCode());
095: }
096:
097: /**
098: * Equality based on propertyNames, maxFeatures, filter, typeName and
099: * version.
100: *
101: * <p>
102: * Changing the handle does not change the meaning of the Query.
103: * </p>
104: *
105: * @param obj Other object to compare against
106: *
107: * @return <code>true</code> if <code>obj</code> matches this filter
108: */
109: public boolean equals(Object obj) {
110: if ((obj == null) || !(obj instanceof Query)) {
111: return false;
112: }
113:
114: if (this == obj) {
115: return true;
116: }
117:
118: Query other = (Query) obj;
119:
120: return Arrays.equals(getPropertyNames(), other
121: .getPropertyNames())
122: && (retrieveAllProperties() == other
123: .retrieveAllProperties())
124: && (getMaxFeatures() == other.getMaxFeatures())
125: && ((getFilter() == null) ? (other.getFilter() == null)
126: : getFilter().equals(other.getFilter()))
127: && ((getTypeName() == null) ? (other.getTypeName() == null)
128: : getTypeName().equals(other.getTypeName()))
129: && ((getVersion() == null) ? (other.getVersion() == null)
130: : getVersion().equals(other.getVersion()))
131: && ((getCoordinateSystem() == null) ? (other
132: .getCoordinateSystem() == null)
133: : getCoordinateSystem().equals(
134: other.getCoordinateSystem()))
135: && ((getCoordinateSystemReproject() == null) ? (other
136: .getCoordinateSystemReproject() == null)
137: : getCoordinateSystemReproject().equals(
138: other.getCoordinateSystemReproject()));
139: }
140:
141: public String toString() {
142: return "Query.ALL";
143: }
144:
145: /**
146: * Return <code>null</code> as ALLQuery does not require a CS.
147: *
148: * @return <code>null</code> as override is not required.
149: *
150: * @see org.geotools.data.Query#getCoordinateSystem()
151: */
152: public CoordinateReferenceSystem getCoordinateSystem() {
153: return null;
154: }
155:
156: /**
157: * Return <code>null</code> as ALLQuery does not require a CS.
158: *
159: * @return <code>null</code> as reprojection is not required.
160: *
161: * @see org.geotools.data.Query#getCoordinateSystemReproject()
162: */
163: public CoordinateReferenceSystem getCoordinateSystemReproject() {
164: return null;
165: }
166:
167: /**
168: * @return {@link SortBy#UNSORTED}.
169: */
170: public SortBy[] getSortBy() {
171: return SortBy.UNSORTED;
172: }
173:
174: /**
175: * Returns an empty Hints set
176: */
177: public Hints getHints() {
178: return new Hints(Collections.EMPTY_MAP);
179: }
180: }
|