Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ch2

  • Loading branch information...
commit 93bea6c61db3b3d1e90221d4cdc68bf04d4281c9 1 parent 1ce396c
@demian0311 authored
View
10 groovy_in_action/chapter2/Book.groovy
@@ -0,0 +1,10 @@
+class Book{
+ private String title
+ Book(String theTitle){
+ title = theTitle
+ }
+
+ String getTitle(){
+ return title
+ }
+}
View
35 groovy_in_action/chapter2/chapter2.groovy
@@ -0,0 +1,35 @@
+#!/usr/bin/env groovy
+
+// Page37: Assertions
+assert(true)
+assert 1 == 1 // equality, not identity
+def x = 1
+assert x == 1
+
+def y = 1; assert y == 1
+
+// Page43: Annotations for AST Transformations
+@Immutable class FixedBook {
+ String title
+}
+
+def gina = new FixedBook('Groovy in Action')
+def regina = new FixedBook(title: 'Groovy in Action')
+
+assert gina.title == 'Groovy in Action'
+assert gina == regina
+
+try {
+ gina.title = "Ooop!"
+ assert false, "should not reach here"
+} catch(ReadOnlyPropertyException e){
+ println("yep, threw the exception")
+}
+
+// Page45: Regular Expressions
+// / the string you are searching
+// / find operator
+// // the regular expression
+assert '12345' =~ /\d+/
+// FAILS: assert 'ABCDE' =~ /\d+/
+
View
12 groovy_in_action/customers.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<customers>
+ <corporate>
+ <customer name="Bill Gates" company="Microsoft" />
+ <customer name="Steve Jobs" company="Apple" />
+ <customer name="Jonathan Schwartz" company="Sun" />
+ </corporate>
+<consumer>
+ <customer name="John Doe" />
+ <customer name="Jane Doe" />
+</consumer>
+</customers>

0 comments on commit 93bea6c

Please sign in to comment.
Something went wrong with that request. Please try again.