|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.thebuzzmedia.sjxp.XMLParser.Location
class XMLParser.Location
Simple and fast class used to mock the behavior of a stack in the form of a string for the purposes of "pushing" and "popping" the parser's current location within an XML document as it processes START and END_TAG events.
Performance is optimized by using aStringBuilder
who's length is
chopped (which just adjusts an int
value) to simulate a
"pop" off the top.
System.arraycopy(Object, int, Object, int, int)
) has been
completely removed and replaced with using simple integer hash codes.
The performance improvement is huge over the original toString-based
method of matching IRule
's locationPath
s against the
parser's current location.
Constructor Summary | |
---|---|
XMLParser.Location()
Creates a new empty location. |
Method Summary | |
---|---|
void |
clear()
Used to clear all the internal state of the location. |
Integer |
getCachedHashCode()
Used to get a cached Integer version of the int
hashCode() return value. |
int |
hashCode()
Overridden to calculate the hash code of this location using the exact same hash code calculation that String.hashCode() uses. |
void |
pop()
"Pops" the last pushed path element off the "stack" by re-adjusting the StringBuilder 's length to what it was before the last
element was appended. |
void |
push(String localName,
String namespaceURI)
"Pushes" a new local name and optional namespace URI onto the "stack" by appending it to the current location path that represents the parser's location inside of the XML doc. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLParser.Location()
Method Detail |
---|
public int hashCode()
String.hashCode()
uses.
This allows us to say a String
with the content
"/library/book/title" is equal to an instance of this class
representing the same location when doing lookups in a Map
.
This method calculates the hash code and then caches it, followup
calls to push(String, String)
or pop()
invalidate
the cached hash code allowing it to be recalculated again on the next
call.
hashCode
in class Object
public Integer getCachedHashCode()
Integer
version of the int
hashCode()
return value.
To avoid unnecessary Integer
allocations, this method caches
up to a certain number of Integer
instances, re-using them
every time the same hash code value comes back up and creating new
instances when it doesn't.
If a larger number of Integer
instances are created than the
underlying cache can hold, then a new instance will be created and
returned like normal.
Integer
values for these unique paths is
created and cached, once we re-encounter that path again and again,
we don't need to recreate that hash code Integer
, we can just
use the one from the previous occurrence.
Integer
version of the int
hashCode()
return value.public void clear()
public void push(String localName, String namespaceURI)
localName
- The local name of the tag (e.g. "title").namespaceURI
- Optionally, the full qualifying namespace URI for this
tag.public void pop()
StringBuilder
's length to what it was before the last
element was appended.
This effectively chops the last element off the path without doing a
more costly StringBuilder.delete(int, int)
operation that
would incur a call to
System.arraycopy(Object, int, Object, int, int)
by simply
adjusting a single int
counter inside of
StringBuilder
.
|
Copyright 2011 The Buzz Media, LLC | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |