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.feature.visitor;
017:
018: import java.io.IOException;
019: import java.util.List;
020: import java.util.Map;
021: import java.util.Set;
022:
023: import com.vividsolutions.jts.geom.Envelope;
024: import com.vividsolutions.jts.geom.Geometry;
025: import com.vividsolutions.jts.geom.Point;
026:
027: /**
028: * Encapsulates the results from a FeatureCalc, and includes methods for
029: * obtaining and merging results.
030: *
031: * @author Cory Horner, Refractions
032: *
033: * @see FeatureCalc
034: * @since 2.2.M2
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/visitor/CalcResult.java $
036: */
037: public interface CalcResult {
038: /**
039: * Returns true if the target results is a compatible type with the current
040: * results, with compatible meaning that the two results may be merged.
041: *
042: * @param targetResults the second CalcResult Object
043: *
044: * @return true if the targetResults can be merged with the current results
045: */
046: public boolean isCompatible(CalcResult targetResults);
047:
048: /**
049: * Returns the merged results of two CalcResult. The way in which the
050: * results are merged is dependent on the type of the results added. A new
051: * instance is created containing the merged results.
052: *
053: * <p>
054: * For example: merging two min functions would return the smaller of the
055: * two values; merging a count and a sum would return an average.
056: * </p>
057: *
058: * @param resultsToAdd
059: *
060: * @return the merged results
061: */
062: public CalcResult merge(CalcResult resultsToAdd);
063:
064: /**
065: * Actual answer
066: *
067: * @return the calculation result as a generic object
068: */
069: public Object getValue();
070:
071: /**
072: * Access getValue as an int
073: *
074: * @return the calculation result as a int (or 0 if not applicable)
075: * @throws IOException
076: */
077: public int toInt();
078:
079: /**
080: * Access getValue as a double
081: *
082: * @return the calculation result as a double (or 0 if not applicable)
083: */
084: public double toDouble();
085:
086: /**
087: * Access getValue as a string
088: *
089: * @return the calculation result as a string (or "" if not applicable)
090: */
091: public String toString();
092:
093: /**
094: * Access getValue as a long
095: *
096: * @return the calculation result as a long (or 0 if not applicable)
097: */
098: public long toLong();
099:
100: /**
101: * Access getValue as a float
102: *
103: * @return the calculation result as a float (or 0 if not applicable)
104: */
105: public float toFloat();
106:
107: /**
108: * Access getValue as a geometry
109: *
110: * @return the calculation result as a geometry (or null if not applicable)
111: */
112: public Geometry toGeometry();
113:
114: /**
115: * Access getValue as an envelope
116: *
117: * @return the calculation result as an envelope (or null if not applicable)
118: */
119: public Envelope toEnvelope();
120:
121: /**
122: * Access getValue as a point
123: *
124: * @return the calculation result as a point (or null if not applicable)
125: */
126: public Point toPoint();
127:
128: /**
129: * Access getValue as a set
130: *
131: * @return the calculation result as a set (or null if not applicable)
132: */
133: public Set toSet();
134:
135: /**
136: * Access getValue as a list
137: *
138: * @return the calculation result as a list (or null if not applicable)
139: */
140: public List toList();
141:
142: /**
143: * Access getValue as an array
144: *
145: * @return the calculation result as an array (or null if not applicable)
146: */
147: public Object[] toArray();
148:
149: /**
150: * Access getValue as a map
151: *
152: * @return the calculation result as a map (or null if not applicable)
153: */
154: public Map toMap();
155: }
|