groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donny (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7809) Create a map from selected properties of an Object
Date Tue, 05 Apr 2016 04:03:25 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-7809?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Donny updated GROOVY-7809:
--------------------------
    Description: 
It would be nice if Groovy allows developers to create a map from selected properties of an
Object.

Below are the example:

{code:title=Example|theme=FadeToGrey|linenumbers=true|language=groovy|firstline=0001|collapse=false}

class Hero {
    String name
    Integer strength
    Integer constitution
    String weakness
}

Hero hero = new Hero(name: "Robin", strength: 70, constitution: 80, weakness: "Beautiful Women")

def mapNoWeakness = hero.asMap(['name', 'strength', 'constitution'])

println mapNoWeakness // [name: 'Robin', strength: 70, constitution: 80]

def mapOnlyName = hero.asMap(['name'])

println mapOnlyName // [name: 'Robin']

{code}

  was:
It would be nice if Groovy allows developers to create a map from selected properties of an
Object

Below are the example:

{code:title=Example|theme=FadeToGrey|linenumbers=true|language=groovy|firstline=0001|collapse=false}

class Hero {
    String name
    Integer strength
    Integer constitution
    String weakness
}

Hero hero = new Hero(name: "Robin", strength: 70, constitution: 80, weakness: "Beautiful Women")

def mapNoWeakness = hero.asMap(['name', 'strength', 'constitution'])

println mapNoWeakness // [name: 'Robin', strength: 70, constitution: 80]

def mapOnlyName = hero.asMap(['name'])

println mapOnlyName // [name: 'Robin']

{code}


> Create a map from selected properties of an Object
> --------------------------------------------------
>
>                 Key: GROOVY-7809
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7809
>             Project: Groovy
>          Issue Type: New Feature
>          Components: syntax
>            Reporter: Donny
>            Priority: Minor
>
> It would be nice if Groovy allows developers to create a map from selected properties
of an Object.
> Below are the example:
> {code:title=Example|theme=FadeToGrey|linenumbers=true|language=groovy|firstline=0001|collapse=false}
> class Hero {
>     String name
>     Integer strength
>     Integer constitution
>     String weakness
> }
> Hero hero = new Hero(name: "Robin", strength: 70, constitution: 80, weakness: "Beautiful
Women")
> def mapNoWeakness = hero.asMap(['name', 'strength', 'constitution'])
> println mapNoWeakness // [name: 'Robin', strength: 70, constitution: 80]
> def mapOnlyName = hero.asMap(['name'])
> println mapOnlyName // [name: 'Robin']
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message