commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-geometry] 03/03: Use more specific interface from the JDK.
Date Tue, 26 Nov 2019 16:07:24 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git

commit ee0b7c2c6c280dd41f3e10a5108c18d549f1723e
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Tue Nov 26 17:06:13 2019 +0100

    Use more specific interface from the JDK.
    
    Reported by "soundcloud.io".
---
 .../java/org/apache/commons/geometry/core/Transform.java     |  4 ++--
 .../geometry/core/partition/test/TestTransform2D.java        |  6 +++---
 .../commons/geometry/euclidean/oned/FunctionTransform1D.java | 12 ++++++------
 .../org/apache/commons/geometry/euclidean/oned/Vector1D.java |  4 ++--
 .../geometry/euclidean/threed/FunctionTransform3D.java       | 12 ++++++------
 .../apache/commons/geometry/euclidean/threed/Vector3D.java   |  4 ++--
 .../commons/geometry/euclidean/twod/FunctionTransform2D.java | 12 ++++++------
 .../org/apache/commons/geometry/euclidean/twod/Vector2D.java |  4 ++--
 .../geometry/euclidean/oned/FunctionTransform1DTest.java     |  4 ++--
 .../geometry/euclidean/threed/FunctionTransform3DTest.java   |  4 ++--
 .../geometry/euclidean/twod/FunctionTransform2DTest.java     |  4 ++--
 11 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Transform.java
b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Transform.java
index 7eedd67..7047fab 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Transform.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Transform.java
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.geometry.core;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 /** This interface represents an <em>inversible affine transform</em> in a space.
  * Common examples of this type of transform in Euclidean space include
@@ -44,7 +44,7 @@ import java.util.function.Function;
  * @param <P> Point implementation type
  * @see <a href="https://en.wikipedia.org/wiki/Affine_transformation">Affine Space</a>
  */
-public interface Transform<P extends Point<P>> extends Function<P, P> {
+public interface Transform<P extends Point<P>> extends UnaryOperator<P>
{
 
     /** Return true if the transform preserves the orientation of the space.
      * For example, in Euclidean 2D space, this will be true for translations,
diff --git a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partition/test/TestTransform2D.java
b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partition/test/TestTransform2D.java
index 2caa2be..0321da2 100644
--- a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partition/test/TestTransform2D.java
+++ b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partition/test/TestTransform2D.java
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.geometry.core.partition.test;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.core.Transform;
 
@@ -26,7 +26,7 @@ import org.apache.commons.geometry.core.Transform;
 public class TestTransform2D implements Transform<TestPoint2D> {
 
     /** Underlying transform function. */
-    private final Function<TestPoint2D, TestPoint2D> fn;
+    private final UnaryOperator<TestPoint2D> fn;
 
     /** True if the transform preserves the handedness of the space. */
     private final boolean preservesHandedness;
@@ -34,7 +34,7 @@ public class TestTransform2D implements Transform<TestPoint2D> {
     /** Create a new instance using the given transform function.
      * @param fn transform function
      */
-    public TestTransform2D(final Function<TestPoint2D, TestPoint2D> fn) {
+    public TestTransform2D(final UnaryOperator<TestPoint2D> fn) {
         this.fn = fn;
 
         final TestPoint2D tx = fn.apply(TestPoint2D.PLUS_X);
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1D.java
index 5c0ca23..056f8cc 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1D.java
@@ -16,18 +16,18 @@
  */
 package org.apache.commons.geometry.euclidean.oned;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
-/** Class that wraps a {@link Function} with the {@link Transform1D} interface.
+/** Class that wraps a {@link UnaryOperator} with the {@link Transform1D} interface.
  */
 public final class FunctionTransform1D implements Transform1D {
 
     /** Static instance representing the identity transform. */
     private static final FunctionTransform1D IDENTITY =
-            new FunctionTransform1D(Function.identity(), true, Vector1D.ZERO);
+            new FunctionTransform1D(UnaryOperator.identity(), true, Vector1D.ZERO);
 
     /** The underlying function for the transform. */
-    private final Function<Vector1D, Vector1D> fn;
+    private final UnaryOperator<Vector1D> fn;
 
     /** True if the transform preserves spatial orientation. */
     private final boolean preservesOrientation;
@@ -40,7 +40,7 @@ public final class FunctionTransform1D implements Transform1D {
      * @param preservesOrientation true if the transform preserves spatial orientation
      * @param translation the translation component of the transform
      */
-    private FunctionTransform1D(final Function<Vector1D, Vector1D> fn, final boolean
preservesOrientation,
+    private FunctionTransform1D(final UnaryOperator<Vector1D> fn, final boolean preservesOrientation,
             final Vector1D translation) {
         this.fn = fn;
         this.preservesOrientation = preservesOrientation;
@@ -84,7 +84,7 @@ public final class FunctionTransform1D implements Transform1D {
      * @param fn the function to use for the transform
      * @return a new transform instance using the given function
      */
-    public static FunctionTransform1D from(final Function<Vector1D, Vector1D> fn) {
+    public static FunctionTransform1D from(final UnaryOperator<Vector1D> fn) {
         final Vector1D tOne = fn.apply(Vector1D.Unit.PLUS);
         final Vector1D tZero = fn.apply(Vector1D.ZERO);
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
index d62e0a6..be0f7ab 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
@@ -17,7 +17,7 @@
 package org.apache.commons.geometry.euclidean.oned;
 
 import java.util.Comparator;
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.core.Geometry;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
@@ -235,7 +235,7 @@ public class Vector1D extends EuclideanVector<Vector1D> {
      * @param fn the function to apply
      * @return the transformed vector
      */
-    public Vector1D transform(final Function<Vector1D, Vector1D> fn) {
+    public Vector1D transform(final UnaryOperator<Vector1D> fn) {
         return fn.apply(this);
     }
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3D.java
index 15dca12..0bd7630 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3D.java
@@ -16,20 +16,20 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.euclidean.internal.Matrices;
 
-/** Class that wraps a {@link Function} with the {@link Transform3D} interface.
+/** Class that wraps a {@link UnaryOperator} with the {@link Transform3D} interface.
  */
 public final class FunctionTransform3D implements Transform3D {
 
     /** Static instance representing the identity transform. */
     private static final FunctionTransform3D IDENTITY =
-            new FunctionTransform3D(Function.identity(), true, Vector3D.ZERO);
+            new FunctionTransform3D(UnaryOperator.identity(), true, Vector3D.ZERO);
 
     /** The underlying function for the transform. */
-    private final Function<Vector3D, Vector3D> fn;
+    private final UnaryOperator<Vector3D> fn;
 
     /** True if the transform preserves spatial orientation. */
     private final boolean preservesOrientation;
@@ -42,7 +42,7 @@ public final class FunctionTransform3D implements Transform3D {
      * @param preservesOrientation true if the transform preserves spatial orientation
      * @param translation the translation component of the transform
      */
-    private FunctionTransform3D(final Function<Vector3D, Vector3D> fn, final boolean
preservesOrientation,
+    private FunctionTransform3D(final UnaryOperator<Vector3D> fn, final boolean preservesOrientation,
             final Vector3D translation) {
         this.fn = fn;
         this.preservesOrientation = preservesOrientation;
@@ -88,7 +88,7 @@ public final class FunctionTransform3D implements Transform3D {
      * @param fn the function to use for the transform
      * @return a new transform instance using the given function
      */
-    public static FunctionTransform3D from(final Function<Vector3D, Vector3D> fn) {
+    public static FunctionTransform3D from(final UnaryOperator<Vector3D> fn) {
         final Vector3D tPlusX = fn.apply(Vector3D.Unit.PLUS_X);
         final Vector3D tPlusY = fn.apply(Vector3D.Unit.PLUS_Y);
         final Vector3D tPlusZ = fn.apply(Vector3D.Unit.PLUS_Z);
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index da6f7a6..6678b04 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -17,7 +17,7 @@
 package org.apache.commons.geometry.euclidean.threed;
 
 import java.util.Comparator;
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.core.internal.DoubleFunction3N;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
@@ -377,7 +377,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D>
{
      * @param fn the function to apply
      * @return the transformed vector
      */
-    public Vector3D transform(final Function<Vector3D, Vector3D> fn) {
+    public Vector3D transform(final UnaryOperator<Vector3D> fn) {
         return fn.apply(this);
     }
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2D.java
index 7062f1c..15fc7bb 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2D.java
@@ -16,20 +16,20 @@
  */
 package org.apache.commons.geometry.euclidean.twod;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.euclidean.internal.Matrices;
 
-/** Class that wraps a {@link Function} with the {@link Transform2D} interface.
+/** Class that wraps a {@link UnaryOperator} with the {@link Transform2D} interface.
  */
 public final class FunctionTransform2D implements Transform2D {
 
     /** Static instance representing the identity transform. */
     private static final FunctionTransform2D IDENTITY =
-            new FunctionTransform2D(Function.identity(), true, Vector2D.ZERO);
+            new FunctionTransform2D(UnaryOperator.identity(), true, Vector2D.ZERO);
 
     /** The underlying function for the transform. */
-    private final Function<Vector2D, Vector2D> fn;
+    private final UnaryOperator<Vector2D> fn;
 
     /** True if the transform preserves spatial orientation. */
     private final boolean preservesOrientation;
@@ -42,7 +42,7 @@ public final class FunctionTransform2D implements Transform2D {
      * @param preservesOrientation true if the transform preserves spatial orientation
      * @param translation the translation component of the transform
      */
-    private FunctionTransform2D(final Function<Vector2D, Vector2D> fn, final boolean
preservesOrientation,
+    private FunctionTransform2D(final UnaryOperator<Vector2D> fn, final boolean preservesOrientation,
             final Vector2D translation) {
         this.fn = fn;
         this.preservesOrientation = preservesOrientation;
@@ -87,7 +87,7 @@ public final class FunctionTransform2D implements Transform2D {
      * @param fn the function to use for the transform
      * @return a new transform instance using the given function
      */
-    public static FunctionTransform2D from(final Function<Vector2D, Vector2D> fn) {
+    public static FunctionTransform2D from(final UnaryOperator<Vector2D> fn) {
         final Vector2D tPlusX = fn.apply(Vector2D.Unit.PLUS_X);
         final Vector2D tPlusY = fn.apply(Vector2D.Unit.PLUS_Y);
         final Vector2D tZero = fn.apply(Vector2D.ZERO);
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
index 6e60fcf..868148d 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
@@ -17,7 +17,7 @@
 package org.apache.commons.geometry.euclidean.twod;
 
 import java.util.Comparator;
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.core.internal.DoubleFunction2N;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
@@ -321,7 +321,7 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D>
{
      * @param fn the function to apply
      * @return the transformed vector
      */
-    public Vector2D transform(final Function<Vector2D, Vector2D> fn) {
+    public Vector2D transform(final UnaryOperator<Vector2D> fn) {
         return fn.apply(this);
     }
 
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1DTest.java
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1DTest.java
index af6b378..779b23a 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/FunctionTransform1DTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.geometry.euclidean.oned;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
 import org.junit.Assert;
@@ -52,7 +52,7 @@ public class FunctionTransform1DTest {
         Vector1D p2 = Vector1D.of(-1);
 
         // act
-        Transform1D t = FunctionTransform1D.from(Function.identity());
+        Transform1D t = FunctionTransform1D.from(UnaryOperator.identity());
 
         // assert
         Assert.assertTrue(t.preservesOrientation());
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3DTest.java
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3DTest.java
index cc32706..da1e25e 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/FunctionTransform3DTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
 import org.junit.Assert;
@@ -52,7 +52,7 @@ public class FunctionTransform3DTest {
         Vector3D p2 = Vector3D.of(-1, -1, -1);
 
         // act
-        FunctionTransform3D t = FunctionTransform3D.from(Function.identity());
+        FunctionTransform3D t = FunctionTransform3D.from(UnaryOperator.identity());
 
         // assert
         Assert.assertTrue(t.preservesOrientation());
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2DTest.java
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2DTest.java
index 845b187..17cfd90 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/FunctionTransform2DTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.geometry.euclidean.twod;
 
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
 import org.junit.Assert;
@@ -52,7 +52,7 @@ public class FunctionTransform2DTest {
         Vector2D p2 = Vector2D.of(-1, -1);
 
         // act
-        FunctionTransform2D t = FunctionTransform2D.from(Function.identity());
+        FunctionTransform2D t = FunctionTransform2D.from(UnaryOperator.identity());
 
         // assert
         Assert.assertTrue(t.preservesOrientation());


Mime
View raw message