Groovy
1.8
  Groovy
Slide # 2   JGGUG G*Workshop 17th / 2011.6.17
http://d.hatena.ne.jp/uehaj/




Slide # 3   JGGUG G*Workshop 17th / 2011.6.17
Slide # 4   JGGUG G*Workshop 17th / 2011.6.17
Slide # 5   JGGUG G*Workshop 17th / 2011.6.17
April 28, 2011


Slide # 6   JGGUG G*Workshop 17th / 2011.6.17
April 28, 2011


Slide # 6   JGGUG G*Workshop 17th / 2011.6.17
Slide #   JGGUG G*Workshop 17th / 2011.6.17
$ cat input.txt
            That that is is that that is
            not is not is that it it is

            $ java WordCount input.txt
            1: [That]
            2: [not]
            2: [it]
            4: [that]
            6: [is]
Slide # 8          JGGUG G*Workshop 17th / 2011.6.17
Java                WordCount:48
                                                       Set<Map.Entry<String, Integer>> entrySet =
import   java.util.Comparator;                    map.entrySet();
import   java.util.HashMap;                            Object[] list = entrySet.toArray();
import   java.util.Map;                                 Comparator comp = new Comparator(){
import   java.util.Set;                                  public int compare(Object o1, Object o2)
import   java.util.List;                          {
import   java.util.Arrays;                                 Map.Entry<String, Integer> e1 =
import   java.io.FileReader;                      (Map.Entry<String, Integer>) o1;
import   java.io.BufferedReader;                           Map.Entry<String, Integer> e2 =
import   java.io.FileNotFoundException;           (Map.Entry<String, Integer>) o2;
import   java.io.IOException;                               return e1.getValue() - e2.getValue();
                                                          }
public class WordCount {                                };
  @SuppressWarnings(value = "unchecked")                Arrays.sort(list, comp);
  public static void main(String[] args) {              for (Object it: list) {
    FileReader fis = null;                                Map.Entry<String, Integer> entry =
    BufferedReader br = null;                     (Map.Entry<String, Integer>)it;
    try {                                                 System.out.println(entry.getValue() + ":
      HashMap<String, Integer> map = new          ["+entry.getKey()+"]");
HashMap<String, Integer>();                             }
      fis = new FileReader(args[0]);                  }
      br = new BufferedReader(fis);                   catch (IOException e) {
      String line;                                      try {if (br != null)
      while ((line = br.readLine()) != null) {    br.close();}catch(IOException ioe){}
        for (String it: line.split("s+")) {           try {if (fis !=
          map.put(it, (map.get(it)==null) ? 1 :   null)fis.close();}catch(IOException ioe){}
(map.get(it) + 1));                                     e.printStackTrace();
        }                                             }
      }                                             }
                                                  }
Slide # 9                 JGGUG G*Workshop 17th / 2011.6.17
Groovy WordCount(9                              )
      def map = [:].withDefault{0}
     new File(args[0]).eachLine {
       it.split(/s+/).each {
         map[it]++
      }
     }
     map.entrySet().sort{it.value}.each {
       println "${it.value}: [${it.key}]"
     }




Slide # 10           JGGUG G*Workshop 17th / 2011.6.17
Java
                                                                       Set<Map.Entry<String, Integer>>
import   java.util.Comparator;                             entrySet = map.entrySet();
import   java.util.HashMap;                                            Object[] list = entrySet.toArray();
import   java.util.Map;                                                Comparator comp = new Comparator(){
import   java.util.Set;                                                    public int compare(Object o1,
import   java.util.List;                                   Object o2) {
import   java.util.Arrays;                                                     Map.Entry<String, Integer> e1
import   java.io.FileReader;                               = (Map.Entry<String, Integer>) o1;
import   java.io.BufferedReader;                                               Map.Entry<String, Integer> e2
import   java.io.FileNotFoundException;                    = (Map.Entry<String, Integer>) o2;
import   java.io.IOException;                                                  return e1.getValue() -
                                                           e2.getValue();
 public class WordCount {                                                  }
     @SuppressWarnings(value = "unchecked")                            };
     public static void main(String[] args) {                          Arrays.sort(list, comp);
         FileReader fis = null;                                        for (Object it: list) {
         BufferedReader br = null;                                         Map.Entry<String, Integer> entry =
         try {                                             (Map.Entry<String, Integer>)it;
             HashMap<String, Integer> map = new                            
 HashMap<String, Integer>();                               System.out.println(entry.getValue() + ":
             fis = new FileReader(args[0]);                ["+entry.getKey()+"]");
             br = new BufferedReader(fis);                             }
             String line;                                          }
             while ((line = br.readLine()) != null)                catch (IOException e) {
 {                                                                     try {if (br != null)
                 for (String it: line.split("s           br.close();}catch(IOException ioe){}
 +")) {                                                                try {if (fis !=
                     map.put(it,                           null)fis.close();}catch(IOException ioe){}
 (map.get(it)==null) ? 1 : (map.get(it) + 1));                         e.printStackTrace();
Slide # 11       }
                          JGGUG G*Workshop 17th       /            }
                                                          2011.6.17
             }                                                 }
Groovy WordCount(9                                        )
    def map = [:].withDefault{0} // value                    0        map
    new File(args[0]).eachLine { //
      it.split(/s+/).each {     //            /s+/
        map[it]++                //          map                  1
      }
    }
    map.entrySet().sort{it.value}.each {// map         entrySet   value
      println "${it.value}: [${it.key}]"//                key,value
    }




Slide # 12        JGGUG G*Workshop 17th / 2011.6.17
(→4
 def map = new File(args[0]).text.split(/s+/).countBy{it}
 map.entrySet().sort{it.value}.each {
   println "${it.value}: [${it.key}]"
 }




Slide # 13   JGGUG G*Workshop 17th / 2011.6.17
(→4
 def map = new File(args[0]).text.split(/s+/).countBy{it}
 map.entrySet().sort{it.value}.each {
   println "${it.value}: [${it.key}]"
 }




Slide # 13   JGGUG G*Workshop 17th / 2011.6.17
Slide # 14   JGGUG G*Workshop 17th / 2011.6.17
AST




                  Groovy 1.8.0




Slide # 15   JGGUG G*Workshop 17th / 2011.6.17
AST




             (curry)
                            Groovy 1.8.0




Slide # 15             JGGUG G*Workshop 17th / 2011.6.17
AST


                                                                        AST
                                                                 AST
                                                                  AST

             (curry)
                            Groovy 1.8.0




Slide # 15             JGGUG G*Workshop 17th / 2011.6.17
AST


                                                                        AST
                                                                 AST
                                                                  AST

             (curry)
                            Groovy 1.8.0




Slide # 15             JGGUG G*Workshop 17th / 2011.6.17
AST


                                                                         AST
                                                                  AST
                                                                   AST

             (curry)
                             Groovy 1.8.0



                                        (GEP3)
                       $/                            /$

Slide # 15              JGGUG G*Workshop 17th / 2011.6.17
AST


                                                                            AST
                                                                     AST
                                                                      AST

             (curry)
                             Groovy 1.8.0


                                                             GDK Groovy API
                                                            GPars
                                        (GEP3)
                                                              GSql
                       $/                            /$

Slide # 15              JGGUG G*Workshop 17th / 2011.6.17
AST


                                                                            AST
                                                                     AST
                                                                      AST

             (curry)
                             Groovy 1.8.0
                                                                                     jar

                                                                                  Grab
                                                                                  GroovyDoc



                                                             GDK Groovy API
                                                            GPars
                                        (GEP3)
                                                              GSql
                       $/                            /$

Slide # 15              JGGUG G*Workshop 17th / 2011.6.17
Groovy 1.8.0

                              (GEP3)
             $/                                       /$
             /
                                      /
Slide # 16        JGGUG G*Workshop 17th / 2011.6.17
println 1+1 //


             m1(a1).m2(a2).m3(a3)



             m1 a1   m2 a2        m3 a3




Slide # 17      JGGUG G*Workshop 17th / 2011.6.17
turn left then right p.p1
        // turn(left).then(right)
        paint wall with red, green and yellow
        // paint(wall).with(red, green).and(yellow)


        take 3 cookies 
        // take(3).cookies
        // take(3).getCookies()                                

        given { } when { } then { }
        // given({}).when({}).then({})
                                http://groovy.codehaus.org/Groovy+1.8+release+notes

Slide # 18     JGGUG G*Workshop 17th / 2011.6.17
$/…/$
                      ///…///(                       )
                                      /…/

        a=$/




        /$


                 $/

Slide # 19       JGGUG G*Workshop 17th / 2011.6.17
AST


                                                         AST

             Groovy 1.8.0                          AST


                                                   AST




Slide # 20     JGGUG G*Workshop 17th / 2011.6.17
Slide # 21   JGGUG G*Workshop 17th / 2011.6.17
Slide # 21   JGGUG G*Workshop 17th / 2011.6.17
Slide # 22   JGGUG G*Workshop 17th / 2011.6.17
Slide # 23   JGGUG G*Workshop 17th / 2011.6.17
import groovy.util.logging.Log
       @Log class MyClass {
         def invoke() {
           log.info 'info message'
           log.fine 'fine message'
         }
       }
Slide # 24                 JGGUG G*Workshop 17th / 2011.6.17
        http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
log.info <                  >



             <     >



       log.isLoggabl(java.util.logging.Level.INFO)
       ? log.info(< >) : null




Slide # 25                 JGGUG G*Workshop 17th / 2011.6.17
        http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
@TupleConstructor                                     class MyClass {
        class MyClass {                                          def a
           def a                                                 def b
           def b                                                 def c
           def c                                                 MyClass(a,b,c) {
         }                                                        this.a=a
        }                                                         this.b=b
                                                                  this.c=c
                                                                 }
                                                               }



Slide # 26                 JGGUG G*Workshop 17th / 2011.6.17
        http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
Slide # 27   JGGUG G*Workshop 17th / 2011.6.17
class MyClass {
       @WithReadLock def             () {         }
       @WithWriteLock def              () {       }
     }
Slide # 28    JGGUG G*Workshop 17th / 2011.6.17
class MyClass {
       @WithReadLock def             () {         }
       @WithWriteLock def              () {       }
     }
Slide # 28    JGGUG G*Workshop 17th / 2011.6.17
Slide # 29   JGGUG G*Workshop 17th / 2011.6.17
while (true) {
                                                                                ←
                                                                   println ”xx”
                                                                 }


       while (true) {
         if (java.lang.Thread.currentThread().isInterrupted()) {
           throw new InterruptedException('Execution
       Interrupted')
         }
         println ”xx”
       }
Slide # 30                 JGGUG G*Workshop 17th / 2011.6.17
        http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
foo.groovy:

       String a=”ABC”
       def bar() { println a }
       bar() // =>           a

                     class foo extends Script {
                       void run() {
                         String a = ”ABC”
                         bar()
                       }
                       def bar() { println a }
                     }
Slide # 31    JGGUG G*Workshop 17th / 2011.6.17
foo.groovy:

       @Field String a=”ABC”
       def bar() { println a }
       bar() ==> “ABC”

                     class foo extends Script {
                       String a = ”ABC”
                       void run() {
                         bar()
                       }
                       def bar() { println a }
                     }
Slide # 32    JGGUG G*Workshop 17th / 2011.6.17
Slide # 33   JGGUG G*Workshop 17th / 2011.6.17
Groovy 1.8.0



             (curry)
Slide # 34    JGGUG G*Workshop 17th / 2011.6.17
@ConditionalInterrupt({ counter > 100 })
    class Foo {
      int counter = 0
      void run() {
        while (true) {
          counter++ // 100
           }                // InterruptedException
         }
       }
Slide # 35     JGGUG G*Workshop 17th / 2011.6.17
//
    fib1 = { n ->
      n <= 1 ? n : fib1(n - 1) + fib1(n - 2)
    }
    //
    fib2 = { n ->
      n <= 1 ? n : fib2(n - 1) + fib2(n - 2)
    }.memoize()
Slide # 36   JGGUG G*Workshop 17th / 2011.6.17
…
                                                 …

                                                 …



Slide # 37   JGGUG G*Workshop 17th / 2011.6.17
Slide # 38   JGGUG G*Workshop 17th / 2011.6.17
Groovy 1.8.0

                         GDK Groovy API
                         GPars
                           GSql
                                              JSon

Slide #   JGGUG G*Workshop 17th / 2011.6.17
Slide # 40   JGGUG G*Workshop 17th / 2011.6.17
!

Slide # 40   JGGUG G*Workshop 17th / 2011.6.17
Java
          JSON

    ‘’’
    {"name": "John                                         HashMap
    Smith", "age": 33}
    ‘’’                                      JsonSlurper
                                             #parseText(
                                             )
   ‘’’                                                     ArrayList
   ["milk", "bread",
   "eggs"]
   ‘’’
          41



Slide #          JGGUG G*Workshop 17th / 2011.6.17
JSON
                                                bldr = new JsonBuilder()
                                                bldr {
                                                  num 1
                                                  ‘boolean’ true
                                                  arr([1,2,3])
      JSonBuilde                                }
      r

                                                JSON
                           toString()
                                                 ”””{"num":
          42                                     1,"boolean":true,"
                                                 arr":[1,2,3]}”””

Slide #            JGGUG G*Workshop 17th / 2011.6.17
Java                        bldr=new JsonBuilder()
                                                       bldr([ num:1,
                               HashMap                 ’boolean’:true, arr:
      JSonBuilde                                       [1,2,3] ])
      r

                                                       JSON
                             toString()
                                                       “””{"num":
          43                                           1,"boolean":true,"
                                                       arr":[1,2,3]}”””
Slide #            JGGUG G*Workshop 17th / 2011.6.17
JSON

                                               {
                                                   "num": 1,
      JSonBuilde       toPrettyString()            "’boolean’": true,
      r                                            "arr": [
                                                     1,
                                                     2,
                                                     3
                                                   ]
          44                                   }

Slide #            JGGUG G*Workshop 17th / 2011.6.17
Groovy 1.8.0




Slide # 45   JGGUG G*Workshop 17th / 2011.6.17
public class FibBench {
        static int fib(int n) {
          return n <= 1 ? n : fib(n - 1) + fib(n - 2);
        }
      }




                                               (ms)       Java   1

     Groovy 1.8.0                              2664                   2.9
     Groovy 1.7.10                           26702                   28.6
     Groovy++ 0.4.230_1.8.0                    1067                  1.14
     Java SE 1.6.0_22                               933               1.0
Slide # 46      JGGUG G*Workshop 17th / 2011.6.17
(   10       !)

                  1.8.0                                   int



                 Groovy++

             Groovy++                   (Java                   !)




                     Groovy 1.8

Slide # 47       JGGUG G*Workshop 17th / 2011.6.17
Groovy 1.8.0

                                           jar
                                           Grab
                                       GroovyDoc



Slide # 48   JGGUG G*Workshop 17th / 2011.6.17
$ java -jar /tool/groovy-1.8.0/target/
      install/embeddable/groovy-all-1.8.0.jar
      fib.groovy
      time=2542
      time=34




Slide # 49    JGGUG G*Workshop 17th / 2011.6.17
Slide # 50   JGGUG G*Workshop 17th / 2011.6.17
Slide # 51   JGGUG G*Workshop 17th / 2011.6.17
Slide # 52   JGGUG G*Workshop 17th / 2011.6.17

Groovy 1.8の新機能について

  • 1.
  • 2.
    Slide # 2 JGGUG G*Workshop 17th / 2011.6.17
  • 3.
    http://d.hatena.ne.jp/uehaj/ Slide # 3 JGGUG G*Workshop 17th / 2011.6.17
  • 4.
    Slide # 4 JGGUG G*Workshop 17th / 2011.6.17
  • 5.
    Slide # 5 JGGUG G*Workshop 17th / 2011.6.17
  • 6.
    April 28, 2011 Slide# 6 JGGUG G*Workshop 17th / 2011.6.17
  • 7.
    April 28, 2011 Slide# 6 JGGUG G*Workshop 17th / 2011.6.17
  • 8.
    Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 9.
    $ cat input.txt That that is is that that is not is not is that it it is $ java WordCount input.txt 1: [That] 2: [not] 2: [it] 4: [that] 6: [is] Slide # 8 JGGUG G*Workshop 17th / 2011.6.17
  • 10.
    Java WordCount:48      Set<Map.Entry<String, Integer>> entrySet = import java.util.Comparator; map.entrySet(); import java.util.HashMap;      Object[] list = entrySet.toArray(); import java.util.Map;     Comparator comp = new Comparator(){ import java.util.Set;        public int compare(Object o1, Object o2) import java.util.List; { import java.util.Arrays;          Map.Entry<String, Integer> e1 = import java.io.FileReader; (Map.Entry<String, Integer>) o1; import java.io.BufferedReader;          Map.Entry<String, Integer> e2 = import java.io.FileNotFoundException; (Map.Entry<String, Integer>) o2; import java.io.IOException;         return e1.getValue() - e2.getValue();         } public class WordCount {       };   @SuppressWarnings(value = "unchecked")       Arrays.sort(list, comp);   public static void main(String[] args) {       for (Object it: list) {     FileReader fis = null;         Map.Entry<String, Integer> entry =     BufferedReader br = null; (Map.Entry<String, Integer>)it;     try {         System.out.println(entry.getValue() + ":       HashMap<String, Integer> map = new ["+entry.getKey()+"]"); HashMap<String, Integer>();       }       fis = new FileReader(args[0]);     }       br = new BufferedReader(fis);     catch (IOException e) {       String line;       try {if (br != null)       while ((line = br.readLine()) != null) { br.close();}catch(IOException ioe){}         for (String it: line.split("s+")) {       try {if (fis !=          map.put(it, (map.get(it)==null) ? 1 : null)fis.close();}catch(IOException ioe){} (map.get(it) + 1));       e.printStackTrace();         }     }       }   } } Slide # 9 JGGUG G*Workshop 17th / 2011.6.17
  • 11.
    Groovy WordCount(9 ) def map = [:].withDefault{0} new File(args[0]).eachLine {   it.split(/s+/).each {     map[it]++    } } map.entrySet().sort{it.value}.each {   println "${it.value}: [${it.key}]" } Slide # 10 JGGUG G*Workshop 17th / 2011.6.17
  • 12.
    Java             Set<Map.Entry<String, Integer>> import java.util.Comparator; entrySet = map.entrySet(); import java.util.HashMap;             Object[] list = entrySet.toArray(); import java.util.Map;             Comparator comp = new Comparator(){ import java.util.Set;                 public int compare(Object o1, import java.util.List; Object o2) { import java.util.Arrays;                     Map.Entry<String, Integer> e1 import java.io.FileReader; = (Map.Entry<String, Integer>) o1; import java.io.BufferedReader;                     Map.Entry<String, Integer> e2 import java.io.FileNotFoundException; = (Map.Entry<String, Integer>) o2; import java.io.IOException;                     return e1.getValue() - e2.getValue(); public class WordCount {                 }     @SuppressWarnings(value = "unchecked")             };     public static void main(String[] args) {             Arrays.sort(list, comp);         FileReader fis = null;             for (Object it: list) {         BufferedReader br = null;                 Map.Entry<String, Integer> entry =         try { (Map.Entry<String, Integer>)it;             HashMap<String, Integer> map = new                  HashMap<String, Integer>(); System.out.println(entry.getValue() + ":             fis = new FileReader(args[0]); ["+entry.getKey()+"]");             br = new BufferedReader(fis);             }             String line;         }             while ((line = br.readLine()) != null)         catch (IOException e) { {             try {if (br != null)                 for (String it: line.split("s br.close();}catch(IOException ioe){} +")) {             try {if (fis !=                     map.put(it, null)fis.close();}catch(IOException ioe){} (map.get(it)==null) ? 1 : (map.get(it) + 1));             e.printStackTrace(); Slide # 11       }           JGGUG G*Workshop 17th /         } 2011.6.17             }     }
  • 13.
    Groovy WordCount(9 ) def map = [:].withDefault{0} // value 0 map new File(args[0]).eachLine { //   it.split(/s+/).each {     // /s+/     map[it]++                // map 1   } } map.entrySet().sort{it.value}.each {// map entrySet value   println "${it.value}: [${it.key}]"// key,value } Slide # 12 JGGUG G*Workshop 17th / 2011.6.17
  • 14.
    (→4 def map= new File(args[0]).text.split(/s+/).countBy{it} map.entrySet().sort{it.value}.each {   println "${it.value}: [${it.key}]" } Slide # 13 JGGUG G*Workshop 17th / 2011.6.17
  • 15.
    (→4 def map= new File(args[0]).text.split(/s+/).countBy{it} map.entrySet().sort{it.value}.each {   println "${it.value}: [${it.key}]" } Slide # 13 JGGUG G*Workshop 17th / 2011.6.17
  • 16.
    Slide # 14 JGGUG G*Workshop 17th / 2011.6.17
  • 17.
    AST Groovy 1.8.0 Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 18.
    AST (curry) Groovy 1.8.0 Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 19.
    AST AST AST AST (curry) Groovy 1.8.0 Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 20.
    AST AST AST AST (curry) Groovy 1.8.0 Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 21.
    AST AST AST AST (curry) Groovy 1.8.0 (GEP3) $/ /$ Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 22.
    AST AST AST AST (curry) Groovy 1.8.0 GDK Groovy API GPars (GEP3) GSql $/ /$ Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 23.
    AST AST AST AST (curry) Groovy 1.8.0 jar Grab GroovyDoc GDK Groovy API GPars (GEP3) GSql $/ /$ Slide # 15 JGGUG G*Workshop 17th / 2011.6.17
  • 24.
    Groovy 1.8.0 (GEP3) $/ /$ / / Slide # 16 JGGUG G*Workshop 17th / 2011.6.17
  • 25.
    println 1+1 // m1(a1).m2(a2).m3(a3) m1 a1 m2 a2 m3 a3 Slide # 17 JGGUG G*Workshop 17th / 2011.6.17
  • 26.
    turn left then right p.p1 // turn(left).then(right) paint wall with red, green and yellow // paint(wall).with(red, green).and(yellow) take 3 cookies  // take(3).cookies // take(3).getCookies()    given { } when { } then { } // given({}).when({}).then({}) http://groovy.codehaus.org/Groovy+1.8+release+notes Slide # 18 JGGUG G*Workshop 17th / 2011.6.17
  • 27.
    $/…/$ ///…///( ) /…/ a=$/ /$ $/ Slide # 19 JGGUG G*Workshop 17th / 2011.6.17
  • 28.
    AST AST Groovy 1.8.0 AST AST Slide # 20 JGGUG G*Workshop 17th / 2011.6.17
  • 29.
    Slide # 21 JGGUG G*Workshop 17th / 2011.6.17
  • 30.
    Slide # 21 JGGUG G*Workshop 17th / 2011.6.17
  • 31.
    Slide # 22 JGGUG G*Workshop 17th / 2011.6.17
  • 32.
    Slide # 23 JGGUG G*Workshop 17th / 2011.6.17
  • 33.
    import groovy.util.logging.Log @Log class MyClass {   def invoke() {     log.info 'info message'     log.fine 'fine message'   } } Slide # 24 JGGUG G*Workshop 17th / 2011.6.17 http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
  • 34.
    log.info < > < > log.isLoggabl(java.util.logging.Level.INFO) ? log.info(< >) : null Slide # 25 JGGUG G*Workshop 17th / 2011.6.17 http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
  • 35.
    @TupleConstructor class MyClass { class MyClass {    def a    def a    def b    def b    def c    def c    MyClass(a,b,c) {  }     this.a=a }     this.b=b     this.c=c    }  } Slide # 26 JGGUG G*Workshop 17th / 2011.6.17 http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
  • 36.
    Slide # 27 JGGUG G*Workshop 17th / 2011.6.17
  • 37.
    class MyClass {   @WithReadLock def () { }   @WithWriteLock def () { } } Slide # 28 JGGUG G*Workshop 17th / 2011.6.17
  • 38.
    class MyClass {   @WithReadLock def () { }   @WithWriteLock def () { } } Slide # 28 JGGUG G*Workshop 17th / 2011.6.17
  • 39.
    Slide # 29 JGGUG G*Workshop 17th / 2011.6.17
  • 40.
    while (true) { ←   println ”xx” } while (true) {   if (java.lang.Thread.currentThread().isInterrupted()) {     throw new InterruptedException('Execution Interrupted')   }   println ”xx” } Slide # 30 JGGUG G*Workshop 17th / 2011.6.17 http://canoo.com/blog/2010/09/20/log-groovys-new-and-extensible-logging-conveniences/
  • 41.
    foo.groovy: String a=”ABC” def bar() { println a } bar() // => a class foo extends Script { void run() { String a = ”ABC” bar() } def bar() { println a } } Slide # 31 JGGUG G*Workshop 17th / 2011.6.17
  • 42.
    foo.groovy: @Field String a=”ABC” def bar() { println a } bar() ==> “ABC” class foo extends Script { String a = ”ABC” void run() { bar() } def bar() { println a } } Slide # 32 JGGUG G*Workshop 17th / 2011.6.17
  • 43.
    Slide # 33 JGGUG G*Workshop 17th / 2011.6.17
  • 44.
    Groovy 1.8.0 (curry) Slide # 34 JGGUG G*Workshop 17th / 2011.6.17
  • 45.
    @ConditionalInterrupt({ counter >100 }) class Foo {   int counter = 0   void run() {     while (true) {       counter++ // 100     } // InterruptedException   } } Slide # 35 JGGUG G*Workshop 17th / 2011.6.17
  • 46.
    // fib1 = { n ->   n <= 1 ? n : fib1(n - 1) + fib1(n - 2) } // fib2 = { n ->   n <= 1 ? n : fib2(n - 1) + fib2(n - 2) }.memoize() Slide # 36 JGGUG G*Workshop 17th / 2011.6.17
  • 47.
    … … Slide # 37 JGGUG G*Workshop 17th / 2011.6.17
  • 48.
    Slide # 38 JGGUG G*Workshop 17th / 2011.6.17
  • 49.
    Groovy 1.8.0 GDK Groovy API GPars GSql JSon Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 50.
    Slide # 40 JGGUG G*Workshop 17th / 2011.6.17
  • 51.
    ! Slide # 40 JGGUG G*Workshop 17th / 2011.6.17
  • 52.
    Java JSON ‘’’ {"name": "John HashMap Smith", "age": 33} ‘’’ JsonSlurper #parseText( ) ‘’’ ArrayList ["milk", "bread", "eggs"] ‘’’ 41 Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 53.
    JSON bldr = new JsonBuilder() bldr { num 1 ‘boolean’ true arr([1,2,3]) JSonBuilde } r JSON toString() ”””{"num": 42 1,"boolean":true," arr":[1,2,3]}””” Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 54.
    Java bldr=new JsonBuilder() bldr([ num:1, HashMap ’boolean’:true, arr: JSonBuilde [1,2,3] ]) r JSON toString() “””{"num": 43 1,"boolean":true," arr":[1,2,3]}””” Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 55.
    JSON { "num": 1, JSonBuilde toPrettyString() "’boolean’": true, r "arr": [ 1, 2, 3 ] 44 } Slide # JGGUG G*Workshop 17th / 2011.6.17
  • 56.
    Groovy 1.8.0 Slide #45 JGGUG G*Workshop 17th / 2011.6.17
  • 57.
    public class FibBench{   static int fib(int n) {     return n <= 1 ? n : fib(n - 1) + fib(n - 2);   } } (ms) Java 1 Groovy 1.8.0 2664 2.9 Groovy 1.7.10 26702 28.6 Groovy++ 0.4.230_1.8.0 1067 1.14 Java SE 1.6.0_22 933 1.0 Slide # 46 JGGUG G*Workshop 17th / 2011.6.17
  • 58.
    ( 10 !) 1.8.0 int Groovy++ Groovy++ (Java !) Groovy 1.8 Slide # 47 JGGUG G*Workshop 17th / 2011.6.17
  • 59.
    Groovy 1.8.0 jar Grab GroovyDoc Slide # 48 JGGUG G*Workshop 17th / 2011.6.17
  • 60.
    $ java -jar/tool/groovy-1.8.0/target/ install/embeddable/groovy-all-1.8.0.jar fib.groovy time=2542 time=34 Slide # 49 JGGUG G*Workshop 17th / 2011.6.17
  • 61.
    Slide # 50 JGGUG G*Workshop 17th / 2011.6.17
  • 62.
    Slide # 51 JGGUG G*Workshop 17th / 2011.6.17
  • 63.
    Slide # 52 JGGUG G*Workshop 17th / 2011.6.17

Editor's Notes

  • #2 \n
  • #3 \n
  • #4 \n
  • #5 \n
  • #6 \n
  • #7 \n
  • #8 \n
  • #9 \n
  • #10 &amp;#x6B63;&amp;#x76F4;&amp;#x3001;Groovy&amp;#x304B;&amp;#x3089;&amp;#x66F8;&amp;#x304D;&amp;#x306A;&amp;#x304A;&amp;#x3059;&amp;#x306E;&amp;#x306F;&amp;#x3001;&amp;#x305F;&amp;#x3044;&amp;#x3078;&amp;#x3093;&amp;#x3067;&amp;#x3057;&amp;#x305F;&amp;#x3002;\n
  • #11 \n
  • #12 &amp;#x300C;&amp;#x4F55;&amp;#x3092;&amp;#x51E6;&amp;#x7406;&amp;#x3059;&amp;#x308B;&amp;#x304B;&amp;#x300D;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x6700;&amp;#x4F4E;&amp;#x9650;&amp;#x306E;&amp;#x6307;&amp;#x793A;&amp;#x306F;&amp;#x4E0A;&amp;#x3067;&amp;#x5341;&amp;#x5206;&amp;#x3001;\n&amp;#x4ED6;&amp;#x306F;&amp;#x30E1;&amp;#x30BF;&amp;#x60C5;&amp;#x5831;&amp;#x3002;\n
  • #13 &amp;#x5404;&amp;#x884C;&amp;#x3092;&amp;#x89E3;&amp;#x8AAC;&amp;#x3057;&amp;#x3066;&amp;#x3044;&amp;#x304D;&amp;#x307E;&amp;#x3059;&amp;#x3002;&amp;#x3059;&amp;#x3093;&amp;#x306A;&amp;#x308A;&amp;#x3068;&amp;#x8AAD;&amp;#x3081;&amp;#x3070;&amp;#x30B3;&amp;#x30FC;&amp;#x30C9;&amp;#x306E;&amp;#x610F;&amp;#x5473;&amp;#x306B;&amp;#x5BFE;&amp;#x5FDC;&amp;#x3059;&amp;#x308B;&amp;#x3002;\n
  • #14 &amp;#x5404;&amp;#x884C;&amp;#x3092;&amp;#x89E3;&amp;#x8AAC;&amp;#x3057;&amp;#x3066;&amp;#x3044;&amp;#x304D;&amp;#x307E;&amp;#x3059;&amp;#x3002;&amp;#x3059;&amp;#x3093;&amp;#x306A;&amp;#x308A;&amp;#x3068;&amp;#x8AAD;&amp;#x3081;&amp;#x3070;&amp;#x30B3;&amp;#x30FC;&amp;#x30C9;&amp;#x306E;&amp;#x610F;&amp;#x5473;&amp;#x306B;&amp;#x5BFE;&amp;#x5FDC;&amp;#x3059;&amp;#x308B;&amp;#x3002;\n
  • #15 \n
  • #16 \n
  • #17 \n
  • #18 \n
  • #19 \n
  • #20 \n
  • #21 \n
  • #22 \n
  • #23 \n
  • #24 \n
  • #25 \n
  • #26 \n
  • #27 \n
  • #28 \n
  • #29 \n
  • #30 \n
  • #31 \n
  • #32 \n
  • #33 \n
  • #34 \n
  • #35 \n
  • #36 \n
  • #37 \n
  • #38 \n
  • #39 \n
  • #40 \n
  • #41 \n
  • #42 \n
  • #43 \n
  • #44 \n
  • #45 \n
  • #46 \n
  • #47 XmlSlurper,Perser&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;DOM&amp;#x3068;&amp;#x304B;&amp;#x51FA;&amp;#x3066;&amp;#x3053;&amp;#x306A;&amp;#x3044;&amp;#x3002;\n
  • #48 \n
  • #49 \n
  • #50 \n
  • #51 \n
  • #52 \n
  • #53 \n
  • #54 \n
  • #55 \n
  • #56 \n
  • #57 \n
  • #58 \n