Adding String lazy caching

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@899895 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-01-16 07:58:11 +00:00
parent 5be7671ea1
commit 8860c37b9d
1 changed files with 30 additions and 8 deletions

View File

@ -28,12 +28,32 @@
*/
public final class Range<T> implements Serializable {
/**
* Required for serialization support.
*
* @see java.io.Serializable
*/
private static final long serialVersionUID = 1L;
/**
* The ordering scheme used in this range.
*/
private final Comparator<T> comparator;
/**
* The minimum value in this range (inclusive).
*/
private final T minimum;
/**
* The maximum value in this range (inclusive).
*/
private final T maximum;
/**
* Cached output toString (class is immutable).
*/
private transient String toString = null;
/**
* <p>Constructs a new <code>Range</code> using the specified
* element as both the minimum and maximum in this range.</p>
@ -320,16 +340,18 @@ public int hashCode() {
*/
@Override
public String toString() {
StringBuilder buf = new StringBuilder(32);
buf.append("Range[");
buf.append(this.minimum);
buf.append(',');
buf.append(this.maximum);
buf.append(']');
return buf.toString();
if (toString == null) {
StringBuilder buf = new StringBuilder(32);
buf.append("Range[");
buf.append(this.minimum);
buf.append(',');
buf.append(this.maximum);
buf.append(']');
toString = buf.toString();
}
return toString;
}
// Taken from Commons Collections - documentation removed as not a public class
private static class ComparableComparator<E extends Comparable<? super E>> implements Comparator<E>, Serializable {