head	1.9;
access;
symbols
	TIGRIS_1_1_0RC2:1.7.2.1
	TIGRIS_1_1_0RC1:1.7.2.1
	TIGRIS_1_1:1.7.2.1.0.2
	TIGRIS_1_0_8:1.7.2.1
	TIGRIS_1_0_8RC3:1.7.2.1
	TIGRIS_1_0_8RC2:1.7.2.1
	TIGRIS_1_0_8RC1:1.7.2.1
	TIGRIS_1_0_7:1.7.2.1
	TIGRIS_1_0_7RC3:1.7.2.1
	TIGRIS_1_0_7RC2:1.7.2.1
	TIGRIS_1_0_7RC1:1.7.2.1
	TIGRIS_1_0_6:1.7.2.1
	TIGRIS_1_0_6RC5:1.7.2.1
	TIGRIS_1_0_6RC4:1.7.2.1
	TIGRIS_1_0_6RC3:1.7.2.1
	TIGRIS_1_0_6RC2:1.7.2.1
	TIGRIS_1_0_6RC1:1.7.2.1
	TIGRIS_1_0_5:1.7.2.1
	TIGRIS_1_0_5RC6:1.7.2.1
	TIGRIS_1_0_5RC5:1.7.2.1
	TIGRIS_1_0_5RC4:1.7.2.1
	TIGRIS_1_0_5RC3:1.7.2.1
	TIGRIS_1_0_5RC2:1.7.2.1
	TIGRIS_1_0_5RC1:1.7.2.1
	TIGRIS_1_0_4:1.7.2.1
	TIGRIS_1_0_3:1.7.2.1
	TIGRIS_1_0_2:1.7.2.1
	TIGRIS_1_0_1:1.7.2.1
	TIGRIS_1_0:1.7.2.1.0.4
	TIGRIS_1_0_0:1.7.2.1
	TIGRIS_1_0_0_RC1:1.7.0.2
	TIGRIS_0_9_2_4:1.3
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.5.0.2
	TURBINE_PEER:1.5
	TIGRIS_0_9_2_1:1.5
	TIGRIS_0_9_2:1.3.0.2;
locks; strict;
comment	@# @;


1.9
date	2001.04.18.22.39.19;	author dlr;	state dead;
branches;
next	1.8;

1.8
date	2001.03.27.22.04.31;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2001.03.26.19.30.59;	author dlr;	state Exp;
branches
	1.7.2.1;
next	1.6;

1.6
date	2001.03.22.01.39.47;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.3;

1.3
date	2001.01.12.21.13.56;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2000.12.21.23.39.17;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2000.12.21.23.38.36;	author dlr;	state Exp;
branches;
next	;

1.5.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	;

1.7.2.1
date	2001.03.28.23.30.13;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.9
log
@SequencedHashtable, BufferCache, and BaseUnicastRemoteService have been moved into Turbine.  Changed references accordingly.
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.tool;

import java.util.*;

/**
 * A <code>Hashtable</code> where keys are sequenced.  The sequenced keys
 * allow easy access to the values in the sequence 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>
 * A slightly more complex implementation and interface could involve the use 
 * of a list of <code>Map.Entry</code> objects.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: SequencedHashtable.java,v 1.8 2001/03/27 22:04:31 dlr Exp $
 */
public class SequencedHashtable extends Hashtable
{
    /**
     * Indicator for an unknown index.
     */
    private static final int UKNOWN_INDEX = -1;

    /**
     * The sequence used to keep track of the hash keys.  Younger objects are
     * kept towards the end of the list.  Does not allow duplicates.
     */
    private LinkedList keySequence;

    /**
     * Creates a new instance with default storage.
     */
    public SequencedHashtable ()
    {
        super();
        keySequence = new LinkedList();
    }

    /**
     * Creates a new instance with the specified storage.
     *
     * @@param size The storage to allocate up front.
     */
    public SequencedHashtable (int size)
    {
        super(size);
        keySequence = new LinkedList();
    }

    /**
     * Clears all elements.
     */
    public synchronized void clear ()
    {
        super.clear();
        keySequence.clear();
    }

    /**
     * Creates a shallow copy of this object, preserving the internal
     * structure by copying only references.  The keys, values, and
     * sequence are not <code>clone()</code>'d.
     *
     * @@return A clone of this instance.  */
    public Object clone ()
    {
        SequencedHashtable seqHash = (SequencedHashtable) super.clone();
        seqHash.keySequence = (LinkedList) keySequence.clone();
        return seqHash;
    }

    /**
     * Returns the key at the specified index.
     */
    public Object get (int index)
    {
        return keySequence.get(index);
    }

    /**
     * Returns the value at the specified index.
     */
    public Object getValue (int index)
    {
        return super.get(get(index));
    }

    /**
     * Returns the index of the specified key.
     */
    public int indexOf (Object key)
    {
        return keySequence.indexOf(key);
    }

    /**
     * Returns a key iterator.
     */
    public Iterator iterator ()
    {
        return keySequence.iterator();
    }

    /**
     * Returns the last index of the specified key.
     */
    public int lastIndexOf (Object key)
    {
        return keySequence.lastIndexOf(key);
    }

    /**
     * Stores the provided key/value pair.  Freshens the sequence of existing
     * elements.
     *
     * @@param key   The key to the provided value.
     * @@param value The value to store.
     * @@return      The previous value for the specified key, or
     *              <code>null</code> if none.
     */
    public synchronized Object put (Object key, Object value)
    {
        Object prevValue = super.put(key, value);
        if (prevValue != null)
        {
            // Freshening existing element's sequence.
            keySequence.remove(key);
        }
        keySequence.add(key);
        return prevValue;
    }

    /**
     * Stores the provided key/value pairs.
     *
     * @@param t The key/value pairs to store.
     */
    public synchronized void putAll (Map t)
    {
        Set set = t.entrySet();
        for (Iterator iter = set.iterator(); iter.hasNext(); )
        {
            Map.Entry e = (Map.Entry)iter.next();
            put(e.getKey(), e.getValue());
        }
    }

    /**
     * Removes the element at the specified index.
     */
    public Object remove (int index)
    {
        return remove(index, null);
    }

    /**
     * Removes the element with the specified key.
     */
    public Object remove (Object key)
    {
        return remove(UKNOWN_INDEX, key);
    }

    /**
     * Removes the element with the specified key or index.
     */
    private final synchronized Object remove (int index, Object key)
    {
        if (index == UKNOWN_INDEX) index = indexOf(key);
        if (key == null) key = get(index);
        if (index != UKNOWN_INDEX) keySequence.remove(index);
        return super.remove(key);
    }

    /**
     * Slightly cheaper implementation of <code>values()</code> method.
     */
    public Collection values ()
    {
        return keySequence;
    }
}
@


1.8
log
@Provided a more useful implementation of clone().
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.7 2001/03/26 19:30:59 dlr Exp $
@


1.7
log
@Handling of LinkedList instance member, keySequence, was incorrect in
remove() (IZ# 3016).  The key value for a given index needed to
retrieved from the sequence list before being removed from said list.
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.6 2001/03/22 01:39:47 dlr Exp $
d108 5
a112 3
     * Performs a shallow clone of the internal structure.  Does not copy keys
     * and values.
     */
d115 2
a116 2
        Object seqHash = super.clone();
        ((SequencedHashtable)seqHash).keySequence = new LinkedList();
@


1.7.2.1
log
@Merged in bug fixes and clean up from HEAD.
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.8 2001/03/27 22:04:31 dlr Exp $
d108 3
a110 5
     * Creates a shallow copy of this object, preserving the internal
     * structure by copying only references.  The keys, values, and
     * sequence are not <code>clone()</code>'d.
     *
     * @@return A clone of this instance.  */
d113 2
a114 2
        SequencedHashtable seqHash = (SequencedHashtable) super.clone();
        seqHash.keySequence = (LinkedList) keySequence.clone();
@


1.6
log
@Added constant denoting an unknown index.
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.5 2001/01/26 18:29:09 edk Exp $
d216 1
a217 1
        if (key == null) key = get(index);
@


1.5
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.3 2001/01/12 21:13:56 dlr Exp $
d68 5
d207 1
a207 1
        return remove(-1, key);
d215 2
a216 2
        if (index == -1) index = indexOf(key);
        if (index != -1) keySequence.remove(index);
@


1.5.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.5 2001/01/26 18:29:09 edk Exp $
@


1.4
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.3
log
@Should not throw an exception when remove(int index, Object key) is
called using a non-existant index.
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.2 2000/12/21 23:39:17 dlr Exp $
@


1.2
log
@Added license.
@
text
@d63 1
a63 1
 * @@version $Id: SequencedHashtable.java,v 1.1 2000/12/21 23:38:36 dlr Exp $
d211 1
a211 1
        keySequence.remove(index);
@


1.1
log
@A Hashtable where keys are sequenced.  The sequenced keys allow easy
access to the values in the sequence which they were added in.  This
class is thread safe.
@
text
@d1 46
d63 1
a63 1
 * @@version $Id: $
@

