SlideShare una empresa de Scribd logo
1 de 37
JGGUG
Grails/Groovy         3




   NTT


          2009/9/25
NTT

                        Gr

               Grails

            JavaWorld Groovy                               (2004)

            Twitter: uehaj




Slide# 2   JGGUG        Grails/Groovy   3   / 2009.09.25
Groovy




           Groovy
                                    Java




                                                         (Groovy Web Console)
     3
Slide#   JGGUG      Grails/Groovy     3   / 2009.09.25
(                 )
                                   (               ,      )




                            (                 )
                            (                       )

Slide# 4   JGGUG   Grails/Groovy       3   / 2009.09.25
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
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
:
                                                          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
:

                                             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
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
,     ,
              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
(                  )


                                     /


                ≒ Java

                     Closure
                println {->}.class
                ==> groovy.lang.Closure

Slide# 11   JGGUG    Grails/Groovy       3   / 2009.09.25
{-> ..}

                                                           (   )
                {-> println ”ABC” }
                ==>
                                      .call()
                {->println ”ABC” }.call()

                ==> ABC

Slide# 12   JGGUG     Grails/Groovy    3   / 2009.09.25
:
             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
:
             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
:
             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
:
             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
:
             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
:
             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
:
             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
:
             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
:
             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
:
             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
:
    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
ExpandoMetaClass
                    (                   )




                                                                    DSL


                :

Slide# 15   JGGUG       Grails/Groovy   3   / 2009.09.25
?




Slide# 16   JGGUG   Grails/Groovy   3   / 2009.09.25
?




Slide# 16   JGGUG   Grails/Groovy   3   / 2009.09.25
:                ==~ =~
                 String.replaceAll(  )
             :/     /


                                 ( )                      GString   $

      ”ABCDE”
       ’ABCDE’
       /ABCDE/

Slide# 17   JGGUG       Grails/Groovy   3   / 2009.09.25
:
            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
final




                      :



Slide# 19   JGGUG          Grails/Groovy   3   / 2009.09.25
: java.lang.String
                                         final


                    String

                    String




Slide# 20   JGGUG        Grails/Groovy    3   / 2009.09.25
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
:
                          java.lang.String




Slide# 22   JGGUG   Grails/Groovy   3   / 2009.09.25
'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
Groovy                                  (              1)
                    groovyc
                                                      Groovy



                    groovyc jad(                                  )
                     groovyc             jad               Java

                             Groovy 1.6.x



Slide# 24   JGGUG        Grails/Groovy     3   / 2009.09.25
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
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
Groovy




                DB       (GroovySql)
                                      (SimpleTemplate)
                                              XML          (XmlSlurper,
                XmlParser)


Slide# 27   JGGUG     Grails/Groovy     3   / 2009.09.25

Más contenido relacionado

Similar a Jggug Nagoya 20090925 Groovy

Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume LaforgeGroovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Guillaume Laforge
 
Groovy Api Tutorial
Groovy Api  TutorialGroovy Api  Tutorial
Groovy Api Tutorial
guligala
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 

Similar a Jggug Nagoya 20090925 Groovy (20)

Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume LaforgeGroovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
Groovy to infinity and beyond - GR8Conf Europe 2010 - Guillaume Laforge
 
Groovy
GroovyGroovy
Groovy
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 
Introduction to Grails
Introduction to Grails Introduction to Grails
Introduction to Grails
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~
 
Groovy Api Tutorial
Groovy Api  TutorialGroovy Api  Tutorial
Groovy Api Tutorial
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
Groovy as a scripting language
Groovy as a scripting languageGroovy as a scripting language
Groovy as a scripting language
 
Groovy
GroovyGroovy
Groovy
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
OpenLogic
OpenLogicOpenLogic
OpenLogic
 
Startup groovysession1
Startup groovysession1Startup groovysession1
Startup groovysession1
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial Slides
 
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume LaforgeGroovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
Groovy: to Infinity and Beyond -- JavaOne 2010 -- Guillaume Laforge
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 

Más de Uehara Junji

Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309
Uehara Junji
 
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Uehara Junji
 
Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)
Uehara Junji
 

Más de Uehara Junji (20)

Groovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUGGroovy Bootcamp 2015 by JGGUG
Groovy Bootcamp 2015 by JGGUG
 
Groovy Shell Scripting 2015
Groovy Shell Scripting 2015Groovy Shell Scripting 2015
Groovy Shell Scripting 2015
 
Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418Shibuya JVM Groovy 20150418
Shibuya JVM Groovy 20150418
 
Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait Introduce Groovy 2.3 trait
Introduce Groovy 2.3 trait
 
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ckIndy(Invokedynamic) and Bytecode DSL and Brainf*ck
Indy(Invokedynamic) and Bytecode DSL and Brainf*ck
 
enterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summerenterprise grails challenge, 2013 Summer
enterprise grails challenge, 2013 Summer
 
New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1New features of Groovy 2.0 and 2.1
New features of Groovy 2.0 and 2.1
 
Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309Groovy kisobenkyoukai20130309
Groovy kisobenkyoukai20130309
 
Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)Read Groovy Compile process(Groovy Benkyoukai 2013)
Read Groovy Compile process(Groovy Benkyoukai 2013)
 
groovy 2.1.0 20130118
groovy 2.1.0 20130118groovy 2.1.0 20130118
groovy 2.1.0 20130118
 
G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901G* Workshop in fukuoka 20120901
G* Workshop in fukuoka 20120901
 
JJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/GrailsJJUG CCC 2012 Real World Groovy/Grails
JJUG CCC 2012 Real World Groovy/Grails
 
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)Java One 2012 Tokyo JVM Lang. BOF(Groovy)
Java One 2012 Tokyo JVM Lang. BOF(Groovy)
 
Java x Groovy: improve your java development life
Java x Groovy: improve your java development lifeJava x Groovy: improve your java development life
Java x Groovy: improve your java development life
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)Easy Going Groovy(Groovyを気軽に使いこなそう)
Easy Going Groovy(Groovyを気軽に使いこなそう)
 
GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.GroovyServ concept, how to use and outline.
GroovyServ concept, how to use and outline.
 
Clojure
ClojureClojure
Clojure
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Jggug Nagoya 20090925 Groovy

  • 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