|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.util.Resolver
public class Resolver
This is used to match String
's with the first pattern
that String
matches. A pattern consists of characters
with either the '*' or '?' characters as wild characters. The '*'
character is completely wild meaning that is will match nothing or
a long sequence of characters. The '?' character matches a single
character.
If the '?' character immediately follows the '*' character then the match is made as any sequence of characters up to the first match of the next character. For example "/*?/index.jsp" will match all files preceeded by only a single path. So "/pub/index.jsp" will match, however "/pub/bin/index.jsp" will not, as it has two paths. So, in effect the '*?' sequence will match anything or nothing up to the first occurence of the next character in the pattern.
A design goal of the Resolver
was to make it capable
of high performance in a multithreaded environment. In order to
achieve a high performance the Resolver
can cache the
resolutions it makes so that if the same text is given to the
Resolver.resolve
method a cached result can be retrived
quickly which will decrease the length of time a thread occupies the
synchronized method. The cache used is a CacheList
.
The semantics of the resolver are such that the last pattern inserted
with a wild string is the first one checked for a match. This means
that if a sequence of insertions like insert(a,b)
insert(x,y)
is made and then a resolve(z)
is attemped then z will be compared to x first and then a, if z
matches x then y is given as the result and if z matches a then b
will be returned, remember if z matches both a and x then y will be
the result due to the fact that is was the last pattern inserted.
CacheList
,
Serialized FormConstructor Summary | |
---|---|
Resolver()
The default constructor will create a Resolver
without a large cache size. |
|
Resolver(int size)
This constructor allows resolves to be cached for increased performance. |
Method Summary | |
---|---|
void |
clear()
This is used to clear all matches from the resolver. |
boolean |
contains(Match match)
This will check this Resolver to see if the
match given is used by this Resolver , if it
is this will return true . |
boolean |
contains(java.lang.String pattern)
This will check this Resolver to see if the
pattern given is used by this Resolver , if
it is this will return true . |
Match |
getMatch(int pos)
This will return the corrosponding Match at
the specified position. |
Match |
getMatch(java.lang.String pattern)
This will return the corrosponding Match at
the specified position. |
Match[] |
getMatches()
Retrives an array of Match 's of each pair that
was entered into this Resolver . |
int |
indexOf(java.lang.String pattern)
Used to find the position of the Match
stored using the specified pattern. |
int |
indexOf(java.lang.String pattern,
int from)
Used to find the position of the Match
stored using the specified pattern. |
void |
insert(java.lang.String pattern,
java.lang.String match)
This will add a new pattern with its resolution. |
void |
insert(java.lang.String pattern,
java.lang.String match,
int pos)
This will add a new pattern with its resolution. |
boolean |
isEmpty()
This can be used to determine wheather or not there is any entrys in the Resolver . |
void |
remove(int pos)
This will remove the entry in this Resolver so that
the pattern will not be used to resolve String 's any
more. |
void |
remove(Match match)
This will remove the entry in this Resolver so that
the pattern will not be used to resolve String 's any
more. |
void |
remove(java.lang.String pattern)
This will remove the entry in this Resolver so that
the pattern will not be used to resolve String 's any
more. |
java.lang.String |
resolve(java.lang.String text)
This will search the patterns in this Resolver to
see if there is a pattern in it that matches the string given. |
int |
size()
This will return the number of entrys that have been inserted into this Resolver . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Resolver()
Resolver
without a large cache size. This is intended for use when
the requests for resolve
tend to use strings
that are reasonably similar. If the strings issued to this
instance are dramatically different then the cache tends
to be an overhead rather than a bonus.
public Resolver(int size)
If a caching is done then an CacheList
is used.
This is a transient object so that when this instance of the
Resolver
is serialized list is cleared.
size
- if this is true the caching of resolves is done
using a CacheList
Method Detail |
---|
public java.lang.String resolve(java.lang.String text)
Resolver
to
see if there is a pattern in it that matches the string given.
This will search the patterns from the last entered pattern to
the first entered. So that the last entered patterns are the
most searched patterns and will resolve it first if it matches.
Although it is criticial that this perform well this method
is synchronized. The reasnon for this is that if there was
several threads modifing the Resolver
at the same
time ConcurrentModificationException
exceptions
would be thrown this would reduce the usefulness of this object.
text
- this is the String
to be resolved
String
that pattern
resolves topublic void insert(java.lang.String pattern, java.lang.String match)
resolve
method is
invoked. This inserts the pair at the end of the list and so
it will be the first pattern checked. If the match is an
empty string then there is not insertion made.
pattern
- this is the pattern that will resolve thismatch
- the String
returned when a correct
match is made
java.lang.NullPointerException
- if either string is nullpublic void insert(java.lang.String pattern, java.lang.String match, int pos)
resolve
method is
invoked. This will insert the pair into the position specified.
This behaves like the Vector.insertElementAt
method, by bumping all entrys up one position. If the match is
an empty string then there is not insertion made.
pattern
- this is the pattern that will resolve thismatch
- the String
returned when a correct
match is madepos
- this is the position to insert the pair into
java.lang.NullPointerException
- if either string is nullpublic void remove(int pos)
Resolver
so that
the pattern will not be used to resolve String
's any
more. This behaves like the Vector.removeElementAt
.
pos
- this is the position that is removed from thispublic void remove(java.lang.String pattern)
Resolver
so that
the pattern will not be used to resolve String
's any
more. If the wild string is parameter is null
then
there is a NullPointerException
. This behaves like
the Vector.removeElementAt
method.
pattern
- this is the pattern that is removed from thispublic void remove(Match match)
Resolver
so that
the pattern will not be used to resolve String
's any
more. If the wild string is parameter is null
then
there is a NullPointerException
. This will only use
the Match.getPattern
to remove the match. This is a
convienence method that it can be used with getMatches
.
match
- this is the match that is removed from thispublic Match[] getMatches()
Match
's of each pair that
was entered into this Resolver
. The elements in
the array are ordered to represent the order they were made.
Match
objects that existpublic Match getMatch(int pos)
Match
at
the specified position. This can be used in conjunction
with the indexOf
method to remove matches.
pos
- the position Match
to retrive
public Match getMatch(java.lang.String pattern)
Match
at
the specified position. This can be used in conjunction
with the indexOf
method to remove matches.
This is a convienence method that avoids having to use
the indexOf
method.
pattern
- the position Match
to retrive
public int indexOf(java.lang.String pattern)
Match
stored using the specified pattern. This operates in a
similar way to the Vector.indexOf
method.
pattern
- the pattern that the Match
is stored using
public int indexOf(java.lang.String pattern, int from)
Match
stored using the specified pattern. This operates in a
similar way to the Vector.indexOf
method.
pattern
- the pattern that the Match
is stored usingfrom
- this starts checking from this position
public boolean contains(java.lang.String pattern)
Resolver
to see if the
pattern given is used by this Resolver
, if
it is this will return true
.
pattern
- the pattern that is used resolving
String
's
true
if this pattern
exists in this Resolver
public boolean contains(Match match)
Resolver
to see if the
match given is used by this Resolver
, if it
is this will return true
.
match
- this is a specific match and pattern pair
true
if this match
exists in this Resolver
public boolean isEmpty()
Resolver
. If this Resolver
is empty this will return true, there must be at
least one entry in the Resolver
.
true
is there are no elementspublic int size()
Resolver
. This uses the Vector
's
size
implementation to determine the number of entrys.
public void clear()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |