|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectau.id.pbw.hyfo.hyph.HyphenationTreeCache
public class HyphenationTreeCache
A singleton class which caches instances of HyphenationTree
.
Such instances are located using a Locale
-style identifier. Such
identifiers are made up of one or more components. The identifier is
normalized before a search. The search proceeds by looking for an instance
matching all components, in order, then stripping the last component and
searching again, until a match is found, or the components are exhausted.
The results, including failures, for all searches are cached to eliminate
unnecessary searches.
Each of thee search components is a prefix of the original identifier.
Aliases may be added to the HyphenationTreeCache
, but all cached
information will be cleared when an alias is installed. If, for example,
trees for en_US and en_GB are available, it may be desirable
to add an alias for en, to enable a shortened Locale
to be
associated with a hyphenation tree. There is otherwise no reliable way to
form such an association.
Field Summary | |
---|---|
protected Logger |
log
The Logger instance for the cache. |
Method Summary | |
---|---|
HyphenationTree |
add_alias(String alias,
String locale)
Adds the given alias for the given Locale -like string,
and returns the HyphenationTree corresponding to the Locale ,
if one exists. |
protected HyphenationTree |
check_prefix(String locale,
String prefix,
List<String> not_found_yet)
Gets the HyphenationTree matched by the the prefix of
locale . |
protected HyphenationTree |
failure(String id,
List<String> not_found_yet)
Adds all of the elements of the argument list to the failed map,
and returns null . |
static HyphenationTreeCache |
get_cache_instance()
Returns the singleton instance of the cache, creating an instance if one does not currently exist. |
HyphenationTree |
get_hyphenation_tree(String locale)
Gets the HyphenationTree corresponding to the given locale
argument, or null if none is found. |
protected String |
next_prefix(String super_prefix)
Returns the next prefix of super_prefix , derived by stripping
the last underscore-separated element off super_prefix . |
protected String |
normalized_locale(String locale)
Normalizes the Locale -like identifier. |
void |
reset_aliases()
Creates a new, empty instance of aliases . |
void |
reset_cache_searches()
Creates new, empty instances of matches ,
superstring_matches and failed . |
void |
reset_cache()
Creates new, empty instances of matches ,
superstring_matches , failed and aliases . |
protected HyphenationTree |
success(String locale,
String prefix,
HyphenationTree tree,
List<String> not_found_yet)
Adds the prefix , mapped to locale , to the
matches map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Logger log
Logger
instance for the cache.
Method Detail |
---|
public static HyphenationTreeCache get_cache_instance()
public HyphenationTree get_hyphenation_tree(String locale) throws IOException
HyphenationTree
corresponding to the given locale
argument, or null
if none is found.
locale
- the Locale
-like identifier to serach for.
HyphenationTree
or null
.
IOException
- if an IO error occurs durng the search for a tree.protected HyphenationTree check_prefix(String locale, String prefix, List<String> not_found_yet) throws IOException
HyphenationTree
matched by the the prefix
of
locale
. If such a match is found, adds the prefix
,
mapped to locale
, to the matches
map. Adds all
elements of not_found_yet to superstring_matches
, mapped
to prefix
. If no such match is found, returns null
.
locale
- the original Locale
-like identifier.prefix
- the prefix
of locale
which is being checked.not_found_yet
- list of super-prefixes of prefix
which have not been matched.
HyphenationTree
or null
, if no match for
this prefix
.
IOException
- if the attempt to deserialize a matched HyphenationTree
fails.protected String next_prefix(String super_prefix)
super_prefix
, derived by stripping
the last underscore-separated element off super_prefix
. If
there is no such prefix, returns null
.
super_prefix
- the original prefix to be stripped fo its last element.
null
.protected HyphenationTree success(String locale, String prefix, HyphenationTree tree, List<String> not_found_yet)
prefix
, mapped to locale
, to the
matches
map. Adds all elements of not_found_yet to
superstring_matches
, mapped to prefix
.
Returns tree
.
locale
- the original Locale
-like identifier.prefix
- the matched prefix
of locale
.tree
- the HyphenationTree
matched by prefix
.not_found_yet
- the list of super-prefixes of prefix
for which no match was found.
tree
.protected HyphenationTree failure(String id, List<String> not_found_yet)
failed
map,
and returns null
.
id
- the original search Locale
-like string.not_found_yet
- the list of prefixes of id for which a match wsa not found; that is, all
preixes.
Null
.public HyphenationTree add_alias(String alias, String locale) throws IOException
alias
for the given Locale
-like string,
and returns the HyphenationTree
corresponding to the Locale
,
if one exists. If not, the alias
is not added, and null
is returned.
alias
- the alias to add.locale
- the string to map alias
to.
HyphenationTree
corresponding to the Locale
,
or null
.
IOException
- if an IO error occurs while trying to locate the aliased tree.public void reset_cache_searches()
matches
,
superstring_matches
and failed
.
public void reset_aliases()
aliases
.
public void reset_cache()
matches
,
superstring_matches
, failed
and aliases
.
protected String normalized_locale(String locale)
Locale
-like identifier. All instances of '-' are
replaced with an underscore. Note that no case changing occurs.
locale
- the string to normalize.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |