What's new in Commons Lang 2.4?Commons Lang 2.4 is out, and the obvious question is: "So what? What's changed?". This article aims to briefly cover the changes and save you from having to dig through each JIRA issue to see what went on in the year of development between Lang 2.3 and 2.4. DeprecationsFirst, let us start with a couple of deprecations. As you can see in the release notes, we chose
to deprecate the We also deprecated The buildBefore we move on, a quick note on the build: we built 2.4 using Maven 2 and Java 1.4. We also tested that the Ant build passed the tests successfully under Java 1.3, and that the classes compiled under Java 1.2. As it's been so long, we stopped building a Java 1.1-compatible jar. Most importantly, it should be a drop in replacement for Lang 2.3, but we recommend testing first, of course. Also, for those of you who work within an OSGi framework, the jar should be ready for OSGi. Now... time to move on. New classesThree new classes were added, so let's cover those next. Firstly, we added an Second and third on our newcomers list are the Together they allow you to take the
By way of an example, imagine that we have a need for custom formatting of an employee identification
number or EIN. Perhaps, simplistically, our EIN is composed of a two-character department code
followed by a four-digit number, and that it is customary within our organization to render the EIN
with a hyphen following the department identifier. Here we'll represent the EIN as a simple
String (of course in real life we would likely create a class composed of department and number).
We can create a custom
MessageFormat -style processing by a
FormatFactory implementation:
java.util.Map<String, FormatFactory> registry (keyed
by format type) to ExtendedMessageFormat :
"EIN: AA-9999" .
If we wanted to trigger the EIN masking code, we could trigger that in the format pattern:
"EIN: AA-####" .
You can also use ExtendedMessageFormat to override any or all of the built-in
formats supported by java.text.MessageFormat . Finally, note that because
ExtendedMessageFormat extends MessageFormat it should work in most
cases as a true drop-in replacement.
New methodsThere were 58 new methods added to existing Commons Lang classes. Going through each one, one at a time would be dull, and fortunately there are some nice groupings that we can discuss instead: CharSet getInstance(String[]) adds an additional builder method by which you can build a CharSet from multiple sets of characters at the same time. If you weren't aware of the CharSet class, it holds a set of characters created by a simple pattern language allowing constructs such as ClassUtils canonical name methods are akin to the non ' ClassUtils toClass(String[]) is very easy to explain - it calls ClassUtils wrapper->primitive conversions are the reflection of the pre-existing ObjectUtils identityToString(StringBuffer, Object) is the StringBuffer variant of the pre-existing StringEscapeUtils CSV methods are a new addition to our range of simple parser/printers. These, quite as expected, parse and unparse CSV text as per RFC-4180. StringUtils has a host of new methods, as always, and we'll leave these for later. WordUtils abbreviate finds the first space after the lower limit and abbreviates the text. math.IntRange/LongRange.toArray turn the range into an array of primitive text.StrMatch.isMatch(char[], int) is a helper method for checking whether there was a match with the StrMatcher objects. time.DateFormatUtils format(Calendar, ...) provide Calendar variants for the pre-existing format methods. If these are new to you, they are helper methods to formatting a date. time.DateUtils getFragment* methods are used to splice the time element out of Date. If you have time.DateUtils setXxx methods round off our walk through the methods - the setXxx variant of the existing addXxx helper methods. StringUtils methodsThe
Hopefully they are in many cases self-describing. Rather than spend a lot of time describing them, we'll let you read the Javadoc of the ones that interest you. What's fixed in Lang 2.4?In addition to new things, there are the bugfixes. As you can tell from the release notes, there are a good few - 24 in fact according to JIRA. Here are some of the interesting ones:
So long, farewell...Hopefully that was all of interest. Don't forget to download Lang 2.4, or, for the Maven repository users, upgrade your <version> tag to 2.4. Please feel free to raise any questions you might have on the mailing lists, and report bugs or enhancements in the issue tracker. |