groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 05/05: Trivial refactoring: Comparator combinator can be used
Date Sun, 03 Nov 2019 15:00:48 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 5143bb7f8aa9b2ddd35b20624f0e7e441b35ed95
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sun Nov 3 22:57:06 2019 +0800

    Trivial refactoring: Comparator combinator can be used
---
 src/main/java/groovy/util/FactoryBuilderSupport.java               | 7 +------
 .../org/codehaus/groovy/transform/SortableASTTransformation.java   | 2 +-
 .../org/codehaus/groovy/transform/ToStringASTTransformation.java   | 2 +-
 .../groovy/transform/TupleConstructorASTTransformation.java        | 2 +-
 4 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/main/java/groovy/util/FactoryBuilderSupport.java b/src/main/java/groovy/util/FactoryBuilderSupport.java
index be85429..7c9642f 100644
--- a/src/main/java/groovy/util/FactoryBuilderSupport.java
+++ b/src/main/java/groovy/util/FactoryBuilderSupport.java
@@ -71,12 +71,7 @@ public abstract class FactoryBuilderSupport extends Binding {
     public static final String CHILD_BUILDER = "_CHILD_BUILDER_";
     public static final String SCRIPT_CLASS_NAME = "_SCRIPT_CLASS_NAME_";
     private static final Logger LOG = Logger.getLogger(FactoryBuilderSupport.class.getName());
-    private static final Comparator<Method> METHOD_COMPARATOR = (o1, o2) -> {
-        int cmp = o1.getName().compareTo(o2.getName());
-        if (cmp != 0) return cmp;
-        cmp = o1.getParameterTypes().length - o2.getParameterTypes().length;
-        return cmp;
-    };
+    private static final Comparator<Method> METHOD_COMPARATOR = Comparator.comparing(Method::getName).thenComparingInt(o
-> o.getParameterTypes().length);
 
     /**
      * Throws an exception if value is null.
diff --git a/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
index 1f8cd4d..c12ff24 100644
--- a/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
@@ -235,7 +235,7 @@ public class SortableASTTransformation extends AbstractASTTransformation
{
             checkComparable(pNode);
         }
         if (includes != null) {
-            Comparator<PropertyNode> includeComparator = (o1, o2) -> Integer.compare(includes.indexOf(o1.getName()),
includes.indexOf(o2.getName()));
+            Comparator<PropertyNode> includeComparator = Comparator.comparingInt(o
-> includes.indexOf(o.getName()));
             properties.sort(includeComparator);
         }
         return properties;
diff --git a/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
index a8acd42..80871a4 100644
--- a/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
@@ -217,7 +217,7 @@ public class ToStringASTTransformation extends AbstractASTTransformation
{
         }
 
         if (includes != null) {
-            Comparator<ToStringElement> includeComparator = (tse1, tse2) -> Integer.compare(includes.indexOf(tse1.name),
includes.indexOf(tse2.name));
+            Comparator<ToStringElement> includeComparator = Comparator.comparingInt(tse
-> includes.indexOf(tse.name));
             elements.sort(includeComparator);
         }
 
diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index df4be58..4c97c67 100644
--- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -247,7 +247,7 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
         }
 
         if (includes != null) {
-            Comparator<Parameter> includeComparator = (p1, p2) -> Integer.compare(includes.indexOf(p1.getName()),
includes.indexOf(p2.getName()));
+            Comparator<Parameter> includeComparator = Comparator.comparingInt(p ->
includes.indexOf(p.getName()));
             params.sort(includeComparator);
         }
 


Mime
View raw message