[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
GitHub user Leward opened a pull request:

    https://github.com/apache/groovy/pull/558

    GROOVY-8218 @Sortable allows reversed natural ordering

    See [GROOVY-8218](https://issues.apache.org/jira/browse/GROOVY-8218)

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/Leward/groovy master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/558.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #558
   
----
commit 4f4cdbeeb40ed40c6020f1ddfadca3769ee10b67
Author: Paul-Julien Vauthier <[hidden email]>
Date:   2017-06-04T06:31:48Z

    GROOVY-8218 @Sortable allows reversed natural ordering

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/558#discussion_r125552693
 
    --- Diff: src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java ---
    @@ -219,10 +219,38 @@ public static ClosureExpression closureX(Statement code) {
             return result;
         }
     
    +    /**
    +     * Build a binary expression that compares two values
    +     * @param lhv expression for the value to compare from
    +     * @param rhv expression for the value value to compare to
    +     * @return the expression comparing two values
    +     */
         public static BinaryExpression cmpX(Expression lhv, Expression rhv) {
             return new BinaryExpression(lhv, CMP, rhv);
         }
     
    +    /**
    +     * Build a binary expression that compares two values
    +     * @param lhv expression for the value to compare from
    +     * @param rhv expression for the value value to compare to
    +     * @param reversed whether to use natural ordering or reversed natural ordering
    +     * @return the expression comparing two values
    +     */
    +    public static BinaryExpression cmpX(Expression lhv, Expression rhv, boolean reversed) {
    +        return (reversed) ? cmpXReversed(lhv, rhv) : cmpX(lhv, rhv);
    --- End diff --
   
    What about `return (reversed) ? cmpX(rhv, lhv) : cmpX(lhv, rhv);`?  Could eliminate the need for the new `cmpXReversed` method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
In reply to this post by asfgit
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/558#discussion_r125555008
 
    --- Diff: src/main/org/codehaus/groovy/transform/SortableASTTransformation.java ---
    @@ -82,6 +82,7 @@ public void visit(ASTNode[] nodes, SourceUnit source) {
         private void createSortable(AnnotationNode annotation, ClassNode classNode) {
             List<String> includes = getMemberStringList(annotation, "includes");
             List<String> excludes = getMemberStringList(annotation, "excludes");
    +        boolean reversed = getMemberBoolValue(annotation, "reversed");
    --- End diff --
   
    `boolean reversed = memberHasValue(annotation, "reversed", true);`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
In reply to this post by asfgit
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/558#discussion_r125553175
 
    --- Diff: src/main/org/codehaus/groovy/transform/SortableASTTransformation.java ---
    @@ -112,7 +113,7 @@ private static void implementComparable(ClassNode classNode) {
             }
         }
     
    -    private static Statement createCompareToMethodBody(List<PropertyNode> properties) {
    +    private static Statement createCompareToMethodBody(List<PropertyNode> properties, Boolean reversed) {
    --- End diff --
   
    `boolean` as the parameter type would be consistent with the other methods below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
In reply to this post by asfgit
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/558#discussion_r125554738
 
    --- Diff: src/main/org/codehaus/groovy/transform/AbstractASTTransformation.java ---
    @@ -115,6 +115,14 @@ public int getMemberIntValue(AnnotationNode node, String name) {
             return 0;
         }
     
    +    public boolean getMemberBoolValue(AnnotationNode node, String name) {
    --- End diff --
   
    I think it's common to use `memberHasValue` for evaluating boolean attributes, so this new method is probably not needed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
In reply to this post by asfgit
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/558#discussion_r125553663
 
    --- Diff: src/main/groovy/transform/Sortable.java ---
    @@ -145,4 +170,9 @@
          * Must not be used if 'includes' is used.
          */
         String[] excludes() default {};
    +
    +    /**
    +     * Set to true so that comparator uses reversed natural order.
    +     */
    --- End diff --
   
    Would be good to add `@since 2.5.0`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...

asfgit
In reply to this post by asfgit
Github user asfgit closed the pull request at:

    https://github.com/apache/groovy/pull/558


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [hidden email] or file a JIRA ticket
with INFRA.
---
Loading...