org.hypergraphdb.atom
Class HGRelType

java.lang.Object
  extended by org.hypergraphdb.type.HGAtomTypeBase
      extended by org.hypergraphdb.atom.HGRelType
All Implemented Interfaces:
HGGraphHolder, HGLink, HGAtomType

public class HGRelType
extends HGAtomTypeBase
implements HGLink

Represents the type a "semantic" relationship. It carries the name of the relationships and the types of its arguments. The latter are simply the target set of a HGRelType instance.

Author:
Borislav Iordanov

Constructor Summary
HGRelType()
           
HGRelType(HGHandle[] targetTypes)
           
HGRelType(java.lang.String name)
           
HGRelType(java.lang.String name, HGHandle[] targetTypes)
           
 
Method Summary
 boolean equals(java.lang.Object other)
           
 int getArity()
          Return the number of targets of this link.
 java.lang.String getName()
           
 HGHandle getTargetAt(int i)
          Return the ith target.
 int hashCode()
           
 java.lang.Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet)
          Construct a new run-time instance of a hypergraph atom.
 void notifyTargetHandleUpdate(int i, HGHandle handle)
          Notify the HGLink that one of its target atoms should be referred to by a different HGHandle instance.
 void notifyTargetRemoved(int i)
           Notify the HGLink that one of its targets must be removed.
 void release(HGPersistentHandle handle)
          Release a hypergraph value instance from the persistent store.
 void setName(java.lang.String name)
           
 HGPersistentHandle store(java.lang.Object instance)
          Store a run-time instance of a hypergraph atom into the hypergraph HGStore as a new atom.
 
Methods inherited from class org.hypergraphdb.type.HGAtomTypeBase
getHyperGraph, setHyperGraph, subsumes
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HGRelType

public HGRelType()

HGRelType

public HGRelType(java.lang.String name)

HGRelType

public HGRelType(HGHandle[] targetTypes)

HGRelType

public HGRelType(java.lang.String name,
                 HGHandle[] targetTypes)
Method Detail

make

public java.lang.Object make(HGPersistentHandle handle,
                             LazyRef<HGHandle[]> targetSet,
                             IncidenceSetRef incidenceSet)
Description copied from interface: HGAtomType

Construct a new run-time instance of a hypergraph atom. A plain node must be constructed whenever the targetSet parameter is null or of length 0. Otherwise, a HGLink instance must be constructed.

It is not required that all atom types be able to construct both plain (node) atoms and HGLinks. It is up to an HGAtomType implementation to support either or both. When a HGLink counterpart is not available for a particular run-time type, an implementation may choose to create an instance of the default link value holder implementation HGValuedLink, provided by HyperGraph.

Specified by:
make in interface HGAtomType
Parameters:
handle - The HGPersistentHandle of the atom value.
targetSet - When the atom is a link, this parameter holds the target set of the link. When the atom is a node, the parameter is an array of 0 length.
incidenceSet - TODO
Returns:
The run-time atom instance. The return value should never be null. In case the handle points to an invalid instance (inexisting or with a erronous layout), the method should throw a HGException.

release

public void release(HGPersistentHandle handle)
Description copied from interface: HGAtomType

Release a hypergraph value instance from the persistent store.

This method should be called when a HGPersistentHandle returned from the store is no longer in use.

Specified by:
release in interface HGAtomType
Parameters:
handle - The persistent handle of the value to release.

store

public HGPersistentHandle store(java.lang.Object instance)
Description copied from interface: HGAtomType

Store a run-time instance of a hypergraph atom into the hypergraph HGStore as a new atom.

Specified by:
store in interface HGAtomType
Parameters:
instance - The atom instance.
Returns:
The persistent handle of the stored value.

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

getArity

public int getArity()
Description copied from interface: HGLink

Return the number of targets of this link. This number may be >= 0.

Specified by:
getArity in interface HGLink

getTargetAt

public HGHandle getTargetAt(int i)
Description copied from interface: HGLink

Return the ith target.

Specified by:
getTargetAt in interface HGLink
Parameters:
i - The index of the desired target. The range of this parameters must be [0...getArity() - 1].

notifyTargetHandleUpdate

public void notifyTargetHandleUpdate(int i,
                                     HGHandle handle)
Description copied from interface: HGLink

Notify the HGLink that one of its target atoms should be referred to by a different HGHandle instance. Generally, implementation should update their reference to this target with the passed in live handle.

IMPORTANT NOTE: This method should never be called by application code. It is strictly reserved to the HyperGraph implementation which guarantees that the new handle will always refer to the same atom. The method should essentially perform a setTargetAt operation, but a more elaborate name was chosen to reflect the intended usage. Note also that the intent is not for an implementation to attempt a database update! The intent is to only update the runtime representation of the set of targets pointed to be this link.

Specified by:
notifyTargetHandleUpdate in interface HGLink
Parameters:
i - The index of the target that was loaded.
handle - The new live handle of the target atom.

notifyTargetRemoved

public void notifyTargetRemoved(int i)
Description copied from interface: HGLink

Notify the HGLink that one of its targets must be removed. This method is invoked by the system when the target at position i refers to an atom that is being deleted from the database. Implementation are required to remove the target at that position from their implementation data structure. It remains the system's responsibility to reflect that change in permanent data storage.

An implementation may throw an IllegalArgumentException if the target cannot be removed from the link because it would somehow break the semantics of the application or lead in otherwise inconsistent state. Throwing such an exception would indicate a fatal error and a very likely bug in the application.

Specified by:
notifyTargetRemoved in interface HGLink
Parameters:
i - The 0-based position of the target to be removed from this link.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object