Be careful writing hashCode() methods when using HashCodeBuilder

I've blogged in the past about using the Apache Commons EqualsBuilder and HashCodeBuilder to write simpler equals() & hashCode() methods.

My colleague recently blogged about a potential pitfall when using this approach, I'll summarise his findings here:

Be VERY careful when you ask the HashCodeBuilder to generate the resulting hashcode value:

Make sure you call builder.toHashCode() rather than builder.hashCode()

The first correctly generates a hashcode value based on the objects that you have added to the builder, the second gives you the hashcode of the builder object itself - definitely not the value you would be expecting (and would be a sure fire way to lose your objects in a Collection)...

Technorati Tags: , , , ,

How to escape text when pasting into Eclipse (including XML)

When you paste text into Eclipse it does just that - places where the cursor is in it's full un-altered original form. This is fine most of the time apart from when you might want to copy a chunk of XML (or a similar large body of text). What you end up with in this case is the text pasted in with red lines everywhere because the text hasn't been properly escaped for Java code.

To enable escaping of pasted text open the Preferences panel ('Window' menu -> 'Preferences...' option), then choose: 'Java' -> 'Editor' -> 'Typing' and tick the box which says "Escape text when pasting in a string literal":


Now whenever you post in text which is broken over multiple lines, Eclipse will insert the relevant quotes of Java to make Eclipse happy.

Technorati Tags: , , , , ,

Summary of June's Manchester Spring User Group Meeting

I missed the first Manchester Spring User Group meeting back in April which I heard was excellent so I made sure I didn't miss June's meeting.

The sessions (based at the University of Manchester Core Technology Facility - cool building BTW) were organised by Cake Solutions (in particular their MD Guy Remond) and it was Guy that introduced the evening and laid out the agenda. Just a quick note about the venue, it's a very new tidy building, the room was an excellent size (seating for 50+ people) and coffee (and cake!) were provided. Parking was free and immediately outside the building, just press the buzzer and mention the Spring User Group...

The first talk was by Paul Sweby (of CapGemini) entitled:

Spring in Government - Improving System & Personal Performance

Paul works on the HM Revenue & Customs website and started his talk by providing some pretty impressive statistics: around 40 million tax payers use the HMRC web site for various purposes. The software is developed by CapGemini, the systems integration provided by Fujitsu, with BT providing the network connectivity.

Previous versions were composed of a mixture of COBOL, Java and .Net, and since 2000 it was predominately Java with stateless sessions beans and the facade pattern.

Since then this has been ripped out and replaced with Spring. It's now made up of the following software technologies: Spring 2.0, Hibernate 3.2, Apache Commons, Drools 4, and the following supporting components: F5 BigIP, Apache, WebLogic, Oracle 10g (with RAC)

Here are the notes that I was able to capture as Paul described some of the key points to being able to build such a large scale application:

  • Minimal use of JavaScript to ensure widest reach and browser compatibility
  • Uses REST extensively - will be migrating to Spring 3.0's REST support
  • Strictly one business call per request
  • The HTTP session is bad, difficult & expensive to replicate, compromises the compliance of the browsers navigation features (back button)
  • Minimal shared user data is maintained (around 2k) this is passed around between servers either via the database or sometimes as hidden fields on the page
  • Because of the above the pages are all bookmarkable
  • Careful planning of the URLs is important due to the use of REST and the exposure of data and services as 'resources'
  • Using CruiseControl (and possibly Hudson) for continuous integration
  • The used agile 'by stealth', test first development and 'barely enough' modelling
Future plans include:
  • Increased use of Spring Batch
  • Migration from Spring 2 to Spring 3 (remove the concrete inheritance of the controllers)
  • Add support for 'Web 2.0' components
The Spring-based system described above was able to deal with 400,000 filings on the last allowed day (Jan 30th) with 40,000 submissions filed in the last hour alone! For the tax year of 2008/2009 over 5.8 million tax returns were filed, with a saving to the government of £20 million. Pretty impressive stuff!

There was a little break which contained a mention of the Manchester Spring User Group sponsors: UMIC, Hays IT, Skills Matter, SpringSource & Cake Solutions and a mention about a new open source portal/forum/community site called OpenSource-Central.

The next talk was by Russ Miles (author and MD of OpenCredo amongst other things) and his talk was:

Grails Eye for the Spring Guy

Grails is an "open-source web application framework that leverages the Groovy language and complements Java Web development". It aims to make you more productive by providing a natural process from idea to concrete solution. It follows the 'convention over configuration' approach giving you an opinionated 'right way' of doing things - this is helpful in that fact that if you follow it's way of doing things you end up doing your work in less time, it's taken care of a lot of the mundane and background tasks for you.

After Russ explained some of the core ideas behind Grails, he then proceeded for the rest of the presentation to build a simple web application from scratch using Grails. He started by asking Grails to create the basic project structure: grails create-app and then followed by explaining some of the directory structure.

Without writing any code he then started his web application: grails run-app and navigated to a simple start page in his browser - the basic guts of getting a running application was done for you. He then created a domain class using the built-in Groovy scripts to create various types of artefacts, this auto-created an appropriate controller and a number of views suitable for simple CRUD operations. The controller doesn't have normal methods for the CRUD operations, it has 'closures' - methods which are assigned to properties and so can be passed around like variables.
Without writing any database code he re-ran the web app and added a new domain object which was then displayed in a resulting list - Grails had created a development database using HSQLDB and mapped the domain object to a backing table created when the web-application started up.

Grails plugins were mentioned next, it appears that most non-core functionality will be released as plugins which can cover the full technology stack from raw Spring access all the way up through controllers and domain objects up to the views. It's with the use of plugins that new 'conventions' can be introduced enriching the Grails world - one example of this was the quartz plugin - this provided some new commands including grails create-job. Other useful plugins included jsecurity, springws and yui.

He also dived a little into the world of Groovy showing that it's a smooth learning curve from Java to Groovy - you can write normal Java in a .groovy file and the Groovy interpreter/compiler understands it. Groovy also follows the same path as some of the other dynamic languages in that it has a 'metaobject protocol' (MOP) allowing the application to add functionality to objects and classes at runtime.

From my point of view, having done some Ruby and Rails development in the past, was that Grails appears to be a port of Rails to the Groovy language, taking the same ethos that 'convention of configuration' and simplicity are best. That's not to say that I don't see vast benefit in Grails just that I didn't see any new 'magic' being presented. One great advantage of Grails is the fact that it's underlying language (Groovy) is Java-based and runs (and compiles down to) standard Java which runs in the JVM. This allows a much smoother transition for Java developers to migration to something like Grails rather than learn Ruby and then figure out how to deploy Rails - quite different than dropping WAR files into Tomcat...

Guy concluded the evening with a little prize draw and then it was off to the local pub for some beers provided by Arie Chapman of SpringSource, cheers Arie!

UPDATE: Russ Miles has kindly uploaded his slides to his blog

Technorati Tags: , , , , , , , , , , , ,

Improving slow wifi bandwidth performance on an Acer Aspire One

We've noticed over the past few days that it was taking a long time to download stuff on our Acer Aspire One. Tonight I found out that it was only slow when it was unplugged from the mains - so it's a power-saving 'feature'. I couldn't find any options within the power saving section of Windows control panel, so it was off to google for some help.

Within seconds I found the perfect solution explained very clearly over on Peve's Blog. I'm not going to repeat his instructions as he explains it great already so head over there to read his post entitled Acer Aspire One Slow Wifi - Thanks Peve!

Technorati Tags: , , , ,

How to copy recorded TV programmes off your PVR (Humax 9200T)

We have had a Humax 9200T PVR for quite some time now and occasionally we have wanted a more portable copy (think DVD) of a particular programme that we have recorded.


If you flip down the right-hand panel you will notice an unlabelled standard USB B socket. It's by the use of this socket that you can stream recorded programmes off the Humax and onto a PC ready for converting to a DVD (or just watching on the PC).


Here's how you do it:

Visit Humax's support site and download & install their rather old and flaky Media E-Linker software (Click the "Media E-Linker software (Version 2.5) download link).

Get a regular USB lead with an 'A' type plug on one end, and a 'B' type plug on the other. Plug the 'B' end into the Humax, and the 'A' into any USB socket on your PC. Your PC should now 'find' the Humax and request to install the drivers, I let mine 'auto-search' and it found and installed the drivers just fine (I think they also might be packaged in the Humax E-Linker software installation).

Once the Humax is correctly attached, run the E-Linker software and choose to 'connect'. If everything is successful you be given a file listing on the righthand side - probably giving you options of Pictures & MP3. Change the drive letter in the drop-down box on the top-right and you should now see a listing of all your recorded programs.

Select the one that you want to transfer and click the button in the middle with an arrow pointing from right to left. Now the tricky part: wait, and wait, and wait, etc. On my rather old laptop (with USB1.1 I might add) it took over 24 hours to transfer a two hour program. It may be quicker with a USB2.0 PC but I had problems getting our Acer Aspire One to connect to the Humax correctly.

Once the transfer has completed you will be left with the program as a ".ts" file - this is an MPEG2 file but with "transport stream" encoding, exactly the same format as the file came over the air to your Humax in the first place. Many players and DVD burning software know how to deal with this format, but if not you can simply convert it to a regular MPEG2 video file with something like HDTVtoMPEG2


Technorati Tags: , ,

The Spring User Group comes back to Manchester on June 15th

Back in March I blogged about the first North West Spring User Group meeting. Well on the 15th June they are coming back to Manchester. I wasn't able to attend the last one but an old colleague Bill Comer attended the session.

June's session is on "Grails eye for the Spring guy" by Russ Miles (MD of OpenCredo). Russ has also blogged about the future talk over on his blog. It sounds good and I'm planning on attending this time so if you see me there come over and say hi!

Technorati Tags: , , , , , ,