From d528509c82ab56cc76d827b30834b51f948e4d01 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Mon, 6 Sep 2004 00:41:02 +0000 Subject: [PATCH] added classes to write about git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137928 13f79535-47bb-0310-9956-ffa450edef68 --- xdocs/userguide.xml | 59 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/xdocs/userguide.xml b/xdocs/userguide.xml index a35236eda..6e5594c81 100644 --- a/xdocs/userguide.xml +++ b/xdocs/userguide.xml @@ -95,10 +95,24 @@ limitations under the License.
+

When you write a hashcode, do you check Bloch's Effective Java? No? You just hack in a quick number? Well HashCodeBuilder will save your day. It, and its buddies (EqualsBuilder, CompareToBuilder, ToStringBuilder), take care of the nasty bits while you focus on the important bits, like which fields will go into making up the hashcode.

-
+
+

Enums are an old C thing. Very useful. One of the major uses is to give type to your constants, and even more, to give them order. For example:

A simple Enum
@@ -124,24 +138,65 @@ public final class ColorEnum extends Enum {
+

JDK 1.4 brought us NestedExceptions, that is an Exception which can link to another Exception. This subpackage provides it to those of us who have to code to something other than JDK 1.4 (most reusable code libaries are aimed at JDK 1.2).

It isn't just a nested exception framework though, it uses reflection to allow it to handle many nested exception frameworks, including JDK 1.4's.

The reflection ability is one of the more interesting tricks hidden in the reflection sub-package, and of much use to writers of applications such as Tomcat or IDEs, in fact any code which has to catch 'Exception' from an unknown source and then wanting to display in a novel way.

+

Although Commons-Math also exists, some basic mathematical functions are contained within Lang. These include classes to represent ranges of numbers, a Fraction class, various utilities for random numbers, and the flagship class, NumberUtils which contains a handful of classic number functions.

There are two aspects of this package I would like to highlight. The first is NumberUtils.createNumber(String), a method which does its best to convert a String into a Number object. You have no idea what type of Number it will return, so you should call the relevant xxxValue method when you reach the point of needing a number. NumberUtils also has a related isNumber method. The second is the JVMRandom class. This is an instance of Random which relies on the Math.random() method for its implementation and so gives the developer access to the JVM's random seed. If you try to create Random objects in the same millisecond, they will give the same answer; so quickly you will find yourself caching that Random object. Rather than caching your own object, simply use the one the JVM is caching already. The RandomUtils provides a static access to the JVMRandom class, which may be easier to use.

+
-

Lang 2.0 saw the arrival of a time package. It contains some basic utilities for manipulating time (a delorean, police box and [hgwells lookup needed]?). These include a StopWatch for simple performance measurements and an optimised FastDateFormat class.

+ +

Lang 2.0 saw the arrival of a time package. It contains some basic utilities for manipulating time (a delorean, police box and grandfather clock?). These include a StopWatch for simple performance measurements and an optimised FastDateFormat class.

+