Author: julien(a)jboss.com
Date: 2007-05-12 18:10:34 -0400 (Sat, 12 May 2007)
New Revision: 7248
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
Log:
cache toString value of PortalObjectId
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2007-05-12
03:53:59 UTC (rev 7247)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2007-05-12
22:10:34 UTC (rev 7248)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.core.model.portal;
-import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.Base64;
@@ -55,6 +54,9 @@
/** The lazy computed hash code. */
private Integer hashCode;
+ /** The lazy computed to string value. */
+ private String toString;
+
public PortalObjectId()
{
this.names = EMPTY_STRINGS;
@@ -71,6 +73,8 @@
public PortalObjectId(PortalObjectId that) throws IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNull(that, "PortalObjectId to be
copied");
+
+ //
this.names = that.names;
this.hashCode = that.hashCode;
this.from = that.from;
@@ -86,6 +90,8 @@
public PortalObjectId(String[] names) throws IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNull(names, "composing
names");
+
+ //
this.names = names;
this.from = 0;
this.to = names.length;
@@ -100,20 +106,13 @@
private PortalObjectId(String[] names, int from, int to) throws
IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNull(names, "composing
names");
+
+ //
this.names = names;
this.from = from;
this.to = to;
}
- public PortalObjectId blah() throws IllegalStateException
- {
- if (from == to)
- {
- throw new IllegalStateException();
- }
- return new PortalObjectId(names, from + 1, to);
- }
-
/**
* Build an id by parsing a string representation.
*
@@ -124,6 +123,8 @@
public PortalObjectId(String value, Format format) throws IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
+
+ //
this.names = format.parse(value);
this.from = 0;
this.to = names.length;
@@ -232,7 +233,11 @@
/** Returns the canonical representation of the id. */
public String toString()
{
- return CANONICAL_FORMAT.toString(names, from, to);
+ if (toString == null)
+ {
+ toString = CANONICAL_FORMAT.toString(names, from, to);
+ }
+ return toString;
}
/**
@@ -244,6 +249,8 @@
public String toString(Format format)
{
ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
+
+ //
return format.toString(names, from, to);
}
@@ -274,6 +281,8 @@
public final String toString(PortalObjectId id) throws IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNull(id,
"PortalObjectId");
+
+ //
return toString(id.names, id.from, id.to);
}
}
@@ -363,6 +372,8 @@
public String[] parse(String value)
{
ParameterValidation.throwIllegalArgExceptionIfNull(value, "value");
+
+ //
if (value.length() == 0)
{
return EMPTY_STRING_ARRAY;
@@ -396,10 +407,14 @@
public String toString(String[] names, int from, int to)
{
ParameterValidation.throwIllegalArgExceptionIfNull(names, "name string
array");
+
+ //
if (from == to)
{
return "";
}
+
+ //
StringBuffer buffer = new StringBuffer((to - from) * 8);
for (int i = from; i < to; i++)
{