henning 01/06/13 06:00:01
Modified: src/java/org/apache/turbine/util SequencedHashtable.java
Log:
Added a bit documentation about the method clash between List and
Collection interface. Added some more documentation and a small
example to sequence()
Finally got around to rename the UKNOWN_INDEX to UNKNOWN_INDEX. ;-)
Revision Changes Path
1.10 +27 -7
jakarta-turbine/src/java/org/apache/turbine/util/SequencedHashtable.java
Index: SequencedHashtable.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/SequencedHashtable.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SequencedHashtable.java 2001/06/11 20:29:42 1.9
+++ SequencedHashtable.java 2001/06/13 13:00:00 1.10
@@ -68,8 +68,16 @@
* which they were added in. This class is thread safe.
* <p>
* Implementing the List interface is not possible due to a instance
- * method name clash. Java does not support method renaming.
- * <p>
+ * method name clash between the Collection and the List interface:
+ *
+ * <table>
+ * <tr><td>Collections</td><td>boolean remove(Object o)</td></tr>
+ * <tr><td>Lists</td><td>Object remove(Object o)</td></tr>
+ * </table>
+ *
+ * So one cannot implement both interfaces at the same, which is unfortunate
+ * because the List interface would be very nice in conjuction with Velocity.
+ *
* A slightly more complex implementation and interface could involve
* the use of a list of <code>Map.Entry</code> objects.
*
@@ -86,7 +94,7 @@
/**
* Indicator for an unknown index.
*/
- private static final int UKNOWN_INDEX = -1;
+ private static final int UNKNOWN_INDEX = -1;
/**
* The sequence used to keep track of the hash keys. Younger objects are
@@ -179,6 +187,18 @@
/**
* Returns the ordered sequence of keys.
*
+ * This method is meant to be used for retrieval of Key / Value pairs
+ * in e.g. Velocity:
+ * <PRE>
+ * ## $table contains a sequenced hashtable
+ * #foreach ($key in $table.sequence())
+ * <TR>
+ * <TD>Key: $key</TD>
+ * </TD>Value: $table.get($key)</TD>
+ * </TR>
+ * #end
+ * </PRE>
+ *
* @return The ordered list of keys.
*/
public List sequence()
@@ -256,21 +276,21 @@
*/
public Object remove (Object key)
{
- return remove(UKNOWN_INDEX, key);
+ return remove(UNKNOWN_INDEX, key);
}
/**
* Removes the element with the specified key or index.
*
* @param index The index of the object to remove, or
- * <code>UKNOWN_INDEX</code> if not known.
+ * <code>UNKNOWN_INDEX</code> if not known.
* @param key The <code>Map</code> key of the object to remove.
* @return The previous value coressponding the <code>key</code>, or
* <code>null</code> if none existed.
*/
private final synchronized Object remove (int index, Object key)
{
- if (index == UKNOWN_INDEX)
+ if (index == UNKNOWN_INDEX)
{
index = indexOf(key);
}
@@ -278,7 +298,7 @@
{
key = get(index);
}
- if (index != UKNOWN_INDEX)
+ if (index != UNKNOWN_INDEX)
{
keySequence.remove(index);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]