de.h2b.taglets
Class CrossRefTable

java.lang.Object
  extended by de.h2b.taglets.CrossRefTable
All Implemented Interfaces:
java.io.Serializable

@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
extends java.lang.Object
implements java.io.Serializable

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.

Since:
h2taglets 0.1
Version:
$Revision: 1.7 $, $Date: 2008/12/14 17:05:37 $
Author:
h2b
See Also:
Serialized Form

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

CrossRefTable

public CrossRefTable()
Creates an empty table.

Since:
h2taglets 0.1

CrossRefTable

public CrossRefTable(java.lang.String path)
Creates a table from an auxiliary file. If the file doesn't exist or an exception occurs during loading, an empty table is created.

Parameters:
path - the pathname of the auxiliary file
Since:
h2taglets 0.1
Method Detail

getIndex

public java.lang.String getIndex(java.lang.String key)
Returns the index associated to a given key in the cross-ref table. If the table does not contain the key already, the latter will be added first.

Parameters:
key - the key whose index is in demand
Returns:
the index associated with the key, counting from 1
Since:
h2taglets 0.1

getReference

public java.lang.String getReference(java.lang.String key)
Returns the index associated to a given key in the cross-ref table. If the table does not contain the key, the key itself will be returned.

Parameters:
key - the key whose index is in demand
Returns:
the index associated with the key, counting from 1, or the key itself if not available
Since:
h2taglets 0.1

save

public void save()
Saves the table to the auxiliary file. If none has been specified during construction, nothing happens.

Since:
h2taglets 0.1


Copyright © 2008 Hans-Hermann Bode, Berlin, Germany. All Rights Reserved.