You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2004/11/08 10:31:15 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/common ScopeTokenizer.java
luetzkendorf 2004/11/08 01:31:15
Modified: src/share/org/apache/slide/common ScopeTokenizer.java
Log:
small optimization using StringBuffer instead of string concatenation + cosmetics.
Revision Changes Path
1.8 +30 -35 jakarta-slide/src/share/org/apache/slide/common/ScopeTokenizer.java
Index: ScopeTokenizer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/ScopeTokenizer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ScopeTokenizer.java 28 Jul 2004 09:38:16 -0000 1.7
+++ ScopeTokenizer.java 8 Nov 2004 09:31:15 -0000 1.8
@@ -65,14 +65,13 @@
this.slideToken = slideToken;
this.namespace = namespace;
- String courScope = new String();
-
scopes.insertElementAt("/", 0);
// We parse the token list and build the scope String objects.
+ StringBuffer b = new StringBuffer(uri.length());
while(super.hasMoreTokens()) {
- courScope = courScope + "/" + super.nextToken();
- scopes.insertElementAt(courScope, 0);
+ b.append("/").append(super.nextToken());
+ scopes.insertElementAt(b.toString(), 0);
}
pos = 0;
@@ -107,20 +106,20 @@
/**
* Tokens container.
*/
- Vector scopes;
+ private Vector scopes;
/**
* Cursor position in the token container.
*/
- int pos;
+ private int pos;
/**
* Namespace.
*/
- Namespace namespace;
- SlideToken slideToken;
+ private Namespace namespace;
+ private SlideToken slideToken;
// --------------------------------------------------------- Public Methods
@@ -166,20 +165,19 @@
* @return Object
* @exception NoSuchElementException
*/
- public Object nextElement()
- throws NoSuchElementException {
- Object obj = null;
- try {
- if (!hasMoreElements()) {
- throw new NoSuchElementException();
+ public Object nextElement() throws NoSuchElementException {
+ Object obj = null;
+ try {
+ if (!hasMoreElements()) {
+ throw new NoSuchElementException();
+ }
+ obj = scopes.elementAt(pos);
+ pos = pos + 1;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Should NEVER happen.
+ e.printStackTrace();
}
- obj = scopes.elementAt(pos);
- pos = pos + 1;
- } catch (ArrayIndexOutOfBoundsException e) {
- // Should NEVER happen.
- e.printStackTrace();
- }
- return obj;
+ return obj;
}
@@ -189,9 +187,8 @@
* @return String
* @exception NoSuchElementException
*/
- public String nextToken()
- throws NoSuchElementException {
- return (String) nextElement();
+ public String nextToken() throws NoSuchElementException {
+ return (String) nextElement();
}
@@ -201,9 +198,8 @@
* @return Scope
* @exception NoSuchElementException
*/
- public Scope nextScope()
- throws NoSuchElementException {
- return new Scope(nextToken());
+ public Scope nextScope() throws NoSuchElementException {
+ return new Scope(nextToken());
}
@@ -213,9 +209,8 @@
* @param delim
* @exception NoSuchElementException
*/
- public String nextToken(String delim)
- throws NoSuchElementException {
- return nextToken();
+ public String nextToken(String delim) throws NoSuchElementException {
+ return nextToken();
}
@@ -225,7 +220,7 @@
* @return Enumeration
*/
public Enumeration elements() {
- return scopes.elements();
+ return scopes.elements();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org