|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.h2b.taglets.CrossRefTable
@ClassLabel(copyright="Copyright (C) 2008 Hans-Hermann Bode", ident="$Id: CrossRefTable.java,v 1.7 2008/12/14 17:05:37 h2b Exp $") public class CrossRefTable
A helper class that provides for a general cross-referencing mechanism.
A cross-referencing table of keys with associated numbers is created. When a key is added to the table, it is ensured that it is not already contained therein, so that the relationship between keys and numbers is unique. Also, numbers are allocated consecutively in accordance with the adding of keys.
Two methods are provided to manage the table's elements. Both return
numbers as a String
for generality.
The method getIndex
always returns a number for a given key;
if it is not already in the table, it will be added first. Also, this is
the only way to add a single element to the table, thus ensuring the
desired uniqueness.
The other method, getReference
, does not change the table.
If the key is not found therein, the key itself is returned. This is
principally useful when implementing a 2-pass referencing system in
conjunction with the save
operation.
The method save
stores the table to an auxiliary file when one
has been specified with the constructor. If the constructor finds such
a file, it will read it in to the table. As mentioned, this supports a
2-pass mechanism where forward references are allowed: just use
getIndex
in places where the original label to be referenced shall
be set and use getReference
anywhere else. In the 1st pass,
forward references cannot be resolved but the key name keeps the document
readable to some extend; after the 2nd pass, everything will be fine.
Constructor Summary | |
---|---|
CrossRefTable()
Creates an empty table. |
|
CrossRefTable(java.lang.String path)
Creates a table from an auxiliary file. |
Method Summary | |
---|---|
java.lang.String |
getIndex(java.lang.String key)
Returns the index associated to a given key in the cross-ref table. |
java.lang.String |
getReference(java.lang.String key)
Returns the index associated to a given key in the cross-ref table. |
void |
save()
Saves the table to the auxiliary file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CrossRefTable()
public CrossRefTable(java.lang.String path)
path
- the pathname of the auxiliary fileMethod Detail |
---|
public java.lang.String getIndex(java.lang.String key)
key
- the key whose index is in demand
public java.lang.String getReference(java.lang.String key)
key
- the key whose index is in demand
public void save()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |