linked in userguide, though it needs work
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b764c11070
commit
64fa7bc607
|
@ -30,7 +30,7 @@ limitations under the License.
|
|||
|
||||
<menu name="Commons Lang">
|
||||
<item name="Overview" href="/index.html"/>
|
||||
<!--item name="Users guide" href="/userguide.html"/-->
|
||||
<item name="Users guide" href="/userguide.html"/>
|
||||
<item name="Javadoc (2.0 release)" href="api/index.html"/>
|
||||
<item name="Mailing lists" href="/mail-lists.html"/>
|
||||
<item name="Team" href="/team-list.html"/>
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright 2002-2004 The Apache Software Foundation.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Commons Lang - Users guide</title>
|
||||
<author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
|
||||
<section name="Description">
|
||||
<p>The Commons Lang library provides much needed additions to the standard JDK's java.lang package. Very generic, very reusable components for everyday use.</p>
|
||||
<p>The top level package contains various Utils classes, whilst there are various subpackages including enums, exception and builder. Using the Utils classes is generally simplicity itself. They are the equivalent of global functions in another language, a collection of stand-alone, thread-safe, static methods. In contrast, subpackages contain interfaces which may have to be implemented or classes which may need to be extended to get the full functionality from the code. </p>
|
||||
</section>
|
||||
|
||||
<section name="lang.*">
|
||||
<subsection name="String classes">
|
||||
<p>The first thing for me at the top level is StringUtils. I'm partizan here as it's one of the ones I had a lions share in. Oodles and oodles of functions here which tweak, transform, squeeze and cuddle java.lang.Strings. Throw in RandomStringUtils and CharSetUtils to complete the 'String' trilogy. </p>
|
||||
<p>Most developers have their own, most of them are tiny and small. The Jakarta ones are guaranteed to be used in a larger audience and have subtle issues like using toTitleCase in StringUtils.capitalise and not toUpperCase (Yugoslavians[Bad term now. Research which languages are affected] will thank you). </p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="SystemUtils">
|
||||
<p>SystemUtils is a simple little class which makes it easy to find out information about which platform you are on. For some, this is a necessary evil. It was never something I expected to use myself until I was trying to ensure that Commons Lang itself compiled under JDK 1.2. Having pushed out a few JDK 1.3 bits that had slipped in (Collections.EMPTY_MAP is a classic offender), I then found that one of the Unit Tests was dying mysteriously under JDK 1.2, but ran fine under JDK 1.3. There was no obvious solution and I needed to move onwards, so the simple solution was to wrap that particular test in a 'if(SystemUtils.isJavaVersionAtLeast(1.3f)) {', make a note and move on. </p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="SerializationUtils">
|
||||
<p>Serialization doesn't have to be that hard! A simple util class can take away the pain. Plus it provides a method to clone an object by unserializing and reserializing, an old Java trick.</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="ObjectUtils">
|
||||
<p>Do things to Objects.</p>
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
<section name="lang.enums">
|
||||
<p>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:</p>
|
||||
<h5>A simple Enum</h5>
|
||||
<source>
|
||||
public final class ColorEnum extends Enum {
|
||||
public static final ColorEnum RED = new ColorEnum("Red");
|
||||
public static final ColorEnum GREEN = new ColorEnum("Green");
|
||||
public static final ColorEnum BLUE = new ColorEnum("Blue");
|
||||
|
||||
private ColorEnum(String color) {
|
||||
super(color);
|
||||
}
|
||||
|
||||
public static ColorEnum getEnum(String color) {
|
||||
return (ColorEnum) getEnum(ColorEnum.class, color);
|
||||
}
|
||||
|
||||
public static Iterator iterator() {
|
||||
return iterator(ColorEnum.class);
|
||||
}
|
||||
}
|
||||
</source>
|
||||
<p>The enums package used to be the enum package, but with Java 5 giving us an enum keyword, the move to the enums package name was necessary and the old enum package was deprecated. </p>
|
||||
</section>
|
||||
|
||||
<section name="lang.exception.*">
|
||||
<p>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).</p>
|
||||
<p>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.</p>
|
||||
<p>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.</p>
|
||||
</section>
|
||||
|
||||
<section name="lang.builder.*">
|
||||
<p>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.</p>
|
||||
</section>
|
||||
|
||||
<section name="lang.math.*">
|
||||
<p>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. </p>
|
||||
<p>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. </p>
|
||||
</section>
|
||||
<section name="lang.time.*">
|
||||
<p>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. </p>
|
||||
</section>
|
||||
<section name="Next version of Lang">
|
||||
<p>The next version of Lang will be 2.1. The most notable addition is a mutable package, but there are also new classes such as DurationFormatUtils [and ...]. </p>
|
||||
</section>
|
||||
|
||||
</body>
|
||||
</document>
|
Loading…
Reference in New Issue