Entries tagged "Tech" ↓

Java: Type safe character set

If you are working on strings and want to make sure that they conform to a certain character set and are encoded with a certain encoding scheme you will come across the standard Java class Charset that outlines various character sets that should be available in every implementation of the JVM. Instead of scattering magic strings like “UTF-8″ all over your code and catching UnsupportedEncodingException I came up with an enum that encapsulates all this.

Continue reading →

Wicket: Internationalization for enums

There are various nice tutorials available on how you would add internationalization to enum values. Some of them seem outdated because using a class called EnumChoiceRenderer – which is packaged with Wicket now – makes it very easy to, e.g., display the translated values of enums with a drop down box.

Continue reading →

Java: Type safe MessageDigest

The standard Java class MessageDigest can be used to return instances for various message digest algorithms. Implementing a simple factory helps you to return these instances in a type safe way without magic strings and preventing catch blocks with NoSuchAlgorithmException in your code.

Continue reading →

Steinhaus–Johnson–Trotter implementation in Java

Generally it’s frustrating to read that somebody implemented the Steinhaus–Johnson–Trotter algorithm to generate permutations but doesn’t supply the source code due to the fear that the code could be “copied elsewhere” on the internet. Since I was really interested in permutations for another project I implemented the said algorithm, added a LGPL license to it and published it.

Continue reading →