diva.sketch.recognition
Class Type

java.lang.Object
  extended by diva.sketch.recognition.Type

public final class Type
extends Object

A unique identifier for the type of a piece of data that results from a recognition. For example, different drawings of squares have different parameters (size, etc.) but they all have the same type.

The type system implemented in Diva is semi-dynamic. There is a class SimpleData that is dynamically typed; the only data that it contains is the type that is associated with a particular recognized object. For all other objects with semantic information (e.g. TextType, which contains the recognized text), the type system uses Java's runtime type system. This is an implementation detail, and is transparent to the user.

There are two ways to get a handle to a type object. The static method Type.getType with a String name argument will return a static type if the name has been registered as static. Otherwise it will return a dynamic type. There is also a getType method with a Class object argument that can be used to create a static type.

Version:
$Revision: 1.6 $
Author:
Michael Shilman (michaels@eecs.berkeley.edu)
See Also:
TypedData, SimpleData

Field Summary
static Type NO_TYPE
          The type to be associated with an unrecognized piece of data.
 
Method Summary
static void addStaticType(String staticType)
          Add a static type to the Type system.
 boolean equals(Object o)
          Return whether the given type object is equivalent to this one.
 String getID()
          Return the type ID of this object.
 Type getParent()
          Return the parent type of this one.
 int hashCode()
          Override the hashCode() method so that objects of the same type hash to the same index.
static boolean isStaticType(String typeID)
          Return whether the given type name has been registered as a native type in this type system.
static Type makeType(Class c)
          Return the type object associated with the given class and register it as static.
static Type makeType(String typeName)
          Return the type object associated with the given type name.
 String toString()
          Return a string representation of the type object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_TYPE

public static final Type NO_TYPE
The type to be associated with an unrecognized piece of data.

Method Detail

addStaticType

public static void addStaticType(String staticType)
                          throws ClassNotFoundException
Add a static type to the Type system. The input should be fully-qualified with the package name, e.g. foo.bar.Baz, and this will establish the alias Baz in the type system. This method tries to load the class with the given name, and throws an exception if there is a loading error.

Throws:
ClassNotFoundException

equals

public boolean equals(Object o)
Return whether the given type object is equivalent to this one.

Overrides:
equals in class Object

getID

public String getID()
Return the type ID of this object. This is useful when the type is dynamic.


getParent

public Type getParent()
Return the parent type of this one. Dynamically typed objects have no parent type; statically typed objects' parent type mirrors the parent type in the Java class system.


hashCode

public int hashCode()
Override the hashCode() method so that objects of the same type hash to the same index.

Overrides:
hashCode in class Object

isStaticType

public static boolean isStaticType(String typeID)
Return whether the given type name has been registered as a native type in this type system.


makeType

public static Type makeType(String typeName)
Return the type object associated with the given type name. If the type has been registered as a static type, return a static type, otherwise return a dynamic type.


makeType

public static Type makeType(Class c)
Return the type object associated with the given class and register it as static.


toString

public String toString()
Return a string representation of the type object.

Overrides:
toString in class Object


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.