jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
groovy
  • groovy
  • GROOVY-2597

Map or Property Sort

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.7.2, 1.8-beta-1
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    All
  • Number of attachments :
    0

Description

It would be handy to have a sort method on a Map or Property that would sort by the name/key since this is something that is commonly done. A possible implementation for a Property class might look like this:

Properties.metaClass.sort = {
new TreeMap(delegate)
}

Example usage would be:

System.properties.sort()

Issue Links

relates to

Improvement - An improvement or enhancement to an existing feature or task. GROOVY-3992 Add a reverse method to Map

  • Minor - Minor loss of function, or other problem where easy workaround is present.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
blackdrag blackdrag added a comment - 12/Feb/08 6:25 AM

you mean

System.properties.sort()

vs.

new TreeMap(System.properties)

that's all you suggest, right? In general there is a problem with sorting a map and that is... is it sorting by key, or by value, with what Comperator? Depending on the usage each case make in itself make sense. But your suggestions does not reflect any of this.

Show
blackdrag blackdrag added a comment - 12/Feb/08 6:25 AM you mean System .properties.sort() vs. new TreeMap( System .properties) that's all you suggest, right? In general there is a problem with sorting a map and that is... is it sorting by key, or by value, with what Comperator? Depending on the usage each case make in itself make sense. But your suggestions does not reflect any of this.
Hide
Permalink
Christopher Judd added a comment - 12/Feb/08 6:41 AM

Yes. I would rather type System.properties.sort() to sort. An overloaded sort method that takes a Comperator would be a good idea as well. But at least for Properties a default of ordering by the name in alphabetical order make sense.

Show
Christopher Judd added a comment - 12/Feb/08 6:41 AM Yes. I would rather type System.properties.sort() to sort. An overloaded sort method that takes a Comperator would be a good idea as well. But at least for Properties a default of ordering by the name in alphabetical order make sense.
Hide
Permalink
Paul King added a comment - 13/Mar/10 5:39 AM

Just noticed that there is already support for this:

System.properties.sort{ it.key }
Show
Paul King added a comment - 13/Mar/10 5:39 AM Just noticed that there is already support for this: System .properties.sort{ it.key }
Hide
Permalink
Paul King added a comment - 13/Mar/10 6:24 AM

Added sort() and sort(Comparator) variants.

Show
Paul King added a comment - 13/Mar/10 6:24 AM Added sort() and sort(Comparator) variants.

People

  • Assignee:
    Paul King
    Reporter:
    Christopher Judd
Vote (0)
Watch (2)

Dates

  • Created:
    11/Feb/08 8:07 PM
    Updated:
    07/Apr/10 11:45 PM
    Resolved:
    13/Mar/10 6:24 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.