Markup Template Engine is a new feature of Groovy, that is a kind of Embedded DSL which is implemented using Groovy 2.x features like:
- Custom Type Checker(Type Check Extension)
- Compiler Configuration
You can generate HTML/XML using full brown programming language features:
- modularity
- abstraction
- type system
- flow structure
- variable, OOP, etc, etc..
Slides for JJUG(Japan Java User Group) 2009 Fall BOF.
Talking about groovy history, new features in Groovy 1.6,1.7.
Especially focused on AST Transformations.
LispBuilder is lisp interpreter and parser implemented as Groovy’s Builder. LispBuilder accepts Lisp like expression, and can be evaluated on groovy.
http://wiki.github.com/uehaj/LispBuilder
8. Slide # 渋谷JVM Copyright(C) 2015 NTT Software Corporation All rights reserved.
最近の話題
Pivotal社がスポンサーを降板(∼2015/3末)
Groovy/Grailsコア開発メンバーの直接雇用終了
codehaus閉鎖もあり、GroovyはASF傘下の
インキュベータープロジェクトに
8
9. Slide # 渋谷JVM Copyright(C) 2015 NTT Software Corporation All rights reserved.
こんな感じのやりとり(想像です)
9
ぼくと契約して、ASF
プロジェクトになって
よ!
きゅうべえ、いや
(Apache)インキュベー
ター!!!
10. Slide # 渋谷JVM Copyright(C) 2015 NTT Software Corporation All rights reserved.
Java7コード例(WordCount)
10
import
java.util.Comparator;
import
java.util.HashMap;
import
java.util.Map;
import
java.util.Set;
import
java.util.List;
import
java.util.ArrayList;
import
java.util.Collections;
import
java.io.FileReader;
import
java.io.BufferedReader;
import
java.io.IOException;
public
class
WordCount7
{
public
static
void
main(String[]
args)
throws
IOException
{
try
(FileReader
fis
=
new
FileReader(args[0]);
BufferedReader
br
=
new
BufferedReader(fis))
{
Map<String,
Integer>
map
=
new
HashMap<>();
String
line;
while
((line
=
br.readLine())
!=
null)
{
for
(String
it:
line.split("W+"))
{
map.put(it,
(map.get(it)==null)
?
1
:
(map.get(it)
+
1));
}
}
List<Map.Entry<String,
Integer>>
entrySetList
=
new
ArrayList<>(map.entrySet());
Comparator<Map.Entry<String,
Integer>>
comp
=
new
Comparator<Map.Entry<String,
Integer>>(){
public
int
compare(Map.Entry<String,
Integer>
o1,
Map.Entry<String,
Integer>
o2)
{
return
o1.getValue()
-‐
o2.getValue();
}
};
Collections.sort(entrySetList,
comp);
for
(Map.Entry<String,
Integer>
entry:
entrySetList)
{
System.out.println(entry.getValue()
+
":"+entry.getKey());
}
}
}
}
System.out.println(entry.getValue()
+
":"+entry.getKey());
}
}
}
}
def
words
=
new
File(args[0]).text.split(/W+/)
words.countBy{it}.entrySet().sort{it.value}.each
{
println
"${it.value}:
${it.key}"
}
Groovyコード例(WordCount)
11. Slide # 渋谷JVM Copyright(C) 2015 NTT Software Corporation All rights reserved.
Java7コード例(Immutable)
11
public
final
class
Punter
{
private
final
String
first;
private
final
String
last;
public
Punter(String
first,
String
last)
{
this.first
=
first;
this.last
=
last;
}
public
String
getFirst()
{
return
first;
}
public
String
getLast()
{
return
last;
}
@Override
public
int
hashCode()
{
final
int
prime
=
31;
int
result
=
1;
result
=
prime
*
result
+
((first
==
null)
?
0
:
first.hashCode());
result
=
prime
*
result
+
((last
==
null)
?
0
:
last.hashCode());
return
result;
}
@Override
public
boolean
equals(Object
obj)
{
if
(this
==
obj)
return
true;
if
(obj
==
null)
return
false;
if
(getClass()
!=
obj.getClass())
return
false;
Punter
other
=
(Punter)
obj;
if
(first
==
null)
{
if
(other.first
!=
null)
return
false;
}
else
if
(!first.equals(other.first))
return
false;
if
(last
==
null)
{
if
(other.last
!=
null)
return
false;
}
else
if
(!last.equals(other.last))
return
false;
return
true;
}
@Override
public
String
toString()
{
return
"Punter(first:"
+
first
+
",
last:"
+
last
+
")";
}
}
@Immutable
final
class
Punter
{
String
first,
last
}
Groovyコード例(Immutable)