edu.stanford.nlp.util
Class DeltaIndex<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by edu.stanford.nlp.util.DeltaIndex<E>
All Implemented Interfaces:
Index<E>, Serializable, Iterable<E>, Collection<E>

public class DeltaIndex<E>
extends AbstractCollection<E>
implements Index<E>

A class that has a backing index, such as a hash index you don't want changed, and another index which will hold extra entries that get added during the life of the index.
It is important that nothing else changing the backing index while a DeltaIndex is in use. The behavior of this index is undefined if the backing index changes, although in general the new entries in the backing index will be ignored.

Author:
John Bauer
See Also:
Serialized Form

Constructor Summary
DeltaIndex(Index<E> backingIndex)
           
DeltaIndex(Index<E> backingIndex, Index<E> spilloverIndex)
           
 
Method Summary
 boolean add(E e)
           
 boolean addAll(Collection<? extends E> c)
           
 void clear()
          We don't want to change the backing index in any way, and "clear" would have to entail doing that, so we just throw an UnsupportedOperationException instead
 boolean contains(Object o)
           
 E get(int i)
          Gets the object whose index is the integer argument.
 int indexOf(E o)
          Returns the integer index of the Object in the Index or -1 if the Object is not already in the Index.
 int indexOf(E o, boolean add)
          Takes an Object and returns the integer index of the Object, perhaps adding it to the index first.
 boolean isEmpty()
           
 boolean isLocked()
          Queries the Index for whether it's locked or not.
 Iterator<E> iterator()
          This is one instance where elements added to the backing index will show up in this index's operations
 void lock()
          Locks the Index.
 Collection<E> objects(int[] indices)
          Looks up the objects corresponding to an array of indices, and returns them in a Collection.
 List<E> objectsList()
          Returns a complete List of indexed objects, in the order of their indices.
 void saveToFilename(String s)
          Save the contents of this index into a file.
 void saveToWriter(Writer out)
          Save the contents of this index into string form, as part of a larger text-serialization.
 int size()
          Returns the number of indexed objects.
<T> T[]
toArray(T[] a)
           
 String toString()
          super ghetto
 void unlock()
          Unlocks the Index.
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

DeltaIndex

public DeltaIndex(Index<E> backingIndex)

DeltaIndex

public DeltaIndex(Index<E> backingIndex,
                  Index<E> spilloverIndex)
Method Detail

size

public int size()
Description copied from interface: Index
Returns the number of indexed objects.

Specified by:
size in interface Index<E>
Specified by:
size in interface Collection<E>
Specified by:
size in class AbstractCollection<E>
Returns:
the number of indexed objects.

get

public E get(int i)
Description copied from interface: Index
Gets the object whose index is the integer argument.

Specified by:
get in interface Index<E>
Parameters:
i - the integer index to be queried for the corresponding argument
Returns:
the object whose index is the integer argument.

indexOf

public int indexOf(E o)
Description copied from interface: Index
Returns the integer index of the Object in the Index or -1 if the Object is not already in the Index.

Specified by:
indexOf in interface Index<E>
Parameters:
o - the Object whose index is desired.
Returns:
the index of the Object argument. Returns -1 if the object is not in the index.

indexOf

public int indexOf(E o,
                   boolean add)
Description copied from interface: Index
Takes an Object and returns the integer index of the Object, perhaps adding it to the index first. Returns -1 if the Object is not in the Index. (Note: indexOf(x, true) is the direct replacement for the number(x) method in the old Numberer class.)

Specified by:
indexOf in interface Index<E>
Parameters:
o - the Object whose index is desired.
add - Whether it is okay to add new items to the index
Returns:
the index of the Object argument. Returns -1 if the object is not in the index.

objectsList

public List<E> objectsList()
Description copied from interface: Index
Returns a complete List of indexed objects, in the order of their indices.

Specified by:
objectsList in interface Index<E>
Returns:
a complete List of indexed objects

objects

public Collection<E> objects(int[] indices)
Description copied from interface: Index
Looks up the objects corresponding to an array of indices, and returns them in a Collection.

Specified by:
objects in interface Index<E>
Parameters:
indices - An array of indices
Returns:
a Collection of the objects corresponding to the indices argument.

isLocked

public boolean isLocked()
Description copied from interface: Index
Queries the Index for whether it's locked or not.

Specified by:
isLocked in interface Index<E>
Returns:
whether or not the Index is locked

lock

public void lock()
Description copied from interface: Index
Locks the Index. A locked index cannot have new elements added to it (calls to Index.add(E) will leave the Index unchanged and return false).

Specified by:
lock in interface Index<E>

unlock

public void unlock()
Description copied from interface: Index
Unlocks the Index. A locked index cannot have new elements added to it (calls to Index.add(E) will leave the Index unchanged and return false).

Specified by:
unlock in interface Index<E>

saveToWriter

public void saveToWriter(Writer out)
Description copied from interface: Index
Save the contents of this index into string form, as part of a larger text-serialization.

Specified by:
saveToWriter in interface Index<E>
Parameters:
out - Writer to save to.

saveToFilename

public void saveToFilename(String s)
Description copied from interface: Index
Save the contents of this index into a file.

Specified by:
saveToFilename in interface Index<E>
Parameters:
s - File name.

contains

public boolean contains(Object o)
Specified by:
contains in interface Index<E>
Specified by:
contains in interface Collection<E>
Overrides:
contains in class AbstractCollection<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Index<E>
Specified by:
toArray in interface Collection<E>
Overrides:
toArray in class AbstractCollection<E>

add

public boolean add(E e)
Specified by:
add in interface Index<E>
Specified by:
add in interface Collection<E>
Overrides:
add in class AbstractCollection<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Index<E>
Specified by:
addAll in interface Collection<E>
Overrides:
addAll in class AbstractCollection<E>

clear

public void clear()
We don't want to change the backing index in any way, and "clear" would have to entail doing that, so we just throw an UnsupportedOperationException instead

Specified by:
clear in interface Index<E>
Specified by:
clear in interface Collection<E>
Overrides:
clear in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Overrides:
isEmpty in class AbstractCollection<E>

iterator

public Iterator<E> iterator()
This is one instance where elements added to the backing index will show up in this index's operations

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in class AbstractCollection<E>

toString

public String toString()
super ghetto

Overrides:
toString in class AbstractCollection<E>


Stanford NLP Group