iitb.con.ds
Class InstanceTable

java.lang.Object
  extended by iitb.con.ds.InstanceTable
All Implemented Interfaces:
ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>

public class InstanceTable
extends java.lang.Object
implements ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>

InstanceTable holds the InstanceMetaItem as value objects. The super key is the type id and the sub key is the instance id.

Instances are managed in the concept-net as a set of three files:
ntab file - holds the information about the instance-meta information as InstanceItem
net file - holds the instances
nfsl file - free blocks list in the .net file

The instances are added/updated/removed to the action buffer list and it is committed to the respective file on calling commit() method.

See Also:
InstanceMetaItem, Instance

Constructor Summary
InstanceTable(java.lang.String dirName, java.lang.String mode)
          Constructs the InstanceTable.
 
Method Summary
 void close()
          Close the file associate with the table
 void commit()
          Commits the instances to the respective file.
Commit operation is performed based on the object and action state that present in the ActionBufferList.
 InstanceMetaItem get(java.lang.Integer instanceId)
          Returns the InstanceMetaItem for the given instance id
 java.util.Map<java.lang.Integer,InstanceMetaItem> get(java.lang.Short typeId)
          Returns the hash map with key-value pair as InstanceId , InstanceMetaItem for the given type id
 InstanceMetaItem get(java.lang.Short typeId, java.lang.Integer instanceId)
          Returns the InstanceMetaItem for the given type id and instance id
 java.util.List<InstanceMetaItem> getAllItems()
          Returns all the InstanceMetaItems from the table
 java.lang.Object getObject(java.lang.Object o)
          Returns the InstanceMetaItems for the given type id
 void put(InstanceMetaItem item)
          Puts the InstanceMetaItem into the instance table
 void put(java.lang.Short typeId, InstanceMetaItem item)
          Puts the InstanceMetaItem into the instance table with key as type id
 void put(java.lang.Short typeId, java.lang.Integer instanceId, InstanceMetaItem item)
          Puts the InstanceMetaItem into the instance table with keys as type id and instance id
 boolean remove(InstanceMetaItem item)
          Removes the instance from the instance table with the given InstanceMetaItem handle
 boolean remove(java.lang.Integer instanceId)
          Removes the instance from the instance table with instance id as key
 boolean remove(java.lang.Short typeId, java.lang.Integer instanceId)
          Removes the instance from the instance table with type id and instance id as keys
 void setItem(java.lang.Short typeId, java.lang.Integer instanceId, InstanceMetaItem item)
          Sets the InstanceMetaItem with keys as type id and instance id
 int size()
          Returns the size of the table i.e.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstanceTable

public InstanceTable(java.lang.String dirName,
                     java.lang.String mode)
              throws java.io.FileNotFoundException,
                     java.io.IOException
Constructs the InstanceTable.

Parameters:
dirName - directory name of the concept-net
mode - opening mode (r, rw)
Throws:
java.io.FileNotFoundException - if file not found
java.io.IOException - if file operation fails
Method Detail

close

public void close()
           throws java.io.IOException
Close the file associate with the table

Specified by:
close in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Throws:
java.io.IOException - if file operations fail

commit

public void commit()
            throws java.io.IOException
Commits the instances to the respective file.
Commit operation is performed based on the object and action state that present in the ActionBufferList.

Specified by:
commit in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Throws:
java.io.IOException - if file operation fails

get

public InstanceMetaItem get(java.lang.Integer instanceId)
Returns the InstanceMetaItem for the given instance id

Specified by:
get in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
instanceId - Instance id
Returns:
InstanceMetaItem
See Also:
Instance

get

public java.util.Map<java.lang.Integer,InstanceMetaItem> get(java.lang.Short typeId)
Returns the hash map with key-value pair as InstanceId , InstanceMetaItem for the given type id

Specified by:
get in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
typeId - Type id
Returns:
hash map with key-value pair as InstanceId , InstanceMetaItem

get

public InstanceMetaItem get(java.lang.Short typeId,
                            java.lang.Integer instanceId)
Returns the InstanceMetaItem for the given type id and instance id

Specified by:
get in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
typeId - Type id
instanceId - Instance id
Returns:
InstanceMetaItem
See Also:
Type, Instance

getAllItems

public java.util.List<InstanceMetaItem> getAllItems()
Returns all the InstanceMetaItems from the table

Specified by:
getAllItems in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Returns:
InstanceMetaItems as List
See Also:
InstanceMetaItem

getObject

public java.lang.Object getObject(java.lang.Object o)
Returns the InstanceMetaItems for the given type id

Specified by:
getObject in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
o - Type id - Short type
Returns:
InstanceMetaItems as Map with instance id as key and InstanceMetaItem as value

put

public void put(InstanceMetaItem item)
Puts the InstanceMetaItem into the instance table

Specified by:
put in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
item - InstanceMetaItem
See Also:
InstanceMetaItem

put

public void put(java.lang.Short typeId,
                InstanceMetaItem item)
Puts the InstanceMetaItem into the instance table with key as type id

Specified by:
put in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
typeId - Type id
item - InstanceMetaItem
See Also:
Type, InstanceMetaItem

put

public void put(java.lang.Short typeId,
                java.lang.Integer instanceId,
                InstanceMetaItem item)
Puts the InstanceMetaItem into the instance table with keys as type id and instance id

Specified by:
put in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
typeId - Type id
instanceId - Instance id
item - InstanceMetaItem
See Also:
Type, Instance, InstanceMetaItem

remove

public boolean remove(InstanceMetaItem item)
Removes the instance from the instance table with the given InstanceMetaItem handle

Parameters:
item - InstanceMetaItem
Returns:
true on success
See Also:
InstanceMetaItem

remove

public boolean remove(java.lang.Integer instanceId)
Removes the instance from the instance table with instance id as key

Specified by:
remove in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
instanceId - Instance id
Returns:
true on success

remove

public boolean remove(java.lang.Short typeId,
                      java.lang.Integer instanceId)
Removes the instance from the instance table with type id and instance id as keys

Specified by:
remove in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Parameters:
typeId - Type id
instanceId - Instance id
Returns:
true on success

setItem

public void setItem(java.lang.Short typeId,
                    java.lang.Integer instanceId,
                    InstanceMetaItem item)
Sets the InstanceMetaItem with keys as type id and instance id

Parameters:
typeId - Type id
instanceId - Instance id
item - InstanceMetaItem
See Also:
Type, Instance, InstanceMetaItem

size

public int size()
Returns the size of the table i.e. the no. of instance meta items

Specified by:
size in interface ItemTable<java.lang.Short,java.lang.Integer,InstanceMetaItem>
Returns:
table size