| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DefaultFormula |
|
| 2.4285714285714284;2,429 |
| 1 | /* | |
| 2 | * Geotoolkit.org - An Open Source Java GIS Toolkit | |
| 3 | * http://www.geotoolkit.org | |
| 4 | * | |
| 5 | * (C) 2009-2012, Open Source Geospatial Foundation (OSGeo) | |
| 6 | * (C) 2009-2012, Geomatys | |
| 7 | * | |
| 8 | * This library is free software; you can redistribute it and/or | |
| 9 | * modify it under the terms of the GNU Lesser General Public | |
| 10 | * License as published by the Free Software Foundation; | |
| 11 | * version 2.1 of the License. | |
| 12 | * | |
| 13 | * This library is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 | * Lesser General Public License for more details. | |
| 17 | * | |
| 18 | * This package contains documentation from OpenGIS specifications. | |
| 19 | * OpenGIS consortium's work is fully acknowledged here. | |
| 20 | */ | |
| 21 | package org.geotoolkit.referencing.operation; | |
| 22 | ||
| 23 | import java.io.Serializable; | |
| 24 | import net.jcip.annotations.Immutable; | |
| 25 | ||
| 26 | import org.opengis.util.InternationalString; | |
| 27 | import org.opengis.metadata.citation.Citation; | |
| 28 | import org.opengis.referencing.operation.Formula; | |
| 29 | ||
| 30 | import org.geotoolkit.util.SimpleInternationalString; | |
| 31 | import org.geotoolkit.util.Utilities; | |
| 32 | ||
| 33 | import static org.apache.sis.util.ArgumentChecks.ensureNonNull; | |
| 34 | ||
| 35 | ||
| 36 | /** | |
| 37 | * Specification of the coordinate operation method formula. | |
| 38 | * | |
| 39 | * @author Martin Desruisseaux (Geomatys) | |
| 40 | * @version 3.03 | |
| 41 | * | |
| 42 | * @since 3.03 | |
| 43 | * @module | |
| 44 | */ | |
| 45 | @Immutable | |
| 46 | public class DefaultFormula implements Formula, Serializable { | |
| 47 | /** | |
| 48 | * For cross-version compatibility. | |
| 49 | */ | |
| 50 | private static final long serialVersionUID = 1929966748615362698L; | |
| 51 | ||
| 52 | /** | |
| 53 | * Formula(s) or procedure used by the operation method. | |
| 54 | */ | |
| 55 | private final InternationalString formula; | |
| 56 | ||
| 57 | /** | |
| 58 | * Reference to a publication giving the formula(s) or procedure used by the | |
| 59 | * coordinate operation method. | |
| 60 | */ | |
| 61 | private final Citation citation; | |
| 62 | ||
| 63 | /** | |
| 64 | * Creates a new formula from the given string. | |
| 65 | * | |
| 66 | * @param formula The formula. | |
| 67 | */ | |
| 68 | 145 | public DefaultFormula(final CharSequence formula) { |
| 69 | 145 | ensureNonNull("formula", formula); |
| 70 | 145 | if (formula instanceof InternationalString) { |
| 71 | 145 | this.formula = (InternationalString) formula; |
| 72 | } else { | |
| 73 | 0 | this.formula = new SimpleInternationalString(formula.toString()); |
| 74 | } | |
| 75 | 145 | this.citation = null; |
| 76 | 145 | } |
| 77 | ||
| 78 | /** | |
| 79 | * Creates a new formula from the given citation. | |
| 80 | * | |
| 81 | * @param citation The citation. | |
| 82 | */ | |
| 83 | 0 | public DefaultFormula(final Citation citation) { |
| 84 | 0 | ensureNonNull("citation", citation); |
| 85 | 0 | this.citation = citation; |
| 86 | 0 | this.formula = null; |
| 87 | 0 | } |
| 88 | ||
| 89 | /** | |
| 90 | * Returns the formula(s) or procedure used by the operation method, or {@code null} if none. | |
| 91 | */ | |
| 92 | @Override | |
| 93 | public InternationalString getFormula() { | |
| 94 | 563 | return formula; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Returns the reference to a publication giving the formula(s) or procedure used by the | |
| 99 | * coordinate operation method, or {@code null} if none. | |
| 100 | */ | |
| 101 | @Override | |
| 102 | public Citation getCitation() { | |
| 103 | 563 | return citation; |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Returns a hash code value for this formula. | |
| 108 | */ | |
| 109 | @Override | |
| 110 | public int hashCode() { | |
| 111 | 0 | int code = (int) serialVersionUID; |
| 112 | 0 | if (formula != null) code += formula .hashCode(); |
| 113 | 0 | if (citation != null) code += citation.hashCode() * 31; |
| 114 | 0 | return code; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Compares this formula with the given object for equality. | |
| 119 | * | |
| 120 | * @param object The object to compare with this formula. | |
| 121 | * @return {@code true} if both objects are equal. | |
| 122 | */ | |
| 123 | @Override | |
| 124 | public boolean equals(final Object object) { | |
| 125 | 469 | if (object == this) { |
| 126 | 0 | return true; |
| 127 | } | |
| 128 | 469 | if (object != null && object.getClass() == getClass()) { |
| 129 | 469 | final DefaultFormula that = (DefaultFormula) object; |
| 130 | 469 | return Utilities.equals(this.formula, that.formula) && |
| 131 | Utilities.equals(this.citation, that.citation); | |
| 132 | } | |
| 133 | 0 | return false; |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * Returns a string representation of this formula. | |
| 138 | */ | |
| 139 | @Override | |
| 140 | public String toString() { | |
| 141 | final CharSequence text; | |
| 142 | 0 | if (citation != null) { |
| 143 | 0 | text = citation.getTitle(); |
| 144 | } else { | |
| 145 | 0 | text = formula; |
| 146 | } | |
| 147 | 0 | return "FORMULA[\"" + text + "\"]"; |
| 148 | } | |
| 149 | } |