blog
Class Type

java.lang.Object
  extended by blog.Type
Direct Known Subclasses:
MatrixType

public class Type
extends java.lang.Object

Represents a type in a BLOG model. Stores a set of potential object patterns (POPs), a set of origin functions, and a set of explicitly enumerated guaranteed objects.

We ensure that there is only one Type object for each type, so Type objects can be compared with ==.


Constructor Summary
Type(java.lang.String name)
          Creates a new type with the given name that is not a sub-type of any other type.
Type(java.lang.String name, Type supertype)
          Creates a type with the given name that is a direct sub-type of supertype.
Type(java.lang.String name, Type supertype, boolean infinite)
          Creates a type with the given name that is a direct sub-type of supertype.
 
Method Summary
 EnumeratedObject addGuaranteedObject(NonRandomFunction constant)
          Adds a new guaranteed object with the given canonical constant symbol.
 void addOriginFunction(OriginFunction f)
          Adds the given function as a origin function for this type.
 void addPOP(POP pop)
          Adds the given POP to the set of POPs for this type.
 Term getCanonicalTerm(java.lang.Object o)
          Returns the canonical term for the given object, or null if the object has no canonical term.
 int getCreationIndex()
          Returns an index indicating when this type was declared (or otherwise created).
 java.lang.Object getDefaultValue()
          Returns the default value for functions with this return type.
 java.lang.Object getGuaranteedObject(int index)
          Returns the guaranteed object of this type that has the given index, or null if no such object exists.
 java.util.List getGuaranteedObjects()
          Returns the list of explicitly enumerated guaranteed objects of this type, in the order they were introduced in the model file.
 int getGuaranteedObjIndex(java.lang.Object obj)
          Returns the index of the given object in this type's list of guaranteed objects.
 java.lang.String getName()
          Returns the name of this type.
 java.util.List getOriginFunctions()
          Returns a list of origin functions for this type.
 java.util.Collection getPOPs()
          Returns the set of potential object patterns (POPs) for this type.
 POP getPOPWithOriginFuncs(java.util.BitSet originFuncSet)
          Returns the POP that uses the given set of origin functions, or null if no such POP exists.
 POP getPOPWithOriginFuncs(java.util.Set originFuncSet)
          Returns the POP that uses the given set of origin functions, or null if not such POP exists.
 java.util.Set getStrictAncestors()
          Returns the types that are strict ancestors of this type in the type graph.
 boolean hasFiniteGuaranteed()
          Returns true if this type has a finite number of guaranteed objects.
 boolean isBuiltIn()
          Returns true if this is a built-in type.
 boolean isSubtypeOf(Type other)
          Returns true if this type is a subtype of the given type.
 void print(java.io.PrintStream s)
          Prints the type name.
 java.util.List range()
          Returns a list of all the values that can be returned by an expression with this return type.
 java.lang.String toString()
          Returns the name of this type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Type

public Type(java.lang.String name)
Creates a new type with the given name that is not a sub-type of any other type. It initially has no POPs, no origin functions, and no enumerated guaranteed objects.


Type

public Type(java.lang.String name,
            Type supertype)
Creates a type with the given name that is a direct sub-type of supertype. It initially has no POPs, no origin functions, and no enumerated guaranteed objects.

Note that there's no way to change the supertype of a type once it's created. Thus, the types must be created in order from the root of the type hierarchy downward. So it is impossible to make the supertype relation cyclic.

Parameters:
supertype - a Type object or null

Type

public Type(java.lang.String name,
            Type supertype,
            boolean infinite)
Creates a type with the given name that is a direct sub-type of supertype. It initially has no POPs, no origin functions, and no enumerated guaranteed objects. If infinite is true, the type has infinitely many guaranteed objects.

Parameters:
supertype - a Type object or null
Method Detail

getName

public java.lang.String getName()
Returns the name of this type.


isSubtypeOf

public boolean isSubtypeOf(Type other)
Returns true if this type is a subtype of the given type. A type counts as a subtype of itself.


isBuiltIn

public boolean isBuiltIn()
Returns true if this is a built-in type.


print

public void print(java.io.PrintStream s)
Prints the type name.


getPOPs

public java.util.Collection getPOPs()
Returns the set of potential object patterns (POPs) for this type.

Returns:
unmodifiable Collection of POP objects

getOriginFunctions

public java.util.List getOriginFunctions()
Returns a list of origin functions for this type. Although the order of origin functions does not affect the semantics of the model, the origin functions are always returned in the same order. This facilitates looking up the POP that uses a certain subset of the origin functions (the subset can be represented as a BitSet where bit indices correspond to the indices of origin functions in this list).

Returns:
unmodifiable List of OriginFunction objects

getGuaranteedObjects

public java.util.List getGuaranteedObjects()
Returns the list of explicitly enumerated guaranteed objects of this type, in the order they were introduced in the model file. Or, if this is a built-in type with a finite set of guaranteed objects, returns those objects in some fixed order.

Returns:
unmodifiable list of Object

range

public java.util.List range()
Returns a list of all the values that can be returned by an expression with this return type. The list includes all the guaranteed objects of this type, with Model.NULL added to the end if it serves as the type's default value. The list's get and indexOf methods can be used to convert efficiently between objects and indices.

Throws:
java.lang.IllegalStateException - if the set of objects of this type is infinite or random

getGuaranteedObjIndex

public int getGuaranteedObjIndex(java.lang.Object obj)
Returns the index of the given object in this type's list of guaranteed objects. Returns -1 if this type has infinitely many guaranteed objects (and thus does not maintain a list of them) or if the given object is not a guaranteed object of this type.


getGuaranteedObject

public java.lang.Object getGuaranteedObject(int index)
Returns the guaranteed object of this type that has the given index, or null if no such object exists.


getDefaultValue

public java.lang.Object getDefaultValue()
Returns the default value for functions with this return type.


hasFiniteGuaranteed

public boolean hasFiniteGuaranteed()
Returns true if this type has a finite number of guaranteed objects.


getCanonicalTerm

public Term getCanonicalTerm(java.lang.Object o)
Returns the canonical term for the given object, or null if the object has no canonical term. For an EnumeratedObject, the canonical term is a FuncAppTerm composed of that object's constant symbol and no arguments. For built-in types, the guaranteed objects may have other canonical terms.

Throws:
java.lang.IllegalArgumentException - if the given object is not of this type

getPOPWithOriginFuncs

public POP getPOPWithOriginFuncs(java.util.BitSet originFuncSet)
Returns the POP that uses the given set of origin functions, or null if no such POP exists.

Parameters:
originFuncSet - a BitSet where bit i stands for the ith origin function in the list returned by getOriginFunctions

getPOPWithOriginFuncs

public POP getPOPWithOriginFuncs(java.util.Set originFuncSet)
Returns the POP that uses the given set of origin functions, or null if not such POP exists.

Parameters:
originFuncSet - Set of OriginFunction objects

getStrictAncestors

public java.util.Set getStrictAncestors()
Returns the types that are strict ancestors of this type in the type graph. The type graph contains a node for each type, with an edge from type sigma to type tau if sigma is the return type of some origin function for tau. Note that this graph may be cyclic and may even include self-loops. The strict ancestors of a this type are those types tau such that there is a nonzero-length directed path from tau to this type.

Returns:
a Set of Type objects

addPOP

public void addPOP(POP pop)
Adds the given POP to the set of POPs for this type.

Throws:
java.lang.IllegalArgumentException - if the given POP uses the same set of origin functions as an existing POP

addOriginFunction

public void addOriginFunction(OriginFunction f)
Adds the given function as a origin function for this type.


addGuaranteedObject

public EnumeratedObject addGuaranteedObject(NonRandomFunction constant)
Adds a new guaranteed object with the given canonical constant symbol. Warning: for efficiency, we do not check to make sure a guaranteed object has not already been added with the same symbol.

Returns:
the object added

getCreationIndex

public int getCreationIndex()
Returns an index indicating when this type was declared (or otherwise created).


toString

public java.lang.String toString()
Returns the name of this type.

Overrides:
toString in class java.lang.Object