You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2007/08/27 15:30:57 UTC
svn commit: r570108 -
/xalan/java/trunk/src/org/apache/xpath/objects/XString.java
Author: zongaro
Date: Mon Aug 27 06:30:57 2007
New Revision: 570108
URL: http://svn.apache.org/viewvc?rev=570108&view=rev
Log:
Added an equals(String) method to the XMLString interface. This allows the
caller to compare an XMLString to a Java String without forcing the XMLString
to be converted to a String.
In this particular class (XString), modified equals(XMLString) to take advantage
of the new XMLString.equals(String). If the argument for the comparison
contains a java.lang.String, then comparing that with the String held by this
XString is likely the fastest way to perform the comparison; otherwise, we give
the argument the chance to compare itself natively with the String contained by
this XString.
Part of patch for XALANJ-1243. Reviewed by Brian Minchau (minchau@ca.ibm.com).
Modified:
xalan/java/trunk/src/org/apache/xpath/objects/XString.java
Modified: xalan/java/trunk/src/org/apache/xpath/objects/XString.java
URL: http://svn.apache.org/viewvc/xalan/java/trunk/src/org/apache/xpath/objects/XString.java?rev=570108&r1=570107&r2=570108&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xpath/objects/XString.java (original)
+++ xalan/java/trunk/src/org/apache/xpath/objects/XString.java Mon Aug 27 06:30:57 2007
@@ -320,6 +320,22 @@
}
/**
+ * Compares this string to the specified <code>String</code>.
+ * The result is <code>true</code> if and only if the argument is not
+ * <code>null</code> and is a <code>String</code> object that represents
+ * the same sequence of characters as this object.
+ *
+ * @param obj2 the object to compare this <code>String</code> against.
+ * @return <code>true</code> if the <code>String</code>s are equal;
+ * <code>false</code> otherwise.
+ * @see java.lang.String#compareTo(java.lang.String)
+ * @see java.lang.String#equalsIgnoreCase(java.lang.String)
+ */
+ public boolean equals(String obj2) {
+ return str().equals(obj2);
+ }
+
+ /**
* Compares this string to the specified object.
* The result is <code>true</code> if and only if the argument is not
* <code>null</code> and is a <code>String</code> object that represents
@@ -334,11 +350,14 @@
*/
public boolean equals(XMLString obj2)
{
-
- if (!obj2.hasString())
- return obj2.equals(this);
- else
- return str().equals(obj2.toString());
+ if (obj2 != null) {
+ if (!obj2.hasString()) {
+ return obj2.equals(str());
+ } else {
+ return str().equals(obj2.toString());
+ }
+ }
+ return false;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org