This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 0004947 tweaks for Groovy 4 release
0004947 is described below
commit 000494746f4bd10f89fb7e2ce0a5720a5d7c4f37
Author: Paul King <[email protected]>
AuthorDate: Sun Jan 30 17:30:28 2022 +1000
tweaks for Groovy 4 release
---
site/src/site/releasenotes/groovy-4.0.adoc | 56 ++++++++++++++++++++++++++++--
site/src/site/sitemap-user.groovy | 4 ++-
2 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/site/src/site/releasenotes/groovy-4.0.adoc
b/site/src/site/releasenotes/groovy-4.0.adoc
index 5230a06..2e91a95 100644
--- a/site/src/site/releasenotes/groovy-4.0.adoc
+++ b/site/src/site/releasenotes/groovy-4.0.adoc
@@ -787,8 +787,58 @@ innerjoin n2 in nums2 on n1 == n2
select n1 + 1, n2
--------------------------------------
-More examples could be found at
-link:https://github.com/apache/groovy/blob/master/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy[GINQ
examples]
+Let's look at a complete example. Suppose we have information
+in JSON format about fruits, their prices (per 100g) and
+the concentration of vitamin C (per 100g).
+We can process the JSON as follows:
+
+[source,groovy]
+--------------------------------------
+import groovy.json.JsonSlurper
+def json = new JsonSlurper().parseText('''
+{
+ "prices": [
+ {"name": "Kakuda plum", "price": 13},
+ {"name": "Camu camu", "price": 25},
+ {"name": "Acerola cherries", "price": 39},
+ {"name": "Guava", "price": 2.5},
+ {"name": "Kiwifruit", "price": 0.4},
+ {"name": "Orange", "price": 0.4}
+ ],
+ "vitC": [
+ {"name": "Kakuda plum", "conc": 5300},
+ {"name": "Camu camu", "conc": 2800},
+ {"name": "Acerola cherries", "conc": 1677},
+ {"name": "Guava", "conc": 228},
+ {"name": "Kiwifruit", "conc": 144},
+ {"name": "Orange", "conc": 53}
+ ]
+}
+''')
+--------------------------------------
+
+Now, suppose we are on a budget and want to select
+the most cost-effective fruits to buy to help us achieve
+our daily vitamin C requirements.
+We _join_ the _prices_ and _vitC_ information and
+order by most cost-effective fruit.
+We'll select the top 2 in case our first choice isn't in stock
+when we go shopping. We can see, for this data,
+Kakadu plums followed by Kiwifruit are our best choices:
+
+[source,groovy]
+--------------------------------------
+assert GQ {
+ from p in json.prices
+ join c in json.vitC on c.name == p.name
+ orderby c.conc / p.price in desc
+ limit 2
+ select p.name
+}.toList() == ['Kakuda plum', 'Kiwifruit']
+--------------------------------------
+
+More examples could be found in the link:../using-ginq.html[groovy-ginq
documentation] (or directly in
+link:https://github.com/apache/groovy/blob/master/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy[the
source repo]).
=== TOML Support (incubating)
@@ -828,6 +878,8 @@ assert 'speed' == toml.records.car.record.type
assert 'production pickup truck with speed of 271kph' ==
toml.records.car.record.description
--------------------------------------
+More examples could be found in the link:../processing-toml.html[groovy-toml]
documentation.
+
[[Groovy4.0-other]]
== Other improvements
diff --git a/site/src/site/sitemap-user.groovy
b/site/src/site/sitemap-user.groovy
index 2834c77..851d437 100644
--- a/site/src/site/sitemap-user.groovy
+++ b/site/src/site/sitemap-user.groovy
@@ -126,10 +126,12 @@ documentation {
}
section('Groovy module guides', 'fa-cubes') {
- item 'Parsing and producing JSON', 'json',
'json-userguide'
+ item 'Parsing and producing JSON', 'processing-json',
'json-userguide'
item 'Working with a relational database', 'databases',
'sql-userguide'
item 'Processing XML', 'processing-xml',
'xml-userguide'
item 'Processing YAML', 'processing-yaml',
'yaml-userguide'
+ item 'Processing TOML', 'processing-toml',
'toml-userguide'
+ item 'SQL-like querying of collections', 'using-ginq',
'ginq-userguide'
item 'Scripting Ant tasks', 'scripting-ant',
'ant-builder'
item 'Template engines', 'templating',
'template-engines'
item 'Creating Swing UIs', 'swing',
'swing-builder'