All posts in 'Java'

An iterable array

12-Jan-10

Java has the nice Iterable interface (since Java 5, i guess) that allows object oriented loops like List<String> strings = new ArrayList<String>(); for(String string : strings) System.out.println(string);List<String> strings = new ArrayList<String>(); for(String string : strings) System.out.println(string); but guess what, a simple array is not iterable… In case you need one, feel free to use this […]

Read the complete article »

Today: Fun with Unicode, Regex and Java.

03-Nov-09

Some would say, i have 3 problems 😉 private final static Pattern placeholder = Pattern.compile("#\\{(\\w+?)\\}");private final static Pattern placeholder = Pattern.compile("#\\{(\\w+?)\\}"); won’t match “Mot#{ö}rhead” for example. To replace the word character \w you either need the list of possible unicodeblocks like [\p{InLatin}|\p{InEtc}] (you get the codes for the blocks through “Character.UnicodeBlock.forName” or you’re lazy like […]

Read the complete article »

Javas String.replaceAll

21-Jul-09

The following statement "foo baz".replaceAll("baz","$bar");"foo baz".replaceAll("baz","$bar"); will present you an java.lang.IllegalArgumentException: Illegal group reference exception as the replacement string can contain backreferences to the search pattern as stated in Mather#replaceAll: This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any […]

Read the complete article »

Grails, Hibernate, Current Session Context

12-Feb-09

Graeme was so kind to help me with this problem. My app worked well with Grails 1.0.4 but not in 1.1-beta3 any more. My first wild guess leading to a HibernateException: contains is not valid without active transactionHibernateException: contains is not valid without active transaction exception was my use of annotated Hibernate classes together with […]

Read the complete article »