What's new in Commons Lang 3.0?Commons Lang 3.0 is out, and the obvious question is: "So what? What's changed?". The big storyLang is now Java 5 based. We've generified the API, moved certain APIs to support To that end we have changed the package name, allowing Lang 3.0 to sit side-by-side with your previous version of Lang without any bad side effects. The new package name is the exciting and original As you'd expect, there are also new features, enhancements and bugs fixed. Migrating from 2.xJava codeDespite the label of backwards incompatibility, in the vast majority of cases the simple addition of a Change: Maven
What's gone?Enum packageJava 5 provided enums out of the box, therefore we dispensed with both the deprecated enum package, and the enums package. Instead you should migrate over to the standard Java enum. An EnumUtils class has been born from the ashes of the old code, focused on providing additional functionality to the standard Java enum API. NestedExceptionsIn Java 1.4, the notion that all Throwables could be linked to a cause was introduced. In Lang we had provided a NestedException framework to support the same feature, and now that we're jumping from Java 1.3 to Java 5 we are remove this feature. The deprecation section below covers one part of ExceptionUtils that remains until we are on Java 6, where the last remaining parts of the JDK appear to have embraced the new cause API. JVMRandomThis class was introduced in Lang 2.0 to support a Random object built around the system seed. This proved to be both an uncommon use case and one with bugs and so was dropped. StringEscapeUtils.escapeSqlThis was a misleading method, only handling the simplest of possible SQL cases. As SQL is not Lang's focus, it didn't make sense to maintain this method. *Exceptions removedVarious Exception classes were removed - the lesson in defining more semantically relevant exception classes is that you can keep on coming up with more and more new classes. Simpler to focus on using the main JDK classes. math.*RangeThe various Range classes in the Previous DeprecationsAll deprecated fields/methods/classes - with a new major version, all of the previously deprecated parts of the API could finally go away. If you feel that something was unfairly taken away, please feel free to contact the list. In many cases the possibility exists to reintroduce code. DeprecationsThe lone deprecation in 3.0 is that of the notion of 'cause method names' in ExceptionUtils. In Java 5.0 it is still just about needed to handle some JDK classes that have not been migrated to the getCause API. In Java 6.0 things appear to be resolved and we will remove the related methods in Lang 4.0. New packagesTwo new packages have shown up. org.apache.commons.lang3.concurrent, which unsurprisingly provides support classes for multithreaded programming, and org.apache.commons.lang3.text.translate, which provides a pluggable API for text transformation. concurrent.*Java 1.5 adds a great bunch of functionality related to multithreaded programming
below the The classes located in the
Classes of the former category provide some basic functionality a developer
typically has to implement manually again and again. Examples are a configurable
Initializer classes deal with the creation of objects in a multithreaded
environment. There are several variants of initializer implementations serving
different purposes. For instance, there are a couple of concrete initializers
supporting lazy initialization of objects in a safe way. Another example is
public class DBInitializer extends BackgroundInitialize<EntityManagerFactory> { protected EntityManagerFactory initialize() { return Persistence.createEntityManagerFactory("mypersistenceunit"); } } An application creates an instance of the DBInitializer init = new DBInitializer(); init.start(); // now do some other stuff EntityManagerFactory factory = ConcurrentUtils.initializeUnchecked(init); Comprehensive documentation about the text.translate.*A common complaint with StringEscapeUtils was that its escapeXml and escapeHtml methods should not be escaping non-ASCII characters. We agreed and made the change while creating a modular approach to let users define their own escaping constructs. The simplest way to show this is to look at the code that implements escapeXml: return ESCAPE_XML.translate(input); Very simple. Maybe a bit too very simple, let's look a bit deeper. public static final CharSequenceTranslator ESCAPE_XML = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_ESCAPE()), new LookupTranslator(EntityArrays.APOS_ESCAPE()) ); Here we see that StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) ); That takes the standard Commons Lang provided escape functionality, and adds on another translation layer. Another JIRA requested option was to also escape non-printable ASCII, this is now achievable with a modification of the above: StringEscapeUtils.ESCAPE_XML.with( new AggregateTranslator( NumericEntityEscaper.between(0, 31), NumericEntityEscaper.between(0x80, Integer.MAX_VALUE) ) ) You can also implement your own translators (be they for escaping, unescaping or some aspect of your own). See the New classes + methodsThere are many new classes and methods in Lang 3.0 - the most complete way to see the changes is via this Lang2 to Lang3 Clirr report. Here is a summary of the new classes:
Bugfixes?See the 3.0 changes report for the list of fixed bugs and other enhancements. Other Notable Changes
|