You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/03/31 10:56:42 UTC
svn commit: r760371 -
/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java
Author: jalkanen
Date: Tue Mar 31 08:56:40 2009
New Revision: 760371
URL: http://svn.apache.org/viewvc?rev=760371&view=rev
Log:
Allows now direct comparisons with String.
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java?rev=760371&r1=760370&r2=760371&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java Tue Mar 31 08:56:40 2009
@@ -26,6 +26,9 @@
* A WikiName represents a combination of a WikiSpace as well as a
* path within that space. For example, in "MyWiki:MainPage/foo.jpg",
* "MyWiki" is the space, and "MainPage/foo.jpg" is the path within that space.
+ * <p>
+ * A WikiName is a static object which cannot be changed after it has been
+ * created.
*
* @since 3.0
*/
@@ -34,6 +37,7 @@
private static final long serialVersionUID = 1L;
private String m_space;
private String m_path;
+ private String m_stringRepresentation = null;
private WikiName()
{}
@@ -143,17 +147,26 @@
*/
public String toString()
{
- return m_space+":"+m_path;
+ //
+ // The String representation is cached for maximum speed
+ // and object creation overhead.
+ //
+ if( m_stringRepresentation == null )
+ m_stringRepresentation = m_space+":"+m_path;
+
+ return m_stringRepresentation;
}
/**
- * {@inheritDoc}
+ * The hashcode of the WikiName is exactly the same as the hashcode
+ * of its String representation. This is to fulfil the general
+ * contract of equals().
*
* @return int
*/
public int hashCode()
{
- return m_space.hashCode() ^ m_path.hashCode();
+ return toString().hashCode();
}
/**
@@ -169,7 +182,9 @@
/**
* A WikiName is equal to another WikiName if the space and the path
- * match.
+ * match. A WikiName can also be compared to a String, in which case
+ * a WikiName is equal to the String if its String representation is
+ * the same. This is to make it easier to compare.
*
* @param o The Object to compare against.
* @return True, if this WikiName is equal to another WikiName.
@@ -182,6 +197,10 @@
return m_space.equals( n.m_space ) && m_path.equals( n.m_path );
}
+ else if( o instanceof String )
+ {
+ return toString().equals( o );
+ }
return false;
}
}