Skip to content

Commit a4b7263

Browse files
committed
Add chapter 3.
1 parent 66cbd9c commit a4b7263

5 files changed

+1664
-38
lines changed

ch1-getting-started.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<meta charset="utf-8">
55
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="generator" content="Asciidoctor 1.5.0">
7+
<meta name="generator" content="Asciidoctor 1.5.2">
88
<title>First steps</title>
9-
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic|Noto+Serif:400,400italic,700,700italic|Droid+Sans+Mono:400">
9+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400">
1010
<style>
1111
/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
1212
/* Remove the comments around the @import statement below when using this as a custom stylesheet */
13-
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic|Noto+Serif:400,400italic,700,700italic|Droid+Sans+Mono:400";*/
13+
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400";*/
1414
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
1515
audio,canvas,video{display:inline-block}
1616
audio:not([controls]){display:none;height:0}
@@ -274,8 +274,8 @@
274274
ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
275275
ul.unstyled,ol.unnumbered,ul.checklist,ul.none{list-style-type:none}
276276
ul.unstyled,ol.unnumbered,ul.checklist{margin-left:.625em}
277-
ul.checklist li>p:first-child>.fa-check-square-o:first-child,ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em}
278-
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{position:relative;top:1px}
277+
ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1em;font-size:.85em}
278+
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{width:1em;position:relative;top:1px}
279279
ul.inline{margin:0 auto .625em auto;margin-left:-1.375em;margin-right:0;padding:0;list-style:none;overflow:hidden}
280280
ul.inline>li{list-style:none;float:left;margin-left:1.375em;display:block}
281281
ul.inline>li>*{display:block}
@@ -380,7 +380,7 @@
380380
*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
381381
a{color:inherit!important;text-decoration:underline!important}
382382
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
383-
a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after,a[href^="mailto:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
383+
a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
384384
abbr[title]:after{content:" (" attr(title) ")"}
385385
pre,blockquote,tr,img{page-break-inside:avoid}
386386
thead{display:table-header-group}
@@ -754,7 +754,7 @@ <h2 id="_groovy_as_a_calculator">Groovy as a calculator</h2>
754754
</div>
755755
</div>
756756
<div class="paragraph">
757-
<p>This little example introduces some new concepts and syntax. First, it declares and uses a few local variables using the keyword <code>def</code>. Variables declared in this way can contain values of any type, not just numbers. In other wirds, the variables are untyped.</p>
757+
<p>This little example introduces some new concepts and syntax. First, it declares and uses a few local variables using the keyword <code>def</code>. Variables declared in this way can contain values of any type, not just numbers. In other words, the variables are untyped.</p>
758758
</div>
759759
<div class="paragraph">
760760
<p>The second item of interest is the <code>sqrt()</code> method call. The syntax is absolutely identical to Java&#8217;s and in this case you&#8217;re seeing a <em>static</em> method. This is called on the class itself (<code>lava.lang.Math</code>) rather than on an instance of that class.</p>
@@ -867,7 +867,7 @@ <h2 id="_groovy_as_a_calculator">Groovy as a calculator</h2>
867867
<p>Another interesting facet of the language is that you&#8217;re seeing runtime errors for unknown methods and properties. This is because Groovy resolves properties and methods at runtime by default rather than at compile time. This can be changed, as you&#8217;ll see in chapter TODO. You can also make use of this runtime resolution to do interesting things such as creating builders (chapter TODO) or mock objects (chapter TODO).</p>
868868
</div>
869869
<div class="paragraph">
870-
<p>Let&#8217;s return to the world of numbers and look at some more examples. In the following script, I perform a floatingpoint multiplication repeatedly and time how long it takes:</p>
870+
<p>Let&#8217;s return to the world of numbers and look at some more examples. In the following script, I perform a floating-point multiplication repeatedly and time how long it takes:</p>
871871
</div>
872872
<div class="listingblock">
873873
<div class="content">
@@ -1001,7 +1001,7 @@ <h2 id="_groovy_as_a_calculator">Groovy as a calculator</h2>
10011001
</div>
10021002
</div>
10031003
<div class="paragraph">
1004-
<p>Were you expecting a negative number? Whether you were or not, it&#8217;s certainly not correct. The reason for this is that <code>int</code> and <code>Integer</code> can only store integers up to a size of 2<sup>31</sup>. If your value goes beyond that, then you end up with something called <em>integer overflow</em>.</p>
1004+
<p>Were you expecting a negative number? Whether you were or not, that&#8217;s what happens and it&#8217;s certainly not correct. The reason for this is that <code>int</code> and <code>Integer</code> can only store integers up to a size of 2<sup>31</sup>. If your value goes beyond that, then you end up with something called <em>integer overflow</em>.</p>
10051005
</div>
10061006
<div class="paragraph">
10071007
<p>You can force Groovy to use a wider integer type by changing the specified type. Long integers are 64 bit, so that will allow us to calculate larger factorials:</p>
@@ -1034,7 +1034,7 @@ <h2 id="_groovy_as_a_calculator">Groovy as a calculator</h2>
10341034
</div>
10351035
<div id="footer">
10361036
<div id="footer-text">
1037-
Last updated 2015-02-03 09:00:29 GMT
1037+
Last updated 2015-05-26 16:49:04 BST
10381038
</div>
10391039
</div>
10401040
</body>

ch2-types.html

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<meta charset="utf-8">
55
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="generator" content="Asciidoctor 1.5.0">
7+
<meta name="generator" content="Asciidoctor 1.5.2">
88
<title>Working with types</title>
9-
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic|Noto+Serif:400,400italic,700,700italic|Droid+Sans+Mono:400">
9+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400">
1010
<style>
1111
/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
1212
/* Remove the comments around the @import statement below when using this as a custom stylesheet */
13-
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic|Noto+Serif:400,400italic,700,700italic|Droid+Sans+Mono:400";*/
13+
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400";*/
1414
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
1515
audio,canvas,video{display:inline-block}
1616
audio:not([controls]){display:none;height:0}
@@ -274,8 +274,8 @@
274274
ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
275275
ul.unstyled,ol.unnumbered,ul.checklist,ul.none{list-style-type:none}
276276
ul.unstyled,ol.unnumbered,ul.checklist{margin-left:.625em}
277-
ul.checklist li>p:first-child>.fa-check-square-o:first-child,ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em}
278-
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{position:relative;top:1px}
277+
ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1em;font-size:.85em}
278+
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{width:1em;position:relative;top:1px}
279279
ul.inline{margin:0 auto .625em auto;margin-left:-1.375em;margin-right:0;padding:0;list-style:none;overflow:hidden}
280280
ul.inline>li{list-style:none;float:left;margin-left:1.375em;display:block}
281281
ul.inline>li>*{display:block}
@@ -380,7 +380,7 @@
380380
*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
381381
a{color:inherit!important;text-decoration:underline!important}
382382
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
383-
a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after,a[href^="mailto:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
383+
a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
384384
abbr[title]:after{content:" (" attr(title) ")"}
385385
pre,blockquote,tr,img{page-break-inside:avoid}
386386
thead{display:table-header-group}
@@ -993,11 +993,11 @@ <h2 id="_collections_ranges_and_maps">Collections, ranges and maps</h2>
993993
<div class="paragraph">
994994
<p>We&#8217;ll start with ordered collections, which are represented by the <a href="https://docs.oracle.com/javase/8/docs/api/?java/util/List.html"><code>java.util.List</code></a> interface. In the following example, I create a list of words (strings) and then proceed to iterate over them to calculate the shortest, longest and average word lengths. Before you critize the implementation (there are better ways to do this), remember that I&#8217;m trying to introduce new concepts and APIs gradually!</p>
995995
</div>
996-
<div class="listingblock">
996+
<div id="wordStats" class="listingblock">
997997
<div class="content">
998-
<pre class="CodeRay highlight"><code>def words = ["orange", "sit", "test", "flabbergasted", "honorific"] <b class="conum">(1)</b>
998+
<pre class="CodeRay highlight"><code>final words = ["orange", "sit", "test", "flabbergasted", "honorific"] <b class="conum">(1)</b>
999999

1000-
def minWordLength = Integer.MAX_VALUE <b class="conum">(2)</b>
1000+
def minWordLength = Integer.MAX_VALUE <b class="conum">(2)</b>
10011001
def maxWordLength = 0
10021002
def totalLength = 0
10031003
for (w in words) {
@@ -1008,7 +1008,7 @@ <h2 id="_collections_ranges_and_maps">Collections, ranges and maps</h2>
10081008

10091009
println "Min word length: ${minWordLength}"
10101010
println "Max word length: ${maxWordLength}"
1011-
println "Avg word length: ${totalLength / words.size()}" <b class="conum">(3)</b></code></pre>
1011+
println "Avg word length: ${totalLength / words.size()}" <b class="conum">(3)</b></code></pre>
10121012
</div>
10131013
</div>
10141014
<div class="colist arabic">
@@ -1055,7 +1055,7 @@ <h2 id="_collections_ranges_and_maps">Collections, ranges and maps</h2>
10551055
<div class="paragraph">
10561056
<p>Sometimes a list literal isn&#8217;t sufficient and you need to build one dynamically. Consider a method that creates a list of the powers of two, i.e. <em>f(x) = 2<sup>x</sup></em>:</p>
10571057
</div>
1058-
<div class="listingblock">
1058+
<div id="powersOfTwo" class="listingblock">
10591059
<div class="content">
10601060
<pre class="CodeRay highlight"><code>List powersOfTwo(int n) {
10611061
def result = []
@@ -1738,7 +1738,7 @@ <h2 id="_chapter_example">Chapter example</h2>
17381738
</div>
17391739
<div id="footer">
17401740
<div id="footer-text">
1741-
Last updated 2015-04-01 11:58:36 BST
1741+
Last updated 2015-05-26 16:49:04 BST
17421742
</div>
17431743
</div>
17441744
</body>

0 commit comments

Comments
 (0)