Monday 15 August 2011

groovy - Grails Search Map -


I am a Java programmer trying to write some Groovy code.

I want to redo via the map, the login is called the attribute value, and each key (for example, the user name) gets a cross-reference attribute value and prints it: / P>

john: display_name

However, I'm getting my Java brain. Groovy syntax can anyone show me the right direction? Thank you.

  loginAttributeValues ​​= [user name: 'zone', email: 'john@smith.com'] def map xref = [username: 'display_name', first name: 'first_name', Last name: {if (mapXref [x]) println (mapXref.get (x))}    

  loginAttributeValues ​​= [user name: 'john', email: 'john@smith.com'] def map xref = [username: 'display_name ', Firstname:' first_name ', last name:' last_name ', email:' email '] def newmap = [:] login attribute value. V - & gt; Newmap & lt; & Lt; (MapXref.keySet () in (k): ([v]: mapXref [k]]: [:])} Insert the new map. 'Zone' == 'display_name' newMap. 'John Smith@smith.com I hope you want a map like   

/ Code>

but as john as key and display_name as the value Why should it be? It should not be otherwise. In that case, you should

  newMap & lt; (mapXref.keySet) mapXref.keySet ()? [MapXref [ K]: v]: [:])   

that as

  Will claim newMap Display_name == 'John' emphasizes newMap.email == 'john@smith.com'   

Note: -
If it is a guarantee that login attitudinal value will be key key in mapXref , then the logic is optimized as below Can be done

  diff newMap = loginAttributeValues.collectEntries {k, v - & gt; [V, mapXref [k]]}    

No comments:

Post a Comment