net.obsearch.example
Class OBSlice

java.lang.Object
  extended by net.obsearch.example.OBSlice
All Implemented Interfaces:
OB, OBShort, Storable

public class OBSlice
extends Object
implements OBShort

Example Object that can be stored in OBSearch This class reads strings representations of trees and calculates the distance between the objects by using a tree distance function.

Since:
0.7
Author:
Arnoldo Jose Muller Molina

Field Summary
protected  SliceAST tree
          The root node of the tree.
 
Constructor Summary
OBSlice()
          Default constructor must be provided by every object that implements the interface OB.
OBSlice(String slice)
          Creates an slice object.
 
Method Summary
 short distance(OBShort object)
          Calculates the distance between two trees.
 boolean equals(Object obj)
          Returns true of this.tree.equals(obj.tree).
 SliceAST getTree()
           
 int hashCode()
          A hashCode based on the string representation of the tree.
 void load(byte[] in)
          Re-creates this object from the given byte stream
 int recordSize()
           
 int size()
          Returns the size (in nodes) of the tree.
 byte[] store()
          Stores this object into the given byte stream.
 String toString()
           
protected  void updateTree(String x)
          Internal method that updates the Tree from the String
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

tree

protected SliceAST tree
The root node of the tree.

Constructor Detail

OBSlice

public OBSlice()
Default constructor must be provided by every object that implements the interface OB.


OBSlice

public OBSlice(String slice)
        throws OBException
Creates an slice object.

Parameters:
slice - A string representation of a tree.
Throws:
OBException
Method Detail

getTree

public SliceAST getTree()

distance

public final short distance(OBShort object)
                     throws OBException
Calculates the distance between two trees. TODO: traverse the smallest tree.

Specified by:
distance in interface OBShort
Parameters:
object - The other object to compare
Returns:
A short that indicates how similar or different the trees are.
Throws:
OBException - if something wrong happens.
See Also:
net.obsearch.OB#distance(net.obsearch.OB, net.obsearch.result.Dim)

updateTree

protected final void updateTree(String x)
                         throws OBException
Internal method that updates the Tree from the String

Throws:
OBException

size

public final int size()
               throws OBException
Returns the size (in nodes) of the tree.

Returns:
The size of the tree.
Throws:
OBException - If something goes wrong.

toString

public final String toString()
Overrides:
toString in class Object
Returns:
A String representation of the tree.

load

public final void load(byte[] in)
                throws IOException,
                       OBException
Re-creates this object from the given byte stream

Specified by:
load in interface Storable
Parameters:
in - A byte vector from which the stream will be loaded.
Throws:
OBException - if the data cannot be loaded.
IOException
See Also:
net.obsearch.Storable#load(com.sleepycat.bind.tuple.TupleInput)

recordSize

public final int recordSize()

store

public final byte[] store()
                   throws IOException
Stores this object into the given byte stream.

Specified by:
store in interface Storable
Parameters:
out - The byte stream to be used
Throws:
IOException
See Also:
net.obsearch.Storable#store(com.sleepycat.bind.tuple.TupleOutput)

equals

public final boolean equals(Object obj)
Returns true of this.tree.equals(obj.tree). For this distance function this.distance(obj) == 0 implies that this.equals(obj) == true

Overrides:
equals in class Object
Parameters:
obj - Object to compare.
Returns:
true if this == obj

hashCode

public final int hashCode()
A hashCode based on the string representation of the tree.

Overrides:
hashCode in class Object
Returns:
a hash code of the string representation of this tree.


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.