public abstract class PrimitiveTypeBase<JavaType> extends Object implements HGPrimitiveType<JavaType>, HGOrderedSearchable<JavaType,HGPersistentHandle>, HGRefCountedType
A generic, base implementation of the primitive Java types.
It maintains an index of all primitive values added for faster lookup. It also shares
primitive values for more compact storage - that is, the store
method will always return the same handle for an already added primitive value.
Concrete classes for concrete primitive types must provide a name for the managed index as well as a comparator class for their instance values.
A primitively typed object is translated to a byte [] as follows:
| Modifier and Type | Field and Description |
|---|---|
protected static int |
dataOffset
The offset in the final
byte [] of the actual
primitive value. |
protected HyperGraph |
graph |
protected HGSortIndex<byte[],HGPersistentHandle> |
valueIndex |
| Constructor and Description |
|---|
PrimitiveTypeBase() |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(byte[] left,
byte[] right) |
HGSearchResult<HGPersistentHandle> |
find(JavaType key)
Returns a
HGSearchResult over all values matching a key in the
searched entity. |
HGSearchResult<HGPersistentHandle> |
findGT(JavaType key)
Return a range of all values strictly greater than
the specified key.
|
HGSearchResult<HGPersistentHandle> |
findGTE(JavaType key)
Return a range of all values greater than or equal to
the specified key.
|
HGSearchResult<HGPersistentHandle> |
findLT(JavaType key)
Return a range of all values strictly less than
the specified key.
|
HGSearchResult<HGPersistentHandle> |
findLTE(JavaType key)
Return a range of all values less than or equal to
the specified key.
|
JavaType |
fromByteArray(byte[] byteArray,
int offset,
int length) |
protected HGSortIndex<byte[],HGPersistentHandle> |
getIndex() |
protected abstract String |
getIndexName()
Return the name of the DB index to create for the primitive values.
|
protected int |
getRefCount(byte[] buf) |
int |
getRefCountFor(JavaType o) |
Object |
make(HGPersistentHandle handle,
LazyRef<HGHandle[]> targetSet,
IncidenceSetRef incidenceSet)
Construct a new run-time instance of a hypergraph atom.
|
protected void |
putRefCount(int c,
byte[] buf) |
protected abstract JavaType |
readBytes(byte[] data,
int offset) |
void |
release(HGPersistentHandle handle)
Release a hypergraph value instance from the persistent store.
|
void |
setHyperGraph(HyperGraph hg)
During load time, set the
HyperGraph
instance to which this atom belongs. |
HGPersistentHandle |
store(Object instance)
Store a run-time instance of a hypergraph atom into the hypergraph
HGStore
as a new atom. |
protected HGPersistentHandle |
storeImpl(byte[] data) |
boolean |
subsumes(Object l,
Object r)
A generic semantic predicate that returns
true if the first argument
is more general than the second. |
byte[] |
toByteArray(JavaType object) |
protected abstract byte[] |
writeBytes(JavaType value) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetComparatorprotected HyperGraph graph
protected HGSortIndex<byte[],HGPersistentHandle> valueIndex
protected static final int dataOffset
The offset in the final byte [] of the actual
primitive value.
protected abstract String getIndexName()
Return the name of the DB index to create for the primitive values.
protected final HGSortIndex<byte[],HGPersistentHandle> getIndex()
protected final int getRefCount(byte[] buf)
protected final void putRefCount(int c,
byte[] buf)
protected final HGPersistentHandle storeImpl(byte[] data)
protected abstract byte[] writeBytes(JavaType value)
protected abstract JavaType readBytes(byte[] data, int offset)
public int compare(byte[] left,
byte[] right)
public final void setHyperGraph(HyperGraph hg)
HGGraphHolderDuring load time, set the HyperGraph
instance to which this atom belongs.
setHyperGraph in interface HGGraphHolderpublic final void release(HGPersistentHandle handle)
HGAtomTypeRelease 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.
release in interface HGAtomTypehandle - The persistent handle of the value to release.public Object make(HGPersistentHandle handle, LazyRef<HGHandle[]> targetSet, IncidenceSetRef incidenceSet)
HGAtomTypeConstruct 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.
make in interface HGAtomTypehandle - 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 - A lazy reference to the set of links pointing to this atom. This is
null if we are constructing an internal/nested value of some complex type.null.
In case the handle points to an invalid instance (inexisting or with
a erronous layout), the method should throw a HGException.public JavaType fromByteArray(byte[] byteArray, int offset, int length)
fromByteArray in interface ByteArrayConverter<JavaType>public byte[] toByteArray(JavaType object)
toByteArray in interface ByteArrayConverter<JavaType>public HGPersistentHandle store(Object instance)
HGAtomTypeStore a run-time instance of a hypergraph atom into the hypergraph HGStore
as a new atom.
store in interface HGAtomTypeinstance - The atom instance.public HGSearchResult<HGPersistentHandle> find(JavaType key)
HGSearchable
Returns a HGSearchResult over all values matching a key in the
searched entity.
If there are no matches, the method should return HGSearchResult.EMPTY. The
method will never return a null. A HGException may
be thrown in exceptional situations.
find in interface HGSearchable<JavaType,HGPersistentHandle>public HGSearchResult<HGPersistentHandle> findGT(JavaType key)
HGOrderedSearchableReturn a range of all values strictly greater than the specified key.
findGT in interface HGOrderedSearchable<JavaType,HGPersistentHandle>key - The search key.HGSearchResult over the resulting range of values.public HGSearchResult<HGPersistentHandle> findGTE(JavaType key)
HGOrderedSearchableReturn a range of all values greater than or equal to the specified key.
findGTE in interface HGOrderedSearchable<JavaType,HGPersistentHandle>key - The search key.HGSearchResult over the resulting range of values.public HGSearchResult<HGPersistentHandle> findLT(JavaType key)
HGOrderedSearchableReturn a range of all values strictly less than the specified key.
findLT in interface HGOrderedSearchable<JavaType,HGPersistentHandle>key - The search key.HGSearchResult over the resulting range of values.public HGSearchResult<HGPersistentHandle> findLTE(JavaType key)
HGOrderedSearchableReturn a range of all values less than or equal to the specified key.
findLTE in interface HGOrderedSearchable<JavaType,HGPersistentHandle>key - The search key.HGSearchResult over the resulting range of values.public boolean subsumes(Object l, Object r)
HGAtomTypeA generic semantic predicate that returns true if the first argument
is more general than the second. Atom types must implement this notion of specialization
whenever meaningful in the context of the entities being constructed.
The notion of subsumption can be seen as partial equivalence, or equivalence in one direction only.
As a relation, subsumtion is transitive and reflexive. The latter implies that, at a minimum,
the subsumes method must return true if
general.equals(specific).
subsumes in interface HGAtomTypel - The object which might be more general. Cannot be null.r - The object which might be more specific. Cannot be null.true if specific can be used whenever general
is required and false otherwise.public int getRefCountFor(JavaType o)
Copyright © 2015. All rights reserved.