[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/419 --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/419#discussion_r79297434 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8928,6 +8932,27 @@ public int compare(Map.Entry e1, Map.Entry e2) { if (self.isEmpty()) { throw new NoSuchElementException("Cannot pop() an empty List"); } +return self.remove(0); +} + +/** + * Removes the last item from the List. Using add() and pop() + * is similar to push and pop on a Stack. + * + * def list = ["a", false, 2] + * assert list.removeLast() == 2 + * assert list == ["a", false] + * + * + * @param self a List + * @return the item removed from the List + * @throws NoSuchElementException if the list is empty and you try to pop() it. --- End diff -- I think `if the list is empty` suffices here and don't think the rest of the sentence is needed (same for `pop` throws). --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/419#discussion_r79297452 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8966,20 +8991,24 @@ public int compare(Map.Entry e1, Map.Entry e2) { } /** - * Appends an item to the List. Synonym for add(). - * def list = [3, 4, 2] + * Prepends an item to the start of the List, similar to push on a stack. --- End diff -- Same comment as with pop, would using Deque instead of Stack make sense? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/419#discussion_r79297398 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8928,6 +8932,27 @@ public int compare(Map.Entry e1, Map.Entry e2) { if (self.isEmpty()) { throw new NoSuchElementException("Cannot pop() an empty List"); } +return self.remove(0); +} + +/** + * Removes the last item from the List. Using add() and pop() --- End diff -- Should this be `removeLast()` instead of `pop()` --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/419#discussion_r79297378 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8913,11 +8913,15 @@ public int compare(Map.Entry e1, Map.Entry e2) { } /** - * Removes the last item from the List. Using add() and pop() - * is similar to push and pop on a Stack. - * def list = ["a", false, 2] - * assert list.pop() == 2 - * assert list == ["a", false] + * Removes the initial item from the List, similar to pop on a Stack. --- End diff -- I wonder if most associate removing items from the top of a Stack, so in this case would it make sense to say >..similar to pop on a Deque. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/419#discussion_r79297442 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -8928,6 +8932,27 @@ public int compare(Map.Entry e1, Map.Entry e2) { if (self.isEmpty()) { throw new NoSuchElementException("Cannot pop() an empty List"); } +return self.remove(0); +} + +/** + * Removes the last item from the List. Using add() and pop() + * is similar to push and pop on a Stack. + * + * def list = ["a", false, 2] + * assert list.removeLast() == 2 + * assert list == ["a", false] + * + * + * @param self a List + * @return the item removed from the List + * @throws NoSuchElementException if the list is empty and you try to pop() it. + * @since 2.5.0 + */ +public static T removeLast(List self) { +if (self.isEmpty()) { +throw new NoSuchElementException("Cannot pop() an empty List"); --- End diff -- `pop()` -> `removeLast()` --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] groovy pull request #419: GROOVY-6396: same linkedlist code different behavi...
GitHub user paulk-asert opened a pull request: https://github.com/apache/groovy/pull/419 GROOVY-6396: same linkedlist code different behavior between groovy a⦠â¦nd java You can merge this pull request into a Git repository by running: $ git pull https://github.com/paulk-asert/groovy groovy6396 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/419.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 #419 commit 72bcd6ed039b854678228653daf88acc8604676b Author: paulk Date: 2016-09-13T09:40:31Z GROOVY-6396: same linkedlist code different behavior between groovy and java --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---