Your SlideShare is downloading. ×
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Jggug Nagoya 20090925 Groovy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Jggug Nagoya 20090925 Groovy

1,764

Published on

Groovy seminar hands-out

Groovy seminar hands-out

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,764
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
46
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JGGUG Grails/Groovy 3 NTT 2009/9/25
  • 2. NTT Gr Grails JavaWorld Groovy (2004) Twitter: uehaj Slide# 2 JGGUG Grails/Groovy 3 / 2009.09.25
  • 3. Groovy Groovy Java (Groovy Web Console) 3 Slide# JGGUG Grails/Groovy 3 / 2009.09.25
  • 4. ( ) ( , ) ( ) ( ) Slide# 4 JGGUG Grails/Groovy 3 / 2009.09.25
  • 5. Groovy X Y Z Z(Y(X)) … ← X.Y().Z() … → : Groovy × println(each(sort(grep({it%2=0},[1,3,2])))) ○ [1,3,2].grep{it%2==0}.sort().each{println it} Slide# 5 JGGUG Grails/Groovy 3 / 2009.09.25
  • 6. each/reverseEach/ collect eachWithIndex/ find/findAll grep/max/min reverse/push/pop/join any/every contains/in/groupBy flatten/intersect/disjoint each/keySet/entrySet/ values combinations/ transpose Slide# 6 JGGUG Grails/Groovy 3 / 2009.09.25
  • 7. : ArrayList  println([1,2,3].class) =>java.util.ArrayList as :  [1,2,3] as Set                   // Set  [1,2,3] as LinkedList        // LinkedList  [1,2,3].asImmutable()       // Slide# 7 JGGUG Grails/Groovy 3 / 2009.09.25
  • 8. : LinkedHashMap println([a:1,b:2,c:3].getClass()) =>java.util.LinkedHashMap Map m = [a:1, b:2, c:3]  assert m.get(’a’) == 1   //  assert m[’a’] == 1       //  assert m.a == 1          // Slide# 8 JGGUG Grails/Groovy 3 / 2009.09.25
  • 9. map.get(key) map.put(key, Java value) map[’a’] map[key]          map.a map.”$key” GString Slide# 9 JGGUG Grails/Groovy 3 / 2009.09.25
  • 10. , , class City cities class City { def name; def country; long population; } cities = [ new City(" "," ",35676000), new City(" "," ",19040000), new City(" = "," : Slide# 10 JGGUG Grails/Groovy 3 / 2009.09.25
  • 11. ( ) / ≒ Java Closure println {->}.class ==> groovy.lang.Closure Slide# 11 JGGUG Grails/Groovy 3 / 2009.09.25
  • 12. {-> ..} ( ) {-> println ”ABC” } ==> .call() {->println ”ABC” }.call() ==> ABC Slide# 12 JGGUG Grails/Groovy 3 / 2009.09.25
  • 13. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script result = 1 10.times { result *= 2 } assert result == Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 14. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script result = 1 10.times { Integer(10) result *= 2 } assert result == Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 15. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 16. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 17. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == } { result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 18. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 19. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 20. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 21. : Script.groovy result = 1 10.times {   result *= 2 } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 (call) } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 22. : Script.groovy result = 1 10.times {   result *= 2 (result) } assert result == 1024 Script Integer (10) result = 1 10.times { Integer(10) def result *= 2 times(Closure c){ } c.call() 10 assert result == Integer#times } { (call) (call) result *= 2 (call) } Slide# 13 JGGUG Grails/Groovy 3 / 2009.09.25
  • 23. : import javax.swing.* import java.awt.event.* f = new JFrame(size:[200, 100]) title = "hello" b = new JButton(title) b.addActionListener({println title} as ActionListener) f.contentPane.add(b) f.show() as 1 implements key, value Slide# 14 JGGUG Grails/Groovy 3 / 2009.09.25
  • 24. ExpandoMetaClass ( ) DSL : Slide# 15 JGGUG Grails/Groovy 3 / 2009.09.25
  • 25. ? Slide# 16 JGGUG Grails/Groovy 3 / 2009.09.25
  • 26. ? Slide# 16 JGGUG Grails/Groovy 3 / 2009.09.25
  • 27. : ==~ =~ String.replaceAll( ) :/ / ( ) GString $ ”ABCDE” ’ABCDE’ /ABCDE/ Slide# 17 JGGUG Grails/Groovy 3 / 2009.09.25
  • 28. : String#replaceAll(String, Closure) "abcDefGhi".replaceAll(/([a-z])([A-Z])/) {fullMatch, g1, g2-> g1 + '_' + g2.toLowerCase() } ==> "abc_def_ghi" Java String#replaceAll(String, String) OK($1,$2 ) Slide# 18 JGGUG Grails/Groovy 3 / 2009.09.25
  • 29. final : Slide# 19 JGGUG Grails/Groovy 3 / 2009.09.25
  • 30. : java.lang.String final String String Slide# 20 JGGUG Grails/Groovy 3 / 2009.09.25
  • 31. tr ( ) String#tr() String.metaClass.tr = {from,to ->   def result = delegate   from.eachWithIndex{it,idx->     result = result.replaceAll(it, to.getAt(idx))   }   result } println "abcdef 123".tr("abc ","xyz ") //==> "xyzdef 123" Slide# 21 JGGUG Grails/Groovy 3 / 2009.09.25
  • 32. : java.lang.String Slide# 22 JGGUG Grails/Groovy 3 / 2009.09.25
  • 33. 'ls'.metaClass.exec = { new File(".").eachFile{println it} } 'pwd'.metaClass.exec = { println new File(".").absolutePath } 'env'.metaClass.exec = { System.getenv().each{k,v->println "$k=$v" } } System.in.eachLine {   it.intern().exec() } → : String#intern() Slide# 23 JGGUG Grails/Groovy 3 / 2009.09.25
  • 34. Groovy ( 1) groovyc Groovy groovyc jad( ) groovyc jad Java Groovy 1.6.x Slide# 24 JGGUG Grails/Groovy 3 / 2009.09.25
  • 35. Groovy ( 2) GDK DGM DefaultGroovyMethods.java( DefaultGroovyStaticMethods) <GROOVY_SRC>/src/main/org/codehaus/groovy/ runtime/DefaultGroovyMethods.java Groovy ant -Dskiptests=true GROOVY_HOME <GROOVY_SRC>/target/install Slide# 25 JGGUG Grails/Groovy 3 / 2009.09.25
  • 36. Groovy ( ) Grape(Groovy 1.6-,) Jar ( ) import @Grab(‘group:mod:ver’) (1.7) Power Assert(1.7beta1-) assert a=5; assert a+Math.max(a+1, 5)+2==12 ==> Assertion failed: assert a+Math.max(a+1, 5)+2==12 || | || | | |11 6 |6 | false 5 5 13 at Script1.run(Script1.groovy:2) Slide# 26 JGGUG Grails/Groovy 3 / 2009.09.25
  • 37. Groovy DB (GroovySql) (SimpleTemplate) XML (XmlSlurper, XmlParser) Slide# 27 JGGUG Grails/Groovy 3 / 2009.09.25

×