sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1652839 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/test/suite/
Date Sun, 18 Jan 2015 19:32:48 GMT
Author: desruisseaux
Date: Sun Jan 18 19:32:47 2015
New Revision: 1652839

URL: http://svn.apache.org/r1652839
Log:
Ported the DefaultFormula class.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java?rev=1652839&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
[UTF-8] Sun Jan 18 19:32:47 2015
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.operation;
+
+import java.io.Serializable;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.referencing.operation.Formula;
+import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.util.iso.Types;
+
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+
+// Branch-dependent imports
+import java.util.Objects;
+import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.io.wkt.Formatter;
+
+
+/**
+ * Specification of the coordinate operation method formula.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.5
+ * @since   0.5 (derived from geotk-3.03)
+ * @module
+ */
+public class DefaultFormula extends FormattableObject implements Formula, Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = 1929966748615362698L;
+
+    /**
+     * Formula(s) or procedure used by the operation method.
+     */
+    private final InternationalString formula;
+
+    /**
+     * Reference to a publication giving the formula(s) or procedure used by the coordinate
operation method.
+     */
+    private final Citation citation;
+
+    /**
+     * Creates a new formula from the given string.
+     *
+     * @param formula The formula.
+     */
+    public DefaultFormula(final CharSequence formula) {
+        ensureNonNull("formula", formula);
+        this.formula = Types.toInternationalString(formula);
+        this.citation = null;
+    }
+
+    /**
+     * Creates a new formula from the given citation.
+     *
+     * @param citation The citation.
+     */
+    public DefaultFormula(final Citation citation) {
+        ensureNonNull("citation", citation);
+        this.citation = citation;
+        this.formula  = null;
+    }
+
+    /**
+     * Returns the formula(s) or procedure used by the operation method, or {@code null}
if none.
+     */
+    @Override
+    public InternationalString getFormula() {
+        return formula;
+    }
+
+    /**
+     * Returns the reference to a publication giving the formula(s) or procedure used by
the
+     * coordinate operation method, or {@code null} if none.
+     */
+    @Override
+    public Citation getCitation() {
+        return citation;
+    }
+
+    /**
+     * Returns a hash code value for this formula.
+     */
+    @Override
+    public int hashCode() {
+        int code = (int) serialVersionUID;
+        if (formula  != null) code += formula .hashCode();
+        if (citation != null) code += citation.hashCode() * 31;
+        return code;
+    }
+
+    /**
+     * Compares this formula with the given object for equality.
+     *
+     * @param  object The object to compare with this formula.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (object == this) {
+            return true;
+        }
+        if (object != null && object.getClass() == getClass()) {
+            final DefaultFormula that = (DefaultFormula) object;
+            return Objects.equals(this.formula,  that.formula) &&
+                   Objects.equals(this.citation, that.citation);
+        }
+        return false;
+    }
+
+    /**
+     * Formats this formula as a pseudo-<cite>Well Known Text</cite> element.
+     *
+     * <div class="note"><b>Compatibility note:</b>
+     * ISO 19162 does not define a WKT representation for {@code Formula} objects.
+     * The text formatted by this method is SIS-specific and causes the text to be flagged
as
+     * {@linkplain Formatter#setInvalidWKT(Class, Exception) invalid WKT}.</div>
+     *
+     * @return {@code "Formula"}.
+     */
+    @Override
+    protected String formatTo(final Formatter formatter) {
+        InternationalString text = null;
+        if (citation != null) {
+            text = citation.getTitle();
+        }
+        if (text == null) {
+            text = formula;
+        }
+        if (text != null) {
+            formatter.append(text.toString(formatter.getLocale()), ElementKind.REMARKS);
+        }
+        formatter.setInvalidWKT(Formula.class, null);
+        return "Formula";
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultFormula.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java?rev=1652839&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
[UTF-8] Sun Jan 18 19:32:47 2015
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.operation;
+
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.MetadataAssert.*;
+
+
+/**
+ * Tests {@link DefaultFormula}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.5
+ * @since   0.5
+ * @module
+ */
+public final strictfp class DefaultFormulaTest extends TestCase {
+    /**
+     * Tests {@link DefaultFormula#toWKT()}.
+     */
+    @Test
+    public void testWKT() {
+        final DefaultFormula formula = new DefaultFormula("Mercator");
+        assertWktEquals("Formula[“Mercator”]", formula);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultFormulaTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1652839&r1=1652838&r2=1652839&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Sun Jan 18 19:32:47 2015
@@ -106,6 +106,8 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.CommonCRSTest.class,
     org.apache.sis.referencing.CRSTest.class,
 
+    org.apache.sis.referencing.operation.DefaultFormulaTest.class,
+
     org.apache.sis.geometry.AbstractDirectPositionTest.class,
     org.apache.sis.geometry.GeneralDirectPositionTest.class,
     org.apache.sis.geometry.DirectPosition1DTest.class,



Mime
View raw message