001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * This package contains documentation from OpenGIS specifications.
018: * OpenGIS consortium's work is fully acknowledged here.
019: */
020: package org.geotools.metadata.iso.quality;
021:
022: // J2SE direct dependencies
023: import java.util.Arrays;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.Date;
027:
028: // OpenGIS dependencies
029: import org.opengis.metadata.Identifier;
030: import org.opengis.metadata.citation.Citation;
031: import org.opengis.metadata.quality.Element;
032: import org.opengis.metadata.quality.EvaluationMethodType;
033: import org.opengis.metadata.quality.Result;
034: import org.opengis.util.InternationalString;
035:
036: // Geotools dependencies
037: import org.geotools.metadata.iso.MetadataEntity;
038: import org.geotools.resources.i18n.ErrorKeys;
039: import org.geotools.resources.i18n.Errors;
040:
041: /**
042: * Type of test applied to the data specified by a data quality scope.
043: *
044: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/metadata/iso/quality/ElementImpl.java $
045: * @version $Id: ElementImpl.java 25718 2007-06-01 15:48:23Z chorner $
046: * @author Martin Desruisseaux
047: * @author Touraïvane
048: *
049: * @since 2.1
050: */
051: public class ElementImpl extends MetadataEntity implements Element {
052: /**
053: * Serial number for interoperability with different versions.
054: */
055: private static final long serialVersionUID = -3542504624077298894L;
056:
057: /**
058: * Name of the test applied to the data.
059: */
060: private Collection namesOfMeasure;
061:
062: /**
063: * Code identifying a registered standard procedure, or {@code null} if none.
064: */
065: private Identifier measureIdentification;
066:
067: /**
068: * Description of the measure being determined.
069: */
070: private InternationalString measureDescription;
071:
072: /**
073: * Type of method used to evaluate quality of the dataset, or {@code null} if unspecified.
074: */
075: private EvaluationMethodType evaluationMethodType;
076:
077: /**
078: * Description of the evaluation method.
079: */
080: private InternationalString evaluationMethodDescription;
081:
082: /**
083: * Reference to the procedure information, or {@code null} if none.
084: */
085: private Citation evaluationProcedure;
086:
087: /**
088: * Date or range of dates on which a data quality measure was applied.
089: * The array length is 1 for a single date, or 2 for a range. Returns
090: * {@code null} if this information is not available.
091: */
092: private long date1 = Long.MIN_VALUE, date2 = Long.MIN_VALUE;
093:
094: /**
095: * Value (or set of values) obtained from applying a data quality measure or the out
096: * come of evaluating the obtained value (or set of values) against a specified
097: * acceptable conformance quality level.
098: */
099: private Collection/*<Result>*/results;
100:
101: /**
102: * Constructs an initially empty element.
103: */
104: public ElementImpl() {
105: }
106:
107: /**
108: * Constructs a metadata entity initialized with the values from the specified metadata.
109: *
110: * @since 2.4
111: */
112: public ElementImpl(final Element source) {
113: super (source);
114: }
115:
116: /**
117: * Creates an element initialized to the given result.
118: */
119: public ElementImpl(final Result result) {
120: setResults(Collections.singleton(result));
121: }
122:
123: /**
124: * Returns the name of the test applied to the data.
125: */
126: public synchronized Collection getNamesOfMeasure() {
127: return namesOfMeasure = nonNullCollection(namesOfMeasure,
128: InternationalString.class);
129: }
130:
131: /**
132: * Set the name of the test applied to the data.
133: */
134: public synchronized void setNamesOfMeasure(
135: final Collection newValues) {
136: namesOfMeasure = copyCollection(newValues, namesOfMeasure,
137: InternationalString.class);
138: }
139:
140: /**
141: * Returns the code identifying a registered standard procedure, or {@code null} if none.
142: */
143: public Identifier getMeasureIdentification() {
144: return measureIdentification;
145: }
146:
147: /**
148: * Set the code identifying a registered standard procedure.
149: */
150: public synchronized void setMeasureIdentification(
151: final Identifier newValue) {
152: checkWritePermission();
153: measureIdentification = newValue;
154: }
155:
156: /**
157: * Returns the description of the measure being determined.
158: */
159: public InternationalString getMeasureDescription() {
160: return measureDescription;
161: }
162:
163: /**
164: * Set the description of the measure being determined.
165: */
166: public synchronized void setMeasureDescription(
167: final InternationalString newValue) {
168: checkWritePermission();
169: measureDescription = newValue;
170: }
171:
172: /**
173: * Returns the type of method used to evaluate quality of the dataset,
174: * or {@code null} if unspecified.
175: */
176: public EvaluationMethodType getEvaluationMethodType() {
177: return evaluationMethodType;
178: }
179:
180: /**
181: * Set the ype of method used to evaluate quality of the dataset.
182: */
183: public synchronized void setEvaluationMethodType(
184: final EvaluationMethodType newValue) {
185: checkWritePermission();
186: evaluationMethodType = newValue;
187: }
188:
189: /**
190: * Returns the description of the evaluation method.
191: */
192: public InternationalString getEvaluationMethodDescription() {
193: return evaluationMethodDescription;
194: }
195:
196: /**
197: * Set the description of the evaluation method.
198: */
199: public synchronized void setEvaluationMethodDescription(
200: final InternationalString newValue) {
201: checkWritePermission();
202: evaluationMethodDescription = newValue;
203: }
204:
205: /**
206: * Returns the reference to the procedure information, or {@code null} if none.
207: */
208: public Citation getEvaluationProcedure() {
209: return evaluationProcedure;
210: }
211:
212: /**
213: * Set the reference to the procedure information.
214: */
215: public synchronized void setEvaluationProcedure(
216: final Citation newValue) {
217: checkWritePermission();
218: evaluationProcedure = newValue;
219: }
220:
221: /**
222: * Date that the metadata was created.
223: * The array length is 1 for a single date, or 2 for a range.
224: * Returns {@code null} if this information is not available.
225: *
226: * @deprecated Replaced by {@link #getDates}.
227: */
228: public Date[] getDate() {
229: if (date1 == Long.MIN_VALUE) {
230: return null;
231: }
232: if (date2 == Long.MIN_VALUE) {
233: return new Date[] { new Date(date1) };
234: }
235: return new Date[] { new Date(date1), new Date(date2) };
236: }
237:
238: /**
239: * Returns the date or range of dates on which a data quality measure was applied.
240: * The array length is 1 for a single date, or 2 for a range. Returns
241: * an empty list if this information is not available.
242: *
243: * @since 2.4
244: */
245: public synchronized Collection/*<Date>*/getDates() {
246: if (date1 == Long.MIN_VALUE) {
247: return Collections.EMPTY_LIST;
248: }
249: if (date2 == Long.MIN_VALUE) {
250: return Collections.singleton(new Date(date1));
251: }
252: return Arrays.asList(new Date[] { new Date(date1),
253: new Date(date2) });
254: }
255:
256: /**
257: * Set the date or range of dates on which a data quality measure was applied.
258: * The array length is 1 for a single date, or 2 for a range.
259: *
260: * @deprecated Use {@link #setDates(Collection)} instead.
261: */
262: public synchronized void setDate(final Date[] newValue) {
263: checkWritePermission();
264: date1 = date2 = Long.MIN_VALUE;
265: if (newValue != null) {
266: switch (newValue.length) {
267: default:
268: throw new IllegalArgumentException(Errors
269: .format(ErrorKeys.MISMATCHED_ARRAY_LENGTH));
270: case 2:
271: date2 = newValue[1].getTime(); // Fall through
272: case 1:
273: date1 = newValue[0].getTime(); // Fall through
274: case 0:
275: break;
276: }
277: }
278: }
279:
280: /**
281: * Set the date or range of dates on which a data quality measure was applied.
282: * The collection size is 1 for a single date, or 2 for a range.
283: *
284: * @since 2.4
285: */
286: public void setDates(final Collection/*<Date>*/newValues) {
287: setDate((Date[]) newValues.toArray(new Date[newValues.size()]));
288: }
289:
290: /**
291: * Returns the value (or set of values) obtained from applying a data quality measure or
292: * the out come of evaluating the obtained value (or set of values) against a specified
293: * acceptable conformance quality level.
294: *
295: * @deprecated Use {@link #getResults} instead.
296: */
297: public Result getResult() {
298: final Collection results = getResults();
299: return results.isEmpty() ? null : (Result) results.iterator()
300: .next();
301: }
302:
303: /**
304: * Set the value (or set of values) obtained from applying a data quality measure or
305: * the out come of evaluating the obtained value (or set of values) against a specified
306: * acceptable conformance quality level.
307: *
308: * @deprecated Use {@link #setResults} instead.
309: */
310: public void setResult(final Result newValue) {
311: setResults(Collections.singleton(newValue));
312: }
313:
314: /**
315: * Returns the value (or set of values) obtained from applying a data quality measure or
316: * the out come of evaluating the obtained value (or set of values) against a specified
317: * acceptable conformance quality level.
318: *
319: * @since 2.4
320: */
321: public synchronized Collection getResults() {
322: return results = nonNullCollection(results, Result.class);
323: }
324:
325: /**
326: * Set the value (or set of values) obtained from applying a data quality measure or
327: * the out come of evaluating the obtained value (or set of values) against a specified
328: * acceptable conformance quality level.
329: *
330: * @since 2.4
331: */
332: public synchronized void setResults(
333: final Collection/*<Result>*/newValues) {
334: results = copyCollection(newValues, results, Result.class);
335: }
336: }
|