org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class MofidIndex

java.lang.Object
  extended by org.netbeans.mdr.persistence.btreeimpl.btreestorage.MofidIndex
All Implemented Interfaces:
StorageClient, Streamable

public class MofidIndex
extends java.lang.Object
implements StorageClient

This is an index from names (Strings) to MOFIDs. Its primary use is to store the MOFIDs for secondary indexes.


Field Summary
protected  java.util.HashMap hashOnName
           
 
Constructor Summary
MofidIndex()
          Create a new MofidIndex
MofidIndex(BtreeStorage storage)
          Create a new MofidIndex
 
Method Summary
 void add(java.lang.String name, MOFID id)
          Add a name-MOFID pair to the MofidIndex.
protected  void addObj(java.lang.String name, java.lang.Object id)
          Add a name-Object pair to the NameIndex.
 void clear()
          Remove all name-Object pairs from the NameIndex.
 MOFID get(java.lang.String name)
          get a MOFID by its name.
protected  java.lang.Object getObj(java.lang.String name)
          get an object by its name.
protected  java.lang.Object getObjIf(java.lang.String name)
          get an object by its name.
 java.util.Iterator iterator()
          iterate over entries
 java.lang.String[] listNames()
          return the names of all objects in the NameIndex, in no particular order.
 void read(java.io.DataInputStream dstrm)
          read from a DataOutputStream
 void read(java.io.InputStream strm)
          deserialize the NameIndex from a stream.
protected  java.lang.Object readObjectFromStream(java.io.DataInputStream strm)
          read object from stream.
 void remove(java.lang.String name)
          Remove a name-Object pair from the NameIndex.
 void setName(java.lang.String nm)
          give object a name
 void setStorage(Storage storage)
          called on deserialization
 java.lang.String toString()
          return name set with setName
 void write(java.io.DataOutputStream dstrm)
          write to a DataOutputStream
 void write(java.io.OutputStream strm)
          serialize the NameIndex to a stream.
protected  void writeObjectToStream(java.lang.Object obj, java.io.DataOutputStream strm)
          write object to stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hashOnName

protected java.util.HashMap hashOnName
Constructor Detail

MofidIndex

public MofidIndex()
Create a new MofidIndex


MofidIndex

public MofidIndex(BtreeStorage storage)
Create a new MofidIndex

Method Detail

get

public MOFID get(java.lang.String name)
          throws StorageException
get a MOFID by its name. If none exists, throw an exception

Parameters:
name - the name associated with the MOFID
Throws:
StorageException

add

public void add(java.lang.String name,
                MOFID id)
         throws StorageException
Add a name-MOFID pair to the MofidIndex. If one already existed, throw an exception.

Parameters:
name - name of object to add to index
id - MOFID of object to add
Throws:
StorageException

writeObjectToStream

protected void writeObjectToStream(java.lang.Object obj,
                                   java.io.DataOutputStream strm)
                            throws StorageException
write object to stream. Used by serialization.

Parameters:
obj - object to write
strm - stream to write it to
Throws:
StorageException

readObjectFromStream

protected java.lang.Object readObjectFromStream(java.io.DataInputStream strm)
                                         throws StorageException
read object from stream. Used by deserialization.

Parameters:
strm - stream to read from
Returns:
obj object read
Throws:
StorageException

setStorage

public void setStorage(Storage storage)
called on deserialization

Specified by:
setStorage in interface StorageClient
Parameters:
storage - the Stroage implementation which instantiated the object

setName

public void setName(java.lang.String nm)
give object a name

Parameters:
nm - name of NameIndex

toString

public java.lang.String toString()
return name set with setName

Overrides:
toString in class java.lang.Object

getObj

protected java.lang.Object getObj(java.lang.String name)
                           throws StorageException
get an object by its name. If none exists, throw an exception

Parameters:
name - the name associated with the object
Throws:
StorageException

getObjIf

protected java.lang.Object getObjIf(java.lang.String name)
                             throws StorageException
get an object by its name. If none exists, return null

Parameters:
name - the name associated with the object
Throws:
StorageException

addObj

protected void addObj(java.lang.String name,
                      java.lang.Object id)
               throws StorageException
Add a name-Object pair to the NameIndex. If one already existed, throw an exception.

Parameters:
name - name of object to add to index
id - object to add
Throws:
StorageException

remove

public void remove(java.lang.String name)
            throws StorageException
Remove a name-Object pair from the NameIndex. If it is not present, throw an exception.

Parameters:
name - name of object to rmove from index
Throws:
StorageException

clear

public void clear()
Remove all name-Object pairs from the NameIndex.


listNames

public java.lang.String[] listNames()
return the names of all objects in the NameIndex, in no particular order. Note that this is a snapshot made at the time this method is called.

Returns:
list of all names

iterator

public java.util.Iterator iterator()
iterate over entries


write

public void write(java.io.OutputStream strm)
           throws StorageException
serialize the NameIndex to a stream. The format is:

number of pairs

name of object 1 (in UTF-8)

Representation of object 1

... name of object N (in UTF-8)

Representation of object N

Specified by:
write in interface Streamable
Parameters:
strm - stream to serialize to
Throws:
StorageException

write

public void write(java.io.DataOutputStream dstrm)
           throws StorageException
write to a DataOutputStream

Throws:
StorageException

read

public void read(java.io.InputStream strm)
          throws StorageException
deserialize the NameIndex from a stream. The format is as described in write

Specified by:
read in interface Streamable
Parameters:
strm - stream to deserialize from
Throws:
StorageException

read

public void read(java.io.DataInputStream dstrm)
          throws StorageException
read from a DataOutputStream

Throws:
StorageException


Copyright © 2005-2009 Apache Software Foundation. All Rights Reserved.