<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>All things Grails and RIA</title>
	<atom:link href="http://gr8fanboy.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gr8fanboy.wordpress.com</link>
	<description>Sharing what I&#039;ve learnt...</description>
	<lastBuildDate>Sun, 02 Jan 2011 14:14:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gr8fanboy.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/359417ef67beefd1f3d99cb893a2daa4?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>All things Grails and RIA</title>
		<link>http://gr8fanboy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gr8fanboy.wordpress.com/osd.xml" title="All things Grails and RIA" />
	<atom:link rel='hub' href='http://gr8fanboy.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Improving Grails/Flex integration.</title>
		<link>http://gr8fanboy.wordpress.com/2010/12/20/improving-grailsflex-integration/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/12/20/improving-grailsflex-integration/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 18:48:45 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Cairngorm3]]></category>
		<category><![CDATA[Parsley]]></category>
		<category><![CDATA[Pimento]]></category>
		<category><![CDATA[Presenter Model]]></category>
		<category><![CDATA[Project Sponsor]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1181</guid>
		<description><![CDATA[If you have a shared interest in Grails and Flex and would like to see better integration of these technologies and better templating/automation of code and would be interested in sponsoring such a project, please get in touch. Filed under: Flex, Grails Tagged: Cairngorm3, Flex, Grails, Parsley, Pimento, Presenter Model, Project Sponsor, TDD<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1181&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have a shared interest in Grails and Flex and would like to see better integration of these technologies and better templating/automation of code and would be interested in sponsoring such a project, please get in touch.</p>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/ajax/flex-ajax-2/'>Flex</a>, <a href='http://gr8fanboy.wordpress.com/category/grails/'>Grails</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/cairngorm3/'>Cairngorm3</a>, <a href='http://gr8fanboy.wordpress.com/tag/flex/'>Flex</a>, <a href='http://gr8fanboy.wordpress.com/tag/grails/'>Grails</a>, <a href='http://gr8fanboy.wordpress.com/tag/parsley/'>Parsley</a>, <a href='http://gr8fanboy.wordpress.com/tag/pimento/'>Pimento</a>, <a href='http://gr8fanboy.wordpress.com/tag/presenter-model/'>Presenter Model</a>, <a href='http://gr8fanboy.wordpress.com/tag/project-sponsor/'>Project Sponsor</a>, <a href='http://gr8fanboy.wordpress.com/tag/tdd/'>TDD</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1181&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/12/20/improving-grailsflex-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>A first take on Spicefactory projects Pimento and Parsley</title>
		<link>http://gr8fanboy.wordpress.com/2010/10/07/a-first-take-on-spicefactory-projects-pimento-and-parsley/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/10/07/a-first-take-on-spicefactory-projects-pimento-and-parsley/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 11:06:24 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[GORM]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Cinammon]]></category>
		<category><![CDATA[DBUnit]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[DI]]></category>
		<category><![CDATA[Fluint]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSR303]]></category>
		<category><![CDATA[lazy-loading]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Parsley]]></category>
		<category><![CDATA[Pimento]]></category>
		<category><![CDATA[Spicefactory]]></category>
		<category><![CDATA[Spicelib]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1146</guid>
		<description><![CDATA[I&#8217;ve been meaning to take a look at the projects from the Spicefactory guys for quite a while after hearing Borre Wessel give a talk at Skills Matter a year or so ago about the Matrix project he&#8217;d worked on. I&#8217;d been putting this off for couple of reasons really: I&#8217;d got to grips with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1146&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to take a look at the projects from the <a href="http://www.spicefactory.org/" target="_blank">Spicefactory</a> guys for quite a while after hearing <a href="http://www.borrewessel.com/" target="_blank">Borre Wessel</a> give a <a href="http://skillsmatter.com/podcast/ajax-ria/matrix" target="_blank">talk at Skills Matter</a> a year or so ago about the <a href="http://www.morganstanley.com/matrixinfo/" target="_blank">Matrix project</a> he&#8217;d worked on.</p>
<p>I&#8217;d been putting this off for couple of reasons really:</p>
<ol>
<li> I&#8217;d got to grips with the likes of Cairngorm/PureMVC by reading Chris Giametta&#8217;s APress <a href="http://apress.com/book/view/9781430218357" target="_blank">Pro Flex on Spring</a> book. But it didn&#8217;t quite give me a good enough understanding how some of the XML configuration would work for a basic Java project using BlazeDS &#8211; which I finally mastered this past week or so after reading Filippo di Pisa&#8217;s APress <a href="http://apress.com/book/view/1430223855" target="_blank">Beginning Java and Flex</a> book. I figured it would be prudent to have a good understanding of the basics before moving on to Spicefactory&#8217;s wares.<br />
See my Amazon reviews here:&nbsp;</p>
<ul>
<li><a href="http://www.amazon.co.uk/review/R1CNX8VCPZEFAV/ref=cm_cr_pr_perm?ie=UTF8&amp;ASIN=1430218355&amp;nodeID=&amp;tag=&amp;linkCode=" target="_blank">Pro Flex on Spring</a></li>
<li><a href="http://www.amazon.co.uk/review/RFMBP3OHFGP17/ref=cm_cr_pr_perm?ie=UTF8&amp;ASIN=1430223855&amp;nodeID=&amp;tag=&amp;linkCode=" target="_blank">Beginning Java and Flex</a></li>
</ul>
</li>
<li>The fact you can&#8217;t print the documentation off, and you have to sift through a tons of it whilst glued to the web browser which took me the best part of a couple of days solid reading.<br />
I much prefer to print stuff off and pencil notes against a hard copy&#8230;</li>
</ol>
<p>In summary Spicefactory has four projects:</p>
<h1>Spicelib</h1>
<p>This is a foundational project for Parsley that provides:</p>
<ul>
<li>enhanced Flex reflection capabilities</li>
<li>a bi-directional XML to AS3 object class mapper.(I wasn&#8217;t sure if there was a pluggable implementation here and how scalable it was. I.e. a event driven streaming affair a la SAX or a load the whole thing into memory).<br />
It didn&#8217;t grab me as having the same elegance you find with Groovy XML builders. (<a href="http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlParser" target="_blank">XMLParser</a>/<a href="http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper" target="_blank">XMLSlurper</a>). (Scott Davis&#8217;s <a href="http://www.amazon.co.uk/review/R11EOTX4UF2XEL/ref=cm_cr_pr_perm?ie=UTF8&amp;ASIN=0978739299&amp;nodeID=&amp;tag=&amp;linkCode=" target="_blank">Groovy Recipes</a> book rocks on this subject).</li>
<li>An expressions parser a la JSP EL/Velocity/Freemarker/Groovy GStrings etc. (which seemed to have a missing swc in download)</li>
<li>Logging capabilities (a la Commons logging for AS3)</li>
<li>A task framework. I really though this was a great idea, enabling you to abstract away fine grained events into a a higher level unit of work.</li>
</ul>
<h1>Parsley</h1>
<p>A Flex DI framework. It sounds similar to <a href="http://www.robotlegs.org/" target="_blank">RobotLegs</a>, but my take it&#8217;s a bit more extensible and consequently a bit more of a learning curve. (Think Spring/Google Guice for the Flex world). The framework makes extensive use of metatags that works in either a Flash or Flex world. (Things like [Inject]) &#8211; similar to annotations in the Java world.<br />
There&#8217;s a few strokes of genius in that the project, although I was a bit surprised none of the examples made use of the newer Vector class and still used Arrays:</p>
<ul>
<li>It uses a DSL builder, somewhat reminiscent of jQuery, so that configuration/wiring of components can be done with XML, AS3 or MXML that builds upon the DSL under the covers.</li>
<li>The messaging infrastructure does away with the nasty constants and lots if type casting you see in the likes of Cairngorm and instead uses metatags for the publication/subscription process for events which is very clean. You can also scope the level at which you listen for events which is useful when dealing with nested visual components (Think filtered bubbling).</li>
</ul>
<p>If you want to see a sample project, Christophe Coenraet has a handy blog post <a href="http://coenraets.org/blog/2009/07/building-a-flex-application-with-the-parsley-framework/" target="_blank">here</a>.<br />
Unfortunately, he didn&#8217;t go the extra mile and demonstrate integration with Pimento too.<br />
Watch this space. I&#8217;m going to have a crack at modifying the project to do just that.</p>
<h1>Cinammon Remoting</h1>
<p>Jens Halm points out that the regular RemoteObject MXML tag is not type safe and you normally have to write a business delegate wrapper. Consequently in essence, this is the nut this project cracks.</p>
<h1>Pimento</h1>
<p>There&#8217;s some definite pluses to this project, but it has some peculiarities to it as well.<br />
In essence it provides JPA/Hibernate/Flex/Spring integration and solves a lot of the complex issues with like lazy loading. It does this by embellishing the Java domain classes with annotations and effectively provides client-side caching. You can tweak the properties that get sent across the wire via <a href="http://en.wikipedia.org/wiki/Action_Message_Format" target="_blank">AMF</a> too, by doing things like making things read-only on the AS3 side, or using a @Hidden annotation.<br />
It did seem awkward however to use interceptors to provide constrain functionality (See section 2.6 of documentation). I&#8217;d much prefer to have seen something along the lines of utilising annotations (as you see in the <a href="http://jcp.org/en/jsr/detail?id=303" target="_blank">JSR303</a> Bean Validation framework/<a href="http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/" target="_blank">Hibernate Validator</a>) (see <a href="http://www.manning.com/wheeler/" target="_blank">Willie Wheeler&#8217;s</a> blog <a href="http://wheelersoftware.com/articles/spring-bean-validation-framework.html" target="_blank">post</a> for an example). Or even better from my perspective integration with <a href="http://www.grails.org/GORM" target="_blank">GORM</a>.<br />
It would be good if the project could create the appropriate MXML components for things like emails, dates etc too from annotations/data types/constraints etc.<br />
If I can get my head around elegantly creating an example that uses Pimento and Parsley, I&#8217;ll have a crack at creating some Grails plug-ins.</p>
<p>Integration testing makes use of <a href="http://www.dbunit.org/" target="_blank">DBUnit server-side</a> and <a href="http://code.google.com/p/fluint/" target="_blank">Fluint</a> client-side (which facilitates asynchronous operations).<br />
I think there are some better options that have surfaced server-side than DBUnit, that I&#8217;ve seen in the Grails community. (but I&#8217;m wracking my memory to remember them as I write this&#8230; Will post back later).</p>
<p>The project bears a slight bit resemblance to Struts 2 in a couple of ways, in that it uses interceptors and Freemarker templates to convert Java domain classes into ActionScript. These get invoked by running Ant tasks. Felippo&#8217;s book also mentioned you can achieve similar results via UML tooling too with the likes of Visual Paradigm. (UML to Java and ActionScript 3).</p>
<p>You can also do things like have a named query in your Hibernate class and call into it from the Actionscript side. (Although I&#8217;m not sure if this is a potential security hole. Can you obfuscate your SWCs to avoid this?)</p>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/ajax/flex-ajax-2/'>Flex</a>, <a href='http://gr8fanboy.wordpress.com/category/orm/gorm/'>GORM</a>, <a href='http://gr8fanboy.wordpress.com/category/orm/hibernate/'>Hibernate</a>, <a href='http://gr8fanboy.wordpress.com/category/orm/'>ORM</a>, <a href='http://gr8fanboy.wordpress.com/category/spring-framework/'>Spring Framework</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/actionscript/'>ActionScript</a>, <a href='http://gr8fanboy.wordpress.com/tag/as3/'>AS3</a>, <a href='http://gr8fanboy.wordpress.com/tag/cinammon/'>Cinammon</a>, <a href='http://gr8fanboy.wordpress.com/tag/dbunit/'>DBUnit</a>, <a href='http://gr8fanboy.wordpress.com/tag/dependency-injection/'>Dependency Injection</a>, <a href='http://gr8fanboy.wordpress.com/tag/di/'>DI</a>, <a href='http://gr8fanboy.wordpress.com/tag/flex/'>Flex</a>, <a href='http://gr8fanboy.wordpress.com/tag/fluint/'>Fluint</a>, <a href='http://gr8fanboy.wordpress.com/tag/hibernate/'>Hibernate</a>, <a href='http://gr8fanboy.wordpress.com/tag/jpa/'>JPA</a>, <a href='http://gr8fanboy.wordpress.com/tag/jsr303/'>JSR303</a>, <a href='http://gr8fanboy.wordpress.com/tag/lazy-loading/'>lazy-loading</a>, <a href='http://gr8fanboy.wordpress.com/tag/matrix/'>Matrix</a>, <a href='http://gr8fanboy.wordpress.com/tag/parsley/'>Parsley</a>, <a href='http://gr8fanboy.wordpress.com/tag/pimento/'>Pimento</a>, <a href='http://gr8fanboy.wordpress.com/tag/spicefactory/'>Spicefactory</a>, <a href='http://gr8fanboy.wordpress.com/tag/spicelib/'>Spicelib</a>, <a href='http://gr8fanboy.wordpress.com/tag/spring/'>Spring</a>, <a href='http://gr8fanboy.wordpress.com/tag/spring-framework/'>Spring Framework</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1146&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/10/07/a-first-take-on-spicefactory-projects-pimento-and-parsley/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Groovy Regex &amp; Lookahead/Lookbehind revisited.</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/14/groovy-regex-lookaheadlookbehind-revisited/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/14/groovy-regex-lookaheadlookbehind-revisited/#comments</comments>
		<pubDate>Fri, 14 May 2010 17:01:56 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1133</guid>
		<description><![CDATA[This is very similar to my earlier post Groovy Regular Expressions to abbreviate compass directions with look ahead and look behind. If I break apart pattern 5 by groups, we have: (?!^) : Lookahead negative start (ie Not at start) (?&#60;!\-)   Lookbehind negative for &#8216;-&#8217; i.e. exclude -### (?=\b) Lookahead positive for word boundary [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1133&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def t = '134 445 887 6667 456-987 fdcf'
def p1 = /(?!^)\d{3}\b/            // No good selects 667
def p2 = /(?!^)\b\d{3}\b/          // Great
def p3 = /((\s)(\d{3})(?=\D))/     // No good omits 987 also 3 groups..
def p4 = /((\s|\-)(\d{3})(?=\D))/  //Good again, but 3 groups, result third (post 4 first is full)
def p5 = /((?!^)(?&lt;!\-)(?=\b)(\d{3})(?!\-)(?=\b))/  // Great if you want to omit ###-### permutation
def m1 = (t =~ p1)
def m2 = (t =~ p2)
def m3 = (t =~ p3)
def m4 = (t =~ p4)
def m5 = (t =~ p5)
assert m1.size() == 5
m1.each{assert it in ['445','887','667','456','987']}
assert m2.size() == 4
m2.each{assert it in ['445','887','456','987']}
assert m3.size() == 3
m3.each{assert it[3] in ['445','887','456']}
assert m4.size() == 4
m4.each{assert it[3] in ['445','887','456','987']}
assert m5.size() == 2
m5.each{assert it[0] in ['445','887']}
</pre></p>
<p>This is very similar to my earlier post<br />
<a href="http://gr8fanboy.wordpress.com/2010/05/11/groovy-regular-expressions-to-abbreviate-compass-directions-with-look-ahead-and-look-behind/" target="_blank">Groovy Regular Expressions to abbreviate compass directions with look ahead and look behind</a>.<br />
If I break apart pattern 5 by groups, we have:</p>
<ul>
<li>(?!^)   : Lookahead  negative start (ie Not at start)</li>
<li>(?&lt;!\-)   Lookbehind negative for &#8216;-&#8217; i.e. exclude -###</li>
<li>(?=\b)    Lookahead  positive for word boundary</li>
<li>(\d{3})   3 digits ###</li>
<li>(?!\-)    Lookahead negative for &#8216;-&#8217; i.e. exclude ###-</li>
<li>(?=\b)    Lookahead  positive for word boundary</li>
</ul>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex/'>RegEx</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1133&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/14/groovy-regex-lookaheadlookbehind-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Using StringBuilder and Regex to do an inline search &amp; replace</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/13/using-stringbuilder-and-regex-to-do-an-inline-search-replace/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/13/using-stringbuilder-and-regex-to-do-an-inline-search-replace/#comments</comments>
		<pubDate>Thu, 13 May 2010 18:58:45 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Inline Search and Replace]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Search and Replace]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1124</guid>
		<description><![CDATA[One of the problems you can face if you try to do string replacements &#8216;inline&#8217; is that as you replace one piece of text with another of a different length is that the matcher gets out of synch as soon as you change the string. I was basically looking for a way to replace area [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1124&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the problems you can face if you try to do string replacements &#8216;inline&#8217; is that as you replace one piece of text with another of a different length is that the matcher gets out of synch as soon as you change the string.</p>
<p>I was basically looking for a way to replace area codes in a string with placeholders.<br />
I adapted this example from <a href="http://www.amazon.co.uk/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/" target="_blank">Jeffrey Friedel&#8217;s Mastering Regular Expressions book</a> (P383).</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def t = new StringBuilder('742 : Reserved as a future area code in the 289/905 region (to be overlain by 365 in 2013). [7]')
def p = /\b\d{3}\b/
def m = java.util.regex.Pattern.compile(p).matcher(t)
//def m = (t =~p)
m.each{println it}
def mp = 0
def i  = 0
while(m.find(mp)) {
 def iSt = i.toString()
 def ms = m.start()
 def me = m.end()
 mp = me
 t.replace(ms, me, iSt)
 def ml = me - ms
 mp = mp - ml + iSt.size()
 i+= 1
}
println t
</pre></p>
<pre>742
289
905
365
0 : Reserved as a future area code in the 1/2 region (to be overlain by 3 in 2013). [7]</pre>
<p>I couldn&#8217;t get the commented out Groovier declaration of m to work correctly, so I resorted to the more Java centric approach in order to  get this working.</p>
<p>I&#8217;m guessing Groovy doesn&#8217;t re-establish the pattern for updated StringBuilder.<br />
This is the result if I flip the commenting of m around (lines 3 &amp; 4)!</p>
<pre>0 : Reserved as a future area code in the 28105 2ion (to be overlain by 365 in313). [7]</pre>
<p>I&#8217;m wondering is this a Groovy bug? Or is there another way of doing the compile in a Groovier way. Comments welcome,</p>
<h3>This also works:</h3>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def t = '123 xxx 444 fgg 654'
def p = ~/\b\d{3}\b/
def m = (t =~ p)
def ms, me, ml, p1, p2, r, d, s, f
d = 0
m.eachWithIndex{it, i -&gt;
  ms = m.start()
  me = m.end()
  ml = me - ms // Match length
  s = ms + d  // Adjusted Start
  f = me + d  // Adjusted End (Finish)
  p1 = (s) ? t[0..s-1] : '' // Part 1
  p2 = (f == t.size()) ? '' : t[f..-1] // Part 2
  r = '\$' + (i+1)  // Placeholder Replacement
  d = d - ml + r.size() // Update cummulative adjustment with diff in length
  t = p1 + r + p2 // recombine t with placeholder
}
println t
</pre></p>
<pre>$1 xxx $2 fgg $3</pre>
<h3>Here are some associated useful links:</h3>
<ul>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html" target="_blank">StringBuilder</a></li>
<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html" target="_blank">Javadoc for java.util.regex package</a></li>
</ul>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/inline-search-and-replace/'>Inline Search and Replace</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex/'>RegEx</a>, <a href='http://gr8fanboy.wordpress.com/tag/search-and-replace/'>Search and Replace</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1124&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/13/using-stringbuilder-and-regex-to-do-an-inline-search-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>How to name getters/setters correctly in Groovy for Camel Case field properties</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/12/how-to-name-getterssetters-correctly-in-groovy-for-camel-case-field-properties/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/12/how-to-name-getterssetters-correctly-in-groovy-for-camel-case-field-properties/#comments</comments>
		<pubDate>Wed, 12 May 2010 09:39:00 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Camel Case confusion]]></category>
		<category><![CDATA[Property naming]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1105</guid>
		<description><![CDATA[I would start out by qualifying this post by saying Groovy normally automatically creates getters/setters for you by default, so you don&#8217;t normally need to do this. It&#8217;s one of the joys of programming in Groovy over Java. But if you want to make individual properties immutable because it&#8217;s the result of say a long [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1105&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I would start out by qualifying this post by saying Groovy normally automatically creates getters/setters for you by default, so you don&#8217;t normally need to do this. It&#8217;s one of the joys of programming in Groovy over Java. But if you want to make individual properties immutable because it&#8217;s the result of say a long calculation and the result gets and stored in a transient say. You&#8217;d want to make the setter body have no content.  and the getter perform the calculation if the transient property is null the first time (ie:lazy loaded properties).<br />
As you know one of the quirks of Groovy, is that you can bypass getters/setters altogether by using the @ field access modifier,  (I like Scott Davis&#8217;s quote from Groovy Recipes here)</p>
<blockquote><p>I&#8217;d rather have a sharper scalpel and a better trained surgeon than a duller blade.</p></blockquote>
<p>But I still think it&#8217;s still a useful exercise create your own getters/setters under such conditions.</p>
<p>Anyway, back to the task at hand&#8230;</p>
<p>Ever get confused as to how to name getters and setters for properties?<br />
If property is all lowercase you just convert first letter to uppercase and that&#8217;s easy enough.<br />
If it&#8217;s all uppercase, no problem too. Just leave it as is.<br />
Java &amp; Groovy convention dictates properties shouldn&#8217;t begin with upper case and then revert to lower, so you can&#8217;t define getters and setters for such a property (Tx below). This is normally reserved for class names, so a getter/setter never gets called when you don&#8217;t manually call the property via the get/set method names and resort to property syntax alone (ie field name).<br />
If they are camelCase like qText or rText, things get a bit more tricky to remember.<br />
I made each accessor/mutator (getter/setter) write some output when invoked to test this out.<br />
As you can see, uppercasing  qText to QText property isn&#8217;t correct. It fires a blank. So you leave the property in it&#8217;s camel case state.<br />
You can see this is right by examining the output of LHS (setter) or RHS (getter) property access when you access the property with field style syntax.</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
package jgf
class J {
 def ptext
 def qText
 def rText
 def ST
 def Tx
 void setPtext(s) {
   println 'setter ptext'
   this.ptext = s
 }
 def getPtext() {
   println 'getter ptext'
   return ptext
 }
 void setQtext(s) {
   println 'setter qText'
   this.ptext = s
 }
 def getQtext() {
   println 'getter qText'
   return ptext
 }
  void setrText(s) {
   println 'setter rText'
   this.rText = s
 }
 def getrText() {
   println 'getter rText'
   return rText
 }
  void setST(s) {
   println 'setter ST'
   this.ST = s
 }
 def getST() {
   println 'getter ST'
   return ST
 }
  void setTx(s) {
   println 'setter Tx'
   this.Tx = s
 }
 def getTx() {
   println 'getter Tx'
   return Tx
 }

}
def x = new J()
println '-'*5 + ' p: ' + '-'*5
x.ptext = 'a'
println x.ptext
println '-'*5 + ' q: ' + '-'*5
x.qText = 'b'
println x.qText
println '-'*5 + ' r: ' + '-'*5
x.rText = 'c'
println x.rText
println '-'*5 + ' s: ' + '-'*5
x.ST = 'd'
println x.ST
println '-'*5 + ' t: ' + '-'*5
x.Tx = 'e'
println x.Tx
</pre></p>
<pre>----- p: -----
setter ptext
getter ptext
a
----- q: -----
b
----- r: -----
setter rText
getter rText
c
----- s: -----
setter ST
getter ST
d
----- t: -----
e</pre>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/camel-case-confusion/'>Camel Case confusion</a>, <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/property-naming/'>Property naming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1105&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/12/how-to-name-getterssetters-correctly-in-groovy-for-camel-case-field-properties/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Groovy Regular Expressions to abbreviate compass directions with look ahead and look behind.</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/11/groovy-regular-expressions-to-abbreviate-compass-directions-with-look-ahead-and-look-behind/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/11/groovy-regular-expressions-to-abbreviate-compass-directions-with-look-ahead-and-look-behind/#comments</comments>
		<pubDate>Tue, 11 May 2010 21:56:11 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[look ahead]]></category>
		<category><![CDATA[look behind]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1095</guid>
		<description><![CDATA[I wrote this handy routine to abbreviate compass directions (plus central to C). The thing was I didn&#8217;t want to abbreviate Us state names like North Dakota or South Dakota. I also didn&#8217;t want to corrupt place names like Northridge, and I had to deal with all sorts of permutations of compass points. As well [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1095&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wrote this handy routine to abbreviate compass directions (plus central to C).<br />
The thing was I didn&#8217;t want to abbreviate Us state names like North Dakota or South Dakota.<br />
I also didn&#8217;t want to corrupt place names like Northridge, and I had to deal with all sorts of permutations of compass points.<br />
As well not matching if a name follows a point, I also had the case where there is a place called George West. So I had my work cut out for me. :-)<br />
Anyway here&#8217;s the routine</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def points = [[k: ~/(N|n)ortheast(ern)?/                                                                        , v:'NE'],
              [k: ~/(?&gt;(N|n)orth(W|w)est(ern|:)?)(?! Terrotories)/                                              , v:'NW'],
              [k: ~/(S|s)outheast(ern)?/                                                                        , v:'SE'],
              [k: ~/(?&gt;(S|s)outh(\s)?west(ern)?)(?! Hill| Bend)/                                                , v:'SW'],
              [k: ~/(?&gt;(N|n)orth(ern)?|Upstate)(?! Carolina| Dakota| Platte| Neck| Mariana Islands| Bay|ridge)/ , v:'N' ],
              [k: ~/(E|e)ast(ern)?/                                                                             , v:'E' ],
              [k: ~/(?&gt;(S|s)outh(ern|side)?)(?! Carolina| Dakota)/                                              , v:'S' ],
              [k: ~/(?!(?&lt;=George ))(?&gt;(W|w)est(ern| of the)?)(?! Virginia| Palm Beach)/                        , v:'W' ],
              [k: ~/(?&gt;(C|c)entral|Center|Middle|the middle section of the)(?!town| Peninsula| Tennessee|ia)/   , v:'C' ]
             ]
def text =  'West Virginia'
points.each {p -&gt;
  def matcher = (text =~ p.k)
  text = matcher.replaceAll(p.v)
  println &quot;p.v: ${p.v} text: $text&quot;
}
return null
</pre></p>
<p>If I break apart  line 8, which is the most sophisticated of the lines in the example, it&#8217;s saying:</p>
<ol>
<li>Don&#8217;t match &#8216;West&#8217; (or a variation) if it&#8217;s prefixed by &#8216;George &#8216;.</li>
<li>It&#8217;s using a &#8216;look behind&#8217;  ie. ?&lt;=  for &#8216;George &#8216;.  So effectively after It&#8217;s matched &#8216;West&#8217;, it would discount &#8216;George West&#8217;.</li>
<li>The exclamation mark is the &#8216;not&#8217; symbol.</li>
<li>Then we have the variations: &#8216;West&#8217;, &#8216;Western&#8217;, or &#8216;West of the&#8217; (upper/lower case permutations).</li>
<li>The question mark represents an &#8216;optional (zero or one occurrence)&#8217;, and the vertical bar an &#8216;or&#8217; condition.</li>
<li>The parentheses breaks the regex into &#8216;groups&#8217; to which you can then apply qualifiers or cardinality rules.</li>
<li>The ?&gt; symbol this time is doing the a &#8216;look ahead&#8217; to match anything matched from the West grouping variations but excluding &#8216;!&#8217; a suffix of &#8216;  Virginia&#8217; or &#8216;|&#8217; &#8216; Palm Beach&#8217;.</li>
<li>So, finally &#8216;West Virginia&#8217; or &#8216;West Palm Beach&#8217; will not be matched, but &#8216;West Los Angeles&#8217; would match.</li>
</ol>
<p>Try setting text to &#8216;Northridge&#8217;, &#8216;George West&#8217;, &#8216;Middletown&#8217;, &#8216;South Bend&#8217; etc and you&#8217;ll see it doesn&#8217;t abbreviate the text. But something like &#8216;East Los Angeles&#8217;, would become &#8216;E Los Angeles&#8217;.</p>
<h3>Footnote:</h3>
<p>After reading Mastering Regular Expressions, I found you can also set the regular expression to &#8216;ignore case&#8217; mode with (?i) So the (N|n) can be simplified, by prefixing the RegEx pattern like so.<br />
Obviously the RegEx would now match &#8216;NORTHERNEASTERN&#8217;, whereas it didn&#8217;t before, so it&#8217;s a broader matcher.<br />
<pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def points = [[k: ~/(?i:)northeast(ern)?/                                                                        , v:'NE'],
//... rest of code as before
                    ]
</pre></p>
<h3>Here are some associated useful links:</h3>
<ul>
<li><a href="http://snipplr.com/users/hansamann/tags/regex/" target="_blank">Regex on Snipplr</a></li>
<li><a href="http://refcardz.dzone.com/refcardz/groovy" target="_blank">DZone Refcard on Groovy (has Regex symbols &amp; examples</a>)</li>
<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html" target="_blank">Javadoc for java.util.regex package</a></li>
<li><a href="http://java.sun.com/docs/books/tutorial/essential/regex/index.html" target="_blank">The Java Tutorials: Regular Expressions</a></li>
<li><a href="http://ourcraft.wordpress.com/2009/03/25/positive-examples-of-positive-and-negative-lookahead/" target="_blank">Daniel S. Meyer&#8217;s Positive examples of positive and negative lookahead example</a></li>
<li><a href="http://gr8fanboy.wordpress.com/2010/05/06/groovy-regex-text-manipulation-example/" target="_blank">Groovy Regex text manipulation example</a></li>
<li><a href="http://gr8fanboy.wordpress.com/2010/04/01/groovy-script-demonstrating-regular-expressions-to-manipulate-dates/" target="_blank">Groovy script demonstrating Regular Expressions to manipulate Dates</a></li>
<li><a href="http://gr8fanboy.wordpress.com/2010/05/06/ascertaining-how-subtract-works-with-strings-in-groovy/" target="_blank">Ascertaining how subtract works with Strings in Groovy</a></li>
</ul>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/look-ahead/'>look ahead</a>, <a href='http://gr8fanboy.wordpress.com/tag/look-behind/'>look behind</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex/'>RegEx</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1095/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1095/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1095/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1095&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/11/groovy-regular-expressions-to-abbreviate-compass-directions-with-look-ahead-and-look-behind/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Embellishing NekoHTML text method with Groovy &amp; recursion</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/10/embellishing-nekohtml-text-method-with-groovy-recursion/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/10/embellishing-nekohtml-text-method-with-groovy-recursion/#comments</comments>
		<pubDate>Mon, 10 May 2010 10:17:42 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[get complete text of node]]></category>
		<category><![CDATA[Groovy Grape]]></category>
		<category><![CDATA[NekoHTML]]></category>
		<category><![CDATA[Recursion]]></category>
		<category><![CDATA[Screen Scraping]]></category>
		<category><![CDATA[Web Crawling]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1064</guid>
		<description><![CDATA[NekoHTML is a fantastic library for crawling and extracting content from web pages. But if you&#8217;ve got nodes that are nested to an arbitrary depth, calling text on a node, doesn&#8217;t include nested text content. For example text in a bold tag (B node), nested within in a paragraph will not be returned when you call [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1064&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>NekoHTML is a fantastic library for crawling and extracting content from web pages.<br />
But if you&#8217;ve got nodes that are nested to an arbitrary depth, calling text on a node, doesn&#8217;t include nested text content. For example text in a bold tag (B node), nested within in a paragraph will not be returned when you call text() on the P node.</p>
<p>One of the things I&#8217;ve been working on at the moment is extracting content from the <a href="http://en.wikipedia.org/wiki/List_of_NANP_area_codes" target="_blank">Wiki page for NANP  telephones</a>.</p>
<p>I had a hell of a time tweaking and debugging a recursive routine to construct the paragraph text. The final result was quite elegant but the path to the solution wasn&#8217;t obvious and quite arduous to get right.<br />
So, I thought I&#8217;d share the final result with a little debugging routine I built into the recursive process to evaluate the path the code follows.</p>
<p>I basically extract the P and UL nodes associated to each area code and dump the nodes out into a separate AreaCode class.</p>
<p>The getText() method of AreaCode has an overloaded signature. You call it in it&#8217;s simple form with a single parameter from the client code and it calls into the helper routine. The depth parameter isn&#8217;t strictly necessary, but acts as a debugging aid in following the path through the code.</p>
<p>By analysing the debugging dump, I was surprised to find that you can call each on a String and it will return a character at a time and consequently refactored the code to make the program behave more intelligently, so that when a text node is encountered the whole node is added rather than character by character to the resulting StringBuffer!</p>
<p>The AreaCode class has a debug flag, set to false on creation. When it&#8217;s set to true, the code will dump out a debugging/trace output.<br />
I&#8217;ve highlighted the code you can tweak to enable debugging:</p>
<ol>
<li>If you look at the toString() method, you can uncomment lines 115/125 &amp; change the debug flag to true on line 116.</li>
<li>Uncomment the &#8216;if statement&#8217; on line 66 to only debug certain area  codes.</li>
</ol>
<p>I ended up setting the debug flag in the toString() method, because the getText() method indirectly gets called in the code() method via pText() and I didn&#8217;t want to create debugging output inadvertently.</p>
<p>The append text method, that intelligently adds a space at the appropriate time as the text gets built was at the heart of gettting the desired result.</p>
<h3>Here&#8217;s the code for <strong><span style="color:#ffff00;">crawlWikiNANPDialingCodes7.groovy</span></strong>:</h3>
<p>Hope you enjoy.</p>
<p><pre class="brush: groovy; auto-links: false; highlight: [66,115,116,125]; wrap-lines: false;">
package jgf
import groovy.grape.Grape
import com.thoughtworks.selenium.*

@Grapes([
    @Grab(group='net.sourceforge.nekohtml', module='nekohtml', version='1.9.14'),
    @Grab(group='xerces', module='xercesImpl', version='2.9.1'),
    @Grab(group='org.seleniumhq.selenium.client-drivers', module='selenium-java-client-driver', version='1.0.1') ])

class CrawlWikiNANPDialingCodes extends GroovySeleneseTestCase {

  @Override
  void setUp() throws Exception {
    super.setUp('http://en.wikipedia.org', '*chrome')
    setDefaultTimeout(50000)
    setCaptureScreenshotOnFailure(false)
    return null
  }

  void testCrawlWikiUKDialingCallingCodes() throws Exception {
    def crawl = init()
    extract200to900(crawl)

    return null
  }

  def init() {
    selenium.open(&quot;http://en.wikipedia.org/wiki/List_of_NANP_area_codes&quot;)
    def crawl = [:]
    crawl.with {
      page                            = getNekoHtml()
      areaCodes                       = []
    }
    println ''
    return crawl
  }

  def getNekoHtml() {
    def parser = new org.cyberneko.html.parsers.SAXParser()
    parser.setFeature('http://xml.org/sax/features/namespaces', false)
    def nekoHtml = new XmlParser(parser).parseText(selenium.getHtmlSource())
    return nekoHtml
  }

  def extract200to900(crawl) {
    crawl.with {
      def bc     = page.depthFirst().DIV.find{it.'@id' == 'bodyContent'}
      def ignore = true
      def ac
      bc.each{node -&gt;
        if (node.name() == 'H2' &amp;&amp; ignore &amp;&amp; node.SPAN[1].'@id' == '200')
          ignore = false
        if (node.name() == 'H2' &amp;&amp; !ignore &amp;&amp; node.SPAN[1].'@id'.startsWith('By_state'))
           ignore = true
        if (!ignore) {
          switch (node.name()) {
             case 'P'  : ac        = new AreaCode()
                         areaCodes &lt;&lt; ac
                         ac.pNode  = node
                         break
             case 'UL' : ac.ulNode = node
                         break
          }
        } // don't ignore
      } // bc.each (body content)
      areaCodes.each{ //if ((it.code() in ['928','971','975', '989']))
         println it
      }
    } // crawl.with
  }

}

class AreaCode {
   def pNode
   def ulNode
   def debug

   AreaCode() {
     debug = false
   }

   def pText() {
     return getText(pNode)
   }

   static nl() {
     return System.getProperty(&quot;line.separator&quot;)
   }

   def liNodes() {
     return (ulNode) ? ulNode.LI : null
   }

   def code() {
     return pText()[0..2]
   }

   def uText() {
     def res
     if (ulNode) {
       def sb = new StringBuilder()
       liNodes().each{node -&gt;
         def liText = getText(node)
         sb.append(&quot;$liText${nl()}&quot;)
       }
       res = sb.toString()[0..-2]
     } else {
       res = ''
     }
     return res
   }

   String toString() {
     //println &quot;-- Beg ${code()} ---&quot;
     debug = false // Change to true to debug recursion
     def res
     def p = pText()
     if (ulNode) {
       res    = &quot;$p${nl()}${uText()}&quot;
     } else {
       res = p
     }
     debug = false
     //println &quot;--- End ${code()} ---&quot;
     return res
   }

   def getText(node) {
     def res = new StringBuilder()
     getText(node, 1, res)
     return res
   }

   def getText(node, depth, res) {
    if (debug) println &quot;0B: $depth res: |$res|&quot;
    if (node.class.simpleName =='String') {
      if (debug) println &quot;1B: $depth res: |$res| node: $node&quot;
      appendText(res, node)
      if (debug) println &quot;1A: $depth res: |$res| node: $node&quot;
    } else {
      node.each{child -&gt;
        if (child.class.simpleName == 'String') {
          if (debug) println &quot;2B: $depth res: |$res| child: |$child|&quot;
         appendText(res, child)
          if (debug) println &quot;2A: $depth res: |$res| child: |$child|&quot;
        } else  {
          if (debug) println &quot;3B: $depth res: |$res| child: |${child.name()}|&quot;
          getText(child, depth +1, res)
          if (debug) println &quot;3A: $depth res: |$res| child: |${child.name()}|&quot;
        }
      }
    }
    if (debug) println &quot;0A: $depth res: |$res|&quot;
    return res.toString()
  }

  def appendText(res, newText) {
    if ( // if text being added doesn't start with . , ) or ]
         // and result has data
         // and result doesn't end with space ( or [
         // then append a space to result
         // Note: charAt returns type Char, so you need to cast to String for in to work..
        (!
          ( newText[0] in ['.', ')', ',', ']'] )
        ) &amp;&amp;
        ( res &amp;&amp;
          (!
            (
              (res.charAt(res.size() -1) as String)
               in [' ','(','[']
            )
          )
        )
       ) {
           res.append(' ')
         }
    res.append(newText)
  }
}
</pre></p>
<h3>Here&#8217;s a sample of the tail end of the output in normal mode:</h3>
<pre>
954 : Florida (all of Broward County : Fort Lauderdale, Hollywood, Coral Springs)
Created in 1995 by split from 305.
Overlain by 754 in 2002.
955 : not used
956 : Texas (Laredo, Brownsville, McAllen, Harlingen and South Texas)
Created in 1997 by split from 210.
957–958 : not used
959 : Connecticut
Overlain on 860 in 2001.
960–969 : not used (96x block reserved in case consecutive numbers are ever needed)
970 : Colorado (Aspen, Durango, Grand Junction, Fort Collins and northern and western Colorado)
Created in 1995 by split from 303.
971 : Oregon (Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)
Partially overlain on 503 in 2000. Clatsop and Tillamook Counties, originally excluded from the overlay, were added in 2008.
972 : Texas
Created in 1996 by split from 214. In 1999 the split was reversed to become an overlay, and a second overlay of 469 was added.
973 : New Jersey (Newark, Paterson and northwestern New Jersey)
Created in 1997 by split from 201.
Overlain by 862.
974 : not used
975 is assigned for numbering relief to 816 (Missouri) but no date has been scheduled for this to go into effect.
976–977 : not used
978 : Massachusetts (Fitchburg, Peabody and northeastern Massachusetts)
Created in 1997 by split from 508.
Overlain by 351 in 2001.
979 : Texas (Wharton, Bryan, Bay City, College Station, Lake Jackson, La Grange and Southeast Texas)
Created in 2000 by split from 409.
980 : North Carolina
Overlain on 704 in 2001.
981–983 : not used
984 is assigned for overlay relief to 919 (North Carolina) but no date has been scheduled for this to go into effect.
985 : Louisiana (Houma, Slidell and southeastern Louisiana excluding New Orleans)
Created in 2001 by split from 504.
986–988 : not used
989 : Michigan (Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)
Created in 2000 by split from 517.
</pre>
<h3>Here&#8217;s a sample of the output in debug mode: </h3>
<p>The quirky B/A  in first column means before/after and correlates to the specific println statements, the depth of recursion comes next, then res (the string that gets appended to), then, either the HTML node type or text node value.</p>
<pre>
-- Beg 928 ---
0B: 1 res: ||
3B: 1 res: || child: |B|
0B: 2 res: ||
3B: 2 res: || child: |A|
0B: 3 res: ||
2B: 3 res: || child: |928|
2A: 3 res: |928| child: |928|
0A: 3 res: |928|
3A: 2 res: |928| child: |A|
0A: 2 res: |928|
3A: 1 res: |928| child: |B|
2B: 1 res: |928| child: |:|
2A: 1 res: |928 :| child: |:|
3B: 1 res: |928 :| child: |A|
0B: 2 res: |928 :|
2B: 2 res: |928 :| child: |Arizona|
2A: 2 res: |928 : Arizona| child: |Arizona|
0A: 2 res: |928 : Arizona|
3A: 1 res: |928 : Arizona| child: |A|
2B: 1 res: |928 : Arizona| child: |(|
2A: 1 res: |928 : Arizona (| child: |(|
3B: 1 res: |928 : Arizona (| child: |A|
0B: 2 res: |928 : Arizona (|
2B: 2 res: |928 : Arizona (| child: |Flagstaff|
2A: 2 res: |928 : Arizona (Flagstaff| child: |Flagstaff|
0A: 2 res: |928 : Arizona (Flagstaff|
3A: 1 res: |928 : Arizona (Flagstaff| child: |A|
2B: 1 res: |928 : Arizona (Flagstaff| child: |,|
2A: 1 res: |928 : Arizona (Flagstaff,| child: |,|
3B: 1 res: |928 : Arizona (Flagstaff,| child: |A|
0B: 2 res: |928 : Arizona (Flagstaff,|
2B: 2 res: |928 : Arizona (Flagstaff,| child: |Kingman|
2A: 2 res: |928 : Arizona (Flagstaff, Kingman| child: |Kingman|
0A: 2 res: |928 : Arizona (Flagstaff, Kingman|
3A: 1 res: |928 : Arizona (Flagstaff, Kingman| child: |A|
2B: 1 res: |928 : Arizona (Flagstaff, Kingman| child: |,|
2A: 1 res: |928 : Arizona (Flagstaff, Kingman,| child: |,|
3B: 1 res: |928 : Arizona (Flagstaff, Kingman,| child: |A|
0B: 2 res: |928 : Arizona (Flagstaff, Kingman,|
2B: 2 res: |928 : Arizona (Flagstaff, Kingman,| child: |Prescott|
2A: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott| child: |Prescott|
0A: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott|
3A: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott| child: |A|
2B: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott| child: |,|
2A: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott,| child: |,|
3B: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott,| child: |A|
0B: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott,|
2B: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott,| child: |Yuma|
2A: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma| child: |Yuma|
0A: 2 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma|
3A: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma| child: |A|
2B: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma| child: |and northern and western Arizona)|
2A: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma and northern and western Arizona)| child: |and northern and western Arizona)|
0A: 1 res: |928 : Arizona (Flagstaff, Kingman, Prescott, Yuma and northern and western Arizona)|
0B: 1 res: ||
2B: 1 res: || child: |Created in 2001 by split from|
2A: 1 res: |Created in 2001 by split from| child: |Created in 2001 by split from|
3B: 1 res: |Created in 2001 by split from| child: |B|
0B: 2 res: |Created in 2001 by split from|
3B: 2 res: |Created in 2001 by split from| child: |A|
0B: 3 res: |Created in 2001 by split from|
2B: 3 res: |Created in 2001 by split from| child: |520|
2A: 3 res: |Created in 2001 by split from 520| child: |520|
0A: 3 res: |Created in 2001 by split from 520|
3A: 2 res: |Created in 2001 by split from 520| child: |A|
0A: 2 res: |Created in 2001 by split from 520|
3A: 1 res: |Created in 2001 by split from 520| child: |B|
2B: 1 res: |Created in 2001 by split from 520| child: |.|
2A: 1 res: |Created in 2001 by split from 520.| child: |.|
0A: 1 res: |Created in 2001 by split from 520.|
--- End 928 ---
928 : Arizona (Flagstaff, Kingman, Prescott, Yuma and northern and western Arizona)
Created in 2001 by split from 520.
-- Beg 971 ---
0B: 1 res: ||
3B: 1 res: || child: |B|
0B: 2 res: ||
3B: 2 res: || child: |A|
0B: 3 res: ||
2B: 3 res: || child: |971|
2A: 3 res: |971| child: |971|
0A: 3 res: |971|
3A: 2 res: |971| child: |A|
0A: 2 res: |971|
3A: 1 res: |971| child: |B|
2B: 1 res: |971| child: |:|
2A: 1 res: |971 :| child: |:|
3B: 1 res: |971 :| child: |A|
0B: 2 res: |971 :|
2B: 2 res: |971 :| child: |Oregon|
2A: 2 res: |971 : Oregon| child: |Oregon|
0A: 2 res: |971 : Oregon|
3A: 1 res: |971 : Oregon| child: |A|
2B: 1 res: |971 : Oregon| child: |(Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)|
2A: 1 res: |971 : Oregon (Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)| child: |(Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)|
0A: 1 res: |971 : Oregon (Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)|
0B: 1 res: ||
2B: 1 res: || child: |Partially overlain on|
2A: 1 res: |Partially overlain on| child: |Partially overlain on|
3B: 1 res: |Partially overlain on| child: |B|
0B: 2 res: |Partially overlain on|
2B: 2 res: |Partially overlain on| child: |503|
2A: 2 res: |Partially overlain on 503| child: |503|
0A: 2 res: |Partially overlain on 503|
3A: 1 res: |Partially overlain on 503| child: |B|
2B: 1 res: |Partially overlain on 503| child: |in 2000.|
2A: 1 res: |Partially overlain on 503 in 2000.| child: |in 2000.|
3B: 1 res: |Partially overlain on 503 in 2000.| child: |A|
0B: 2 res: |Partially overlain on 503 in 2000.|
2B: 2 res: |Partially overlain on 503 in 2000.| child: |Clatsop|
2A: 2 res: |Partially overlain on 503 in 2000. Clatsop| child: |Clatsop|
0A: 2 res: |Partially overlain on 503 in 2000. Clatsop|
3A: 1 res: |Partially overlain on 503 in 2000. Clatsop| child: |A|
2B: 1 res: |Partially overlain on 503 in 2000. Clatsop| child: |and|
2A: 1 res: |Partially overlain on 503 in 2000. Clatsop and| child: |and|
3B: 1 res: |Partially overlain on 503 in 2000. Clatsop and| child: |A|
0B: 2 res: |Partially overlain on 503 in 2000. Clatsop and|
2B: 2 res: |Partially overlain on 503 in 2000. Clatsop and| child: |Tillamook|
2A: 2 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook| child: |Tillamook|
0A: 2 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook|
3A: 1 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook| child: |A|
2B: 1 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook| child: |Counties, originally excluded from the overlay, were added in 2008.|
2A: 1 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook Counties, originally excluded from the overlay, were added in 2008.| child: |Counties, originally excluded from the overlay, were added in 2008.|
0A: 1 res: |Partially overlain on 503 in 2000. Clatsop and Tillamook Counties, originally excluded from the overlay, were added in 2008.|
--- End 971 ---
971 : Oregon (Portland, Salem, Hillsboro, Beaverton and northwestern Oregon)
Partially overlain on 503 in 2000. Clatsop and Tillamook Counties, originally excluded from the overlay, were added in 2008.
-- Beg 975 ---
0B: 1 res: ||
3B: 1 res: || child: |B|
0B: 2 res: ||
3B: 2 res: || child: |A|
0B: 3 res: ||
2B: 3 res: || child: |975|
2A: 3 res: |975| child: |975|
0A: 3 res: |975|
3A: 2 res: |975| child: |A|
0A: 2 res: |975|
3A: 1 res: |975| child: |B|
2B: 1 res: |975| child: |is assigned for numbering relief to|
2A: 1 res: |975 is assigned for numbering relief to| child: |is assigned for numbering relief to|
3B: 1 res: |975 is assigned for numbering relief to| child: |B|
0B: 2 res: |975 is assigned for numbering relief to|
3B: 2 res: |975 is assigned for numbering relief to| child: |A|
0B: 3 res: |975 is assigned for numbering relief to|
2B: 3 res: |975 is assigned for numbering relief to| child: |816|
2A: 3 res: |975 is assigned for numbering relief to 816| child: |816|
0A: 3 res: |975 is assigned for numbering relief to 816|
3A: 2 res: |975 is assigned for numbering relief to 816| child: |A|
0A: 2 res: |975 is assigned for numbering relief to 816|
3A: 1 res: |975 is assigned for numbering relief to 816| child: |B|
2B: 1 res: |975 is assigned for numbering relief to 816| child: |(Missouri) but no date has been scheduled for this to go into effect.|
2A: 1 res: |975 is assigned for numbering relief to 816 (Missouri) but no date has been scheduled for this to go into effect.| child: |(Missouri) but no date has been scheduled for this to go into effect.|
0A: 1 res: |975 is assigned for numbering relief to 816 (Missouri) but no date has been scheduled for this to go into effect.|
--- End 975 ---
975 is assigned for numbering relief to 816 (Missouri) but no date has been scheduled for this to go into effect.
-- Beg 989 ---
0B: 1 res: ||
3B: 1 res: || child: |B|
0B: 2 res: ||
3B: 2 res: || child: |A|
0B: 3 res: ||
2B: 3 res: || child: |989|
2A: 3 res: |989| child: |989|
0A: 3 res: |989|
3A: 2 res: |989| child: |A|
0A: 2 res: |989|
3A: 1 res: |989| child: |B|
2B: 1 res: |989| child: |:|
2A: 1 res: |989 :| child: |:|
3B: 1 res: |989 :| child: |A|
0B: 2 res: |989 :|
2B: 2 res: |989 :| child: |Michigan|
2A: 2 res: |989 : Michigan| child: |Michigan|
0A: 2 res: |989 : Michigan|
3A: 1 res: |989 : Michigan| child: |A|
2B: 1 res: |989 : Michigan| child: |(Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)|
2A: 1 res: |989 : Michigan (Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)| child: |(Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)|
0A: 1 res: |989 : Michigan (Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)|
0B: 1 res: ||
2B: 1 res: || child: |Created in 2000 by split from|
2A: 1 res: |Created in 2000 by split from| child: |Created in 2000 by split from|
3B: 1 res: |Created in 2000 by split from| child: |B|
0B: 2 res: |Created in 2000 by split from|
3B: 2 res: |Created in 2000 by split from| child: |A|
0B: 3 res: |Created in 2000 by split from|
2B: 3 res: |Created in 2000 by split from| child: |517|
2A: 3 res: |Created in 2000 by split from 517| child: |517|
0A: 3 res: |Created in 2000 by split from 517|
3A: 2 res: |Created in 2000 by split from 517| child: |A|
0A: 2 res: |Created in 2000 by split from 517|
3A: 1 res: |Created in 2000 by split from 517| child: |B|
2B: 1 res: |Created in 2000 by split from 517| child: |.|
2A: 1 res: |Created in 2000 by split from 517.| child: |.|
0A: 1 res: |Created in 2000 by split from 517.|
--- End 989 ---
989 : Michigan (Alpena, Mt. Pleasant, Bay City, Saginaw, Midland, Owosso and central Michigan)
Created in 2000 by split from 517.
</pre>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/get-complete-text-of-node/'>get complete text of node</a>, <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/groovy-grape/'>Groovy Grape</a>, <a href='http://gr8fanboy.wordpress.com/tag/nekohtml/'>NekoHTML</a>, <a href='http://gr8fanboy.wordpress.com/tag/recursion/'>Recursion</a>, <a href='http://gr8fanboy.wordpress.com/tag/screen-scraping/'>Screen Scraping</a>, <a href='http://gr8fanboy.wordpress.com/tag/web-crawling/'>Web Crawling</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1064/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1064/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1064&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/10/embellishing-nekohtml-text-method-with-groovy-recursion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Groovy Regex text manipulation example</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/06/groovy-regex-text-manipulation-example/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/06/groovy-regex-text-manipulation-example/#comments</comments>
		<pubDate>Thu, 06 May 2010 15:23:22 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1047</guid>
		<description><![CDATA[Output from running program: 201 : New Jersey ( Hackensack , Jersey City , Hoboken , Bayonne , Ridgewood , Union City , Teaneck , New Milford , and northeast New Jersey) p1: 201 : New Jersey code: 201 state: New Jersey &#124; p3: Hackensack , Jersey City , Hoboken , Bayonne , Ridgewood , [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1047&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def text = '201 : New Jersey ( Hackensack , Jersey City , Hoboken , Bayonne , Ridgewood , Union City , Teaneck , New Milford , and northeast New Jersey)'
def textPattern = /(.*)(\()(.*)(\))/         /* Break text into constituent parts.
                                                You have to escape brackets and colons as they make up Regex expressions.
                                                Thank heavens for Groovy / to quote regular expressions otherwise massive escape sequences would apply
                                                1) before '('
                                                2) '('
                                                3) between '(' &amp; ')'
                                                4) ')'
                                              */
def p1Pattern = /(\d{3})(\s\:\s)([\w|\s]+)/  /* Break part 1 from above into
                                                1) Digits
                                                2) ' : '
                                                3) (Word or space) one or more times
                                              */
def p3Pattern = /([\w|\s]+)/                 /* The single Word or space once or more works here, Text from 3) of textPattern will split on commas (or any non word/space character)
                                              * A word character: [a-zA-Z_0-9] See: http://java.sun.com/docs/books/tutorial/essential/regex/pre_char_classes.html
                                              */
(text =~ textPattern).each{fullText, p1, openbracket, p3, closebracket -&gt;
  println fullText
  println &quot;p1: $p1&quot;
  (p1 =~ p1Pattern).each{fullP1, code, p2, state  -&gt;
    println &quot;code: $code&quot;
    println &quot;state: $state|&quot;
  }
  println &quot;p3: $p3&quot;
  def matchP3 = (p3 =~ p3Pattern)
  println matchP3.groupCount()                  /* You can call a group count on Regex. Useful for checking no of params to left of rocket symbol. Remember first always full match
                                                 * So if you leave default it property you will get a list with one group, entry 0 = full match. Entry 1 = first group.
                                                 * Since there's only one group entry 0 and 1 will always be equal (it[0] = it[1])
                                                 */
  matchP3.each{
    println &quot;${it[1]}&quot;
  }
}
</pre></p>
<h3>Output from running program:</h3>
<pre>201 : New Jersey ( Hackensack , Jersey City , Hoboken , Bayonne , Ridgewood , Union City , Teaneck , New Milford , and northeast New Jersey)
p1: 201 : New Jersey
code: 201
state: New Jersey |
p3:  Hackensack , Jersey City , Hoboken , Bayonne , Ridgewood , Union City , Teaneck , New Milford , and northeast New Jersey
1
 Hackensack
 Jersey City
 Hoboken
 Bayonne
 Ridgewood
 Union City
 Teaneck
 New Milford
 and northeast New Jersey</pre>
<h3>Also note the difference:</h3>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def x = ~/(\w+)/
def y = /(\w+)/
println &quot;x: ${x.class}&quot;
println &quot;y: ${y.class}&quot;
</pre></p>
<pre>x: class java.util.regex.Pattern
y: class java.lang.String</pre>
<p>So strictly speaking it&#8217;s going to be better to precompile patterns with the ~/ / style syntax.</p>
<h3>Also note the Groovy &#8216;find&#8217;  operator =~  is a Matcher object, whereas the  &#8216;match&#8217;  operator ==~ is a Boolean and is more restrictive.</h3>
<p>The pattern for &#8216;match&#8217; has to be a full match on text search string to return a result of true. See <a href="http://snipplr.com/view/2091/groovy-series-regular-expressions-23/" target="_blank">here</a>.</p>
<p>You can also get caught by the loose terminology Java applies to the pre-defined character class of &#8216;.&#8217; denoted as &#8216;any character&#8217; <a href="http://java.sun.com/docs/books/tutorial/essential/regex/pre_char_classes.html" target="_blank">here</a>. :-( Grrr!</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def t            = '257–259 : not used'
def patCodeRange = ~/\d{3}\.\d{3}/
def r = (t =~ patCodeRange)
if (r) println &quot;found&quot;
r.each{println it}
return null
</pre></p>
<p>This doesn&#8217;t yield a match!</p>
<p>Whereas this does:</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def t            = '257–259 : not used'
def patCodeRange = ~/\d{3}\W\d{3}/
def r = (t =~ patCodeRange)
if (r) println &quot;found&quot;
r.each{println it}
return null
</pre></p>
<h3>Footnote:</h3>
<p>Since purchasing <a href="http://www.amazon.co.uk/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/" target="_blank">Jeffrey Friedl&#8217;s Mastering Regular Expressions book</a>, I&#8217;ve found out that you can also use \p{Pd} to represents hyphens and dashes of all sorts (P123, Table 3.9).</p>
<p>This also gets a mention <a href="http://www.unicode.org/reports/tr18/#Categories" target="_blank">here</a> by way of the the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html" target="_blank">Javadoc for Pattern</a>.</p>
<pre>found
257–259</pre>
<h3>Here are some associated useful links:</h3>
<ul>
<li><a href="http://snipplr.com/users/hansamann/tags/regex/" target="_blank">Regex on Snipplr</a></li>
<li><a href="http://refcardz.dzone.com/refcardz/groovy" target="_blank">DZone Refcard on Groovy (has Regex symbols &amp; examples</a>)</li>
<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html" target="_blank">Javadoc for java.util.regex package</a></li>
<li><a href="http://java.sun.com/docs/books/tutorial/essential/regex/index.html" target="_blank">The Java Tutorials: Regular Expressions</a></li>
<li><a href="http://ourcraft.wordpress.com/2009/03/25/positive-examples-of-positive-and-negative-lookahead/" target="_blank">Daniel S. Meyer&#8217;s Positive examples of positive and negative lookahead example</a></li>
<li><a href="http://gr8fanboy.wordpress.com/2010/04/01/groovy-script-demonstrating-regular-expressions-to-manipulate-dates/" target="_blank">Groovy script demonstrating Regular Expressions to manipulate Dates</a></li>
</ul>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex/'>RegEx</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1047/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1047&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/06/groovy-regex-text-manipulation-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Ascertaining how subtract works with Strings in Groovy</title>
		<link>http://gr8fanboy.wordpress.com/2010/05/06/ascertaining-how-subtract-works-with-strings-in-groovy/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/05/06/ascertaining-how-subtract-works-with-strings-in-groovy/#comments</comments>
		<pubDate>Thu, 06 May 2010 09:15:56 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[RegEx find]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Subtract]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1032</guid>
		<description><![CDATA[Subtracting strings in Groovy is a bit too ambiguous for my liking. For example, have you ever wondered how the following code would execute: Does b result in?: a) &#8216;abc xyz &#8216; (subtracting right to left) b) &#8216; xyz abc&#8217; (subtracting left to right) c) &#8216; xyz &#8216; (a greedy subtract subtracting all instances) The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1032&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Subtracting strings in Groovy is a bit too ambiguous for my liking.<br />
For example, have you ever wondered how the following code would execute:</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def a = 'abc xyz abc'
def b = a - 'abc'
println b
</pre></p>
<p>Does b result in?:<br />
a) &#8216;abc xyz &#8216; (subtracting right to left)<br />
b) &#8216; xyz abc&#8217; (subtracting left to right)<br />
c) &#8216; xyz &#8216; (a greedy subtract subtracting all instances)</p>
<p>The answer is b!</p>
<p>If you could somehow syntactically specify the three variants in the subtract or specify a starting position to search from in the syntax I&#8217;d be a happier camper.<br />
Depending on your needs you&#8217;re back to using Regular Expressions, String Replace or some sort of manual splicing of strings with the indexOf variants.</p>
<p>If you want the result specified by c), for example you can do this (courtesy of Venkat&#8217;s Programming Groovy P113) The replaceAll is an empty string, two back to back single quotes:</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def c = (a =~ /abc/).replaceAll('')
</pre></p>
<p>Here&#8217;s a few other variants:<br />
<pre class="brush: groovy; auto-links: false; wrap-lines: false;">
def a = 'abc xyz abc'
def b = /abc/
def c = (a =~ b)
def d = c.replaceFirst('')
def e = a.replaceFirst(b, '')
println &quot;d: $d&quot;
println &quot;e: $e&quot;
def st,fin
def cm1 = (c.size() -1)
c.eachWithIndex{m, i -&gt;
  if (i == cm1)  {
    st = c.start()
    fin = c.end()
  }
}
def p1 = (st == 0) ? '' : a[0..st-1]
def p2 = (fin == a.size()) ? '' : a[fin..-1]
a = p1+p2
println &quot;a: |$a|&quot;
return null
</pre><br />
and the resulting output:</p>
<pre>
d:  xyz abc
e:  xyz abc
a: |abc xyz |
</pre>
<p>Here are some associated useful links:</p>
<ul>
<li><a href="http://groovy.codehaus.org/groovy-jdk/java/lang/String.html" target="_blank">Groovy String API</a></li>
<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html" target="_blank">Java String API</a></li>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html" target="_blank">StringBuilder</a></li>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html" target="_blank">StringBuffer</a></li>
<li><a href="http://snipplr.com/users/hansamann/tags/regex/" target="_blank">Regex on Snipplr</a></li>
<li><a href="http://refcardz.dzone.com/refcardz/groovy" target="_blank">DZone Refcard on Groovy (has Regex symbols &amp; examples</a>)</li>
<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html" target="_blank">Javadoc for java.util.regex package</a></li>
<li><a href="http://java.sun.com/docs/books/tutorial/essential/regex/index.html" target="_blank">The Java Tutorials: Regular Expressions</a></li>
<li><a href="http://ourcraft.wordpress.com/2009/03/25/positive-examples-of-positive-and-negative-lookahead/" target="_blank">Daniel S. Meyer&#8217;s Positive examples of positive and negative lookahead example</a></li>
<li><a href="http://gr8fanboy.wordpress.com/2010/04/01/groovy-script-demonstrating-regular-expressions-to-manipulate-dates/" target="_blank">Groovy script demonstrating Regular Expressions to manipulate Dates</a></li>
</ul>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex/'>RegEx</a>, <a href='http://gr8fanboy.wordpress.com/tag/regex-find/'>RegEx find</a>, <a href='http://gr8fanboy.wordpress.com/tag/string/'>String</a>, <a href='http://gr8fanboy.wordpress.com/tag/subtract/'>Subtract</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1032/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1032/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1032/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1032&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/05/06/ascertaining-how-subtract-works-with-strings-in-groovy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
		<item>
		<title>Groovy Enums example</title>
		<link>http://gr8fanboy.wordpress.com/2010/04/30/groovy-enums-example/</link>
		<comments>http://gr8fanboy.wordpress.com/2010/04/30/groovy-enums-example/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 09:08:13 +0000</pubDate>
		<dc:creator>gr8fanboy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://gr8fanboy.wordpress.com/?p=1026</guid>
		<description><![CDATA[Based on Coins example here, I developed a enumeration for me to crawl the various tables in this page on Wiki. What I found interesting was the synthesis of the values() property from value and wasn&#8217;t sure whether it would return the names or the values. Here&#8217;s an example to clarify how things work. 1: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1026&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Based on Coins example <a href="http://groovy.codehaus.org/Using+Enums" target="_blank">here</a>, I developed a enumeration for me to crawl the various tables in <a href="http://en.wikipedia.org/wiki/List_of_NANP_area_codes" target="_blank">this page on Wiki</a>.<br />
What I found interesting was the synthesis of the values() property from value and wasn&#8217;t sure whether it would return the names or the values. Here&#8217;s an example to clarify how things work.</p>
<p><pre class="brush: groovy; auto-links: false; wrap-lines: false;">
enum NANPCodeGroup {
  USA(3), Canada(4), Carribean(5), USPacific(6)
  NANPCodeGroup(int value) {this.value = value}
  private final int value
  public int value() {return value}
}
NANPCodeGroup.each{println &quot;1: $it&quot;}
NANPCodeGroup.each{println &quot;2: ${it.value()}&quot;}
println &quot;3: ${NANPCodeGroup.values()}&quot;
NANPCodeGroup.values().each{println &quot;4: $it&quot;}
println &quot;5: ${NANPCodeGroup.USA.value()}&quot;
println &quot;6: ${NANPCodeGroup.USA}&quot;
x = NANPCodeGroup.grep{it.value() == 3}[0]?:''
println &quot;7: $x , ${x.class}&quot;
</pre></p>
<pre>
1: USA
1: Canada
1: Carribean
1: USPacific
2: 3
2: 4
2: 5
2: 6
3: [USA, Canada, Carribean, USPacific]
4: USA
4: Canada
4: Carribean
4: USPacific
5: 3
6: USA
7: USA , class NANPCodeGroup
</pre>
<br />Filed under: <a href='http://gr8fanboy.wordpress.com/category/groovy/'>Groovy</a> Tagged: <a href='http://gr8fanboy.wordpress.com/tag/enum/'>Enum</a>, <a href='http://gr8fanboy.wordpress.com/tag/groovy/'>Groovy</a>, <a href='http://gr8fanboy.wordpress.com/tag/tutorial/'>Tutorial</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gr8fanboy.wordpress.com/1026/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gr8fanboy.wordpress.com/1026/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gr8fanboy.wordpress.com/1026/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gr8fanboy.wordpress.com&amp;blog=12147156&amp;post=1026&amp;subd=gr8fanboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gr8fanboy.wordpress.com/2010/04/30/groovy-enums-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bdee18bba4f154a08d118cd91359da44?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">gr8fanboy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
