commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raydeca...@apache.org
Subject [16/19] [math] MATH-1284: Restore Vector1D class as an abstract implementation of Vector<Euclidean1D> and now Cartesian1D extends Vector1D. Restore the public interface of Vector1DFormat to act on Vector1D.
Date Sat, 06 May 2017 15:04:29 GMT
MATH-1284: Restore Vector1D class as an abstract implementation of Vector<Euclidean1D>
and now Cartesian1D extends Vector1D.
Restore the public interface of Vector1DFormat to act on Vector1D.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/9be91f38
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/9be91f38
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/9be91f38

Branch: refs/heads/feature-MATH-1284
Commit: 9be91f380c209f895da36d13c40b99687bb4c8c1
Parents: a27ca51
Author: Ray DeCampo <ray@decampo.org>
Authored: Sat May 6 10:45:00 2017 -0400
Committer: Ray DeCampo <ray@decampo.org>
Committed: Sat May 6 10:45:00 2017 -0400

----------------------------------------------------------------------
 .../geometry/euclidean/oned/Cartesian1D.java    |  3 +-
 .../math4/geometry/euclidean/oned/Vector1D.java | 33 +++++++++++++++
 .../geometry/euclidean/oned/Vector1DFormat.java | 10 ++---
 .../oned/Vector1DFormatAbstractTest.java        | 44 ++++++++++----------
 4 files changed, 62 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java
b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java
index f406125..de3f7d2 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java
@@ -34,7 +34,7 @@ import org.apache.commons.math4.util.MathUtils;
  * <p>Instances of this class are guaranteed to be immutable.</p>
  * @since 4.0
  */
-public class Cartesian1D implements Point<Euclidean1D>, Vector<Euclidean1D> {
+public class Cartesian1D extends Vector1D implements Point<Euclidean1D> {
 
     /** Origin (coordinates: 0). */
     public static final Cartesian1D ZERO = new Cartesian1D(0.0);
@@ -128,6 +128,7 @@ public class Cartesian1D implements Point<Euclidean1D>, Vector<Euclidean1D>
{
      * @return abscissa of the vector
      * @see #Cartesian1D(double)
      */
+    @Override
     public double getX() {
         return x;
     }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java
b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java
new file mode 100644
index 0000000..f35c81f
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java
@@ -0,0 +1,33 @@
+/*
+ * 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.commons.math4.geometry.euclidean.oned;
+
+import org.apache.commons.math4.geometry.Vector;
+
+/** This class represents a 1D vector.
+ * 
+ * @since 3.0
+ */
+public abstract class Vector1D implements Vector<Euclidean1D> {
+
+    /** Get the abscissa of the vector.
+     * @return abscissa of the vector
+     * @see #Vector1D(double)
+     */
+    public abstract double getX();
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java
b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java
index c5cead3..911d6f4 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java
@@ -105,26 +105,26 @@ public class Vector1DFormat extends VectorFormat<Euclidean1D>
{
     @Override
     public StringBuffer format(final Vector<Euclidean1D> vector, final StringBuffer
toAppendTo,
                                final FieldPosition pos) {
-        final Cartesian1D p1 = (Cartesian1D) vector;
+        final Vector1D p1 = (Vector1D) vector;
         return format(toAppendTo, pos, p1.getX());
     }
 
     /** {@inheritDoc} */
     @Override
-    public Cartesian1D parse(final String source) throws MathParseException {
+    public Vector1D parse(final String source) throws MathParseException {
         ParsePosition parsePosition = new ParsePosition(0);
-        Cartesian1D result = parse(source, parsePosition);
+        Vector1D result = parse(source, parsePosition);
         if (parsePosition.getIndex() == 0) {
             throw new MathParseException(source,
                                          parsePosition.getErrorIndex(),
-                                         Cartesian1D.class);
+                                         Vector1D.class);
         }
         return result;
     }
 
     /** {@inheritDoc} */
     @Override
-    public Cartesian1D parse(final String source, final ParsePosition pos) {
+    public Vector1D parse(final String source, final ParsePosition pos) {
         final double[] coordinates = parseCoordinates(1, source, pos);
         if (coordinates == null) {
             return null;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormatAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormatAbstractTest.java
b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormatAbstractTest.java
index 2cb5ae2..e73cdc5 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormatAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormatAbstractTest.java
@@ -130,14 +130,14 @@ public abstract class Vector1DFormatAbstractTest {
     @Test
     public void testParseSimpleNoDecimals() throws MathParseException {
         String source = "{1}";
-        Cartesian1D expected = new Cartesian1D(1);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(1);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
     @Test
     public void testParseIgnoredWhitespace() {
-        Cartesian1D expected = new Cartesian1D(1);
+        Vector1D expected = new Cartesian1D(1);
         ParsePosition pos1 = new ParsePosition(0);
         String source1 = "{1}";
         Assert.assertEquals(expected, vector1DFormat.parse(source1, pos1));
@@ -153,8 +153,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{1" + getDecimalCharacter() +
             "23}";
-        Cartesian1D expected = new Cartesian1D(1.23);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(1.23);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -163,8 +163,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{1" + getDecimalCharacter() +
             "2323}";
-        Cartesian1D expected = new Cartesian1D(1.2323);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(1.2323);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -173,8 +173,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{-1" + getDecimalCharacter() +
             "2323}";
-        Cartesian1D expected = new Cartesian1D(-1.2323);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(-1.2323);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -183,8 +183,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{1" + getDecimalCharacter() +
             "2323}";
-        Cartesian1D expected = new Cartesian1D(1.2323);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(1.2323);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -193,8 +193,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{1" + getDecimalCharacter() +
             "2323}";
-        Cartesian1D expected = new Cartesian1D(1.2323);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(1.2323);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -203,8 +203,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{-1" + getDecimalCharacter() +
             "2323}";
-        Cartesian1D expected = new Cartesian1D(-1.2323);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(-1.2323);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -213,8 +213,8 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "{0" + getDecimalCharacter() +
             "0}";
-        Cartesian1D expected = new Cartesian1D(0.0);
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D expected = new Cartesian1D(0.0);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
@@ -223,29 +223,29 @@ public abstract class Vector1DFormatAbstractTest {
         String source =
             "[1" + getDecimalCharacter() +
             "2323]";
-        Cartesian1D expected = new Cartesian1D(1.2323);
-        Cartesian1D actual = vector1DFormatSquare.parse(source);
+        Vector1D expected = new Cartesian1D(1.2323);
+        Vector1D actual = vector1DFormatSquare.parse(source);
         Assert.assertEquals(expected, actual);
     }
 
     @Test
     public void testParseNan() throws MathParseException {
         String source = "{(NaN)}";
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(Cartesian1D.NaN, actual);
     }
 
     @Test
     public void testParsePositiveInfinity() throws MathParseException {
         String source = "{(Infinity)}";
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(Cartesian1D.POSITIVE_INFINITY, actual);
     }
 
     @Test
     public void testParseNegativeInfinity() throws MathParseException {
         String source = "{(-Infinity)}";
-        Cartesian1D actual = vector1DFormat.parse(source);
+        Vector1D actual = vector1DFormat.parse(source);
         Assert.assertEquals(Cartesian1D.NEGATIVE_INFINITY, actual);
     }
 


Mime
View raw message