blog
Class Model

java.lang.Object
  extended by blog.Model

public class Model
extends java.lang.Object

This class contains all the information available about the structure of the model. In particular, it keeps lists of user-defined types and functions. Attributes of those types and functions are stored in the individual Type and Function objects.

Please note that the mutator methods contain little error-checking, if any.Since the type- and semantic checking of the model is done dynamically while the model file is being parsed, it is assumed that if an error occurs it is caught by the type/semantic checker.


Field Summary
protected  java.util.List functions
          Stores user-defined Function objects in the order they were declared.
protected  java.util.Map functionsByName
          Maps function names to lists of functions with that name (and different argument types).
static java.lang.Object MULTIPLE_FUNCTIONS
          Value returned by getRandomFunc when there are multiple random functions with the given name.
static java.lang.Object NULL
          The BLOG null value.
protected  java.util.List<fove.Parfactor> parfactors
          Parfactors, in the order they were defined.
protected  java.util.List types
          Stores user-defined Type objects in the order they were declared.
protected  java.util.Map typesByName
          Maps type names to Type objects.
 
Constructor Summary
Model()
          Class constructor.
 
Method Summary
 NonRandomFunction addEnumeratedObject(java.lang.String name, Type type)
          Adds to the model a non-random constant with the given name, denoting a new enumerated object of the given type.
 void addFunction(Function f)
          Adds the given user-defined function to this model.
 void addParfactor(fove.Parfactor pf)
          Adds the given parfactor to this model.
 void addType(java.lang.String typeName)
          Creates a new user-defined type with the given name and adds it to this model.
 boolean checkCompleteness()
          Returns true if every random function has a dependency statement, or if the model contains at least one parfactor.
 boolean checkTypesAndScope()
          Check types and scopes in the model.
static int compareArgs(java.lang.Object obj1, java.lang.Object obj2)
          Compares two objects that can serve as arguments to basic random variables.
static int compareArgTuples(java.lang.Object[] objs1, java.lang.Object[] objs2)
          Returns a number that is negative, positive, or zero according to whether objs1 comes before, after, or at the same place as objs2 in a lexicographic ordering.
 int compile()
          Does compilation steps that can only be done correctly once the model is complete.
 boolean existsType(java.lang.String typeName)
          Checks whether the specified type has been defined.
 Function getApplicableFunc(java.lang.String name, Type[] types)
          Returns the user-defined or built-in Function with the given name that is applicable to the given type list, or null if no such function exists.
 java.lang.Object getConstantValue(java.lang.String name)
          Returns the value of the non-random constant with the given name, or null if there is no such non-random constant.
 java.util.Collection getFuncsWithName(java.lang.String name)
          Returns all user-defined or built-in functions with the given name.
 Function getFunction(Function.Sig sig)
          Returns the user-defined or built-in Function object with the specified signature, or null if no such function exists.
 java.util.Collection getFunctions()
          Returns the user-defined functions in this model.
 java.util.Set getListedTypes(java.lang.String typeList)
          Returns a Set consisting of the user-defined types named in the given string.
static int getObjectIndex(java.lang.Object obj)
          Returns the index of the given object among objects of its type.
 java.util.Collection getOverlappingFuncs(java.lang.String name, Type[] types)
          Returns the user-defined or built-in functions with the given name that could apply to some tuple of objects with the given types.
 java.util.List<fove.Parfactor> getParfactors()
          Returns the parfactors in this model, in the order they were declared.
 java.lang.Object getRandomFunc(java.lang.String name, int numArgs)
          Returns the unique random function with the given name and number of arguments.
 Type getType(java.lang.String typeName)
          Returns the type information for the given type.
 java.util.Collection getTypes()
          Returns the user-defined types in this model.
static int nextCreationIndex()
          Returns a number that is one greater than the last number returned by this method.
 void print(java.io.PrintStream s)
          Prints this model to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final java.lang.Object NULL
The BLOG null value. We use this object rather than the Java null value so that we can always use equals to compare BLOG objects, and methods can return null as an error indicator without worrying about the possibility that a BLOG value might actually be null.


MULTIPLE_FUNCTIONS

public static final java.lang.Object MULTIPLE_FUNCTIONS
Value returned by getRandomFunc when there are multiple random functions with the given name.


types

protected java.util.List types
Stores user-defined Type objects in the order they were declared.


typesByName

protected java.util.Map typesByName
Maps type names to Type objects. For user-defined types.


functions

protected java.util.List functions
Stores user-defined Function objects in the order they were declared.


functionsByName

protected java.util.Map functionsByName
Maps function names to lists of functions with that name (and different argument types). For user-defined functions.


parfactors

protected java.util.List<fove.Parfactor> parfactors
Parfactors, in the order they were defined.

Constructor Detail

Model

public Model()
Class constructor.

Method Detail

addType

public void addType(java.lang.String typeName)
Creates a new user-defined type with the given name and adds it to this model.


existsType

public boolean existsType(java.lang.String typeName)
Checks whether the specified type has been defined.


getType

public Type getType(java.lang.String typeName)
Returns the type information for the given type.


getTypes

public java.util.Collection getTypes()
Returns the user-defined types in this model.

Returns:
unmodifiable Collection of Type

getListedTypes

public java.util.Set getListedTypes(java.lang.String typeList)
Returns a Set consisting of the user-defined types named in the given string. The string should be a comma-separated list of type names (spaces are optional). The string can also be the special string "none", which yields an empty set, or "all", which yields the set of all user-defined types.

If some of the named types are undefined, this method prints an error message and returns null.


addFunction

public void addFunction(Function f)
Adds the given user-defined function to this model.

Throws:
java.lang.IllegalStateException - if there is already a user-defined function with the same signature

getFunction

public Function getFunction(Function.Sig sig)
Returns the user-defined or built-in Function object with the specified signature, or null if no such function exists. If there is a user-defined function with the same signature as a built-in function, the user-defined one is returned.


getFuncsWithName

public java.util.Collection getFuncsWithName(java.lang.String name)
Returns all user-defined or built-in functions with the given name.

Returns:
unmodifiable Collection of Function

getApplicableFunc

public Function getApplicableFunc(java.lang.String name,
                                  Type[] types)
Returns the user-defined or built-in Function with the given name that is applicable to the given type list, or null if no such function exists. If both a user-defined function and a built-in function apply, then the user-defined one is returned. We assume that there is not more than one user-defined function that applies.


getOverlappingFuncs

public java.util.Collection getOverlappingFuncs(java.lang.String name,
                                                Type[] types)
Returns the user-defined or built-in functions with the given name that could apply to some tuple of objects with the given types. There could be multiple such functions if the given tuple contains a very general type, and several existing functions apply to different subtypes of that type.

Returns:
unmodifiable Collection of Function

getRandomFunc

public java.lang.Object getRandomFunc(java.lang.String name,
                                      int numArgs)
Returns the unique random function with the given name and number of arguments. If there are no random functions matching this description, returns null. If there is more than one such function, returns the special object Model.MULTIPLE_FUNCTIONS. This method exists to support dependency statements that don't state the types of arguments.


getFunctions

public java.util.Collection getFunctions()
Returns the user-defined functions in this model.

Returns:
unmodifiable Collection of Function

getConstantValue

public java.lang.Object getConstantValue(java.lang.String name)
Returns the value of the non-random constant with the given name, or null if there is no such non-random constant. This method works only for user-defined constants and the built-in constants "true" and "false", not for other constants such as numeric or string literals.


addEnumeratedObject

public NonRandomFunction addEnumeratedObject(java.lang.String name,
                                             Type type)
Adds to the model a non-random constant with the given name, denoting a new enumerated object of the given type.

Returns:
the new non-random constant. To get its value (the new enumerated object), use its getValue() method.

addParfactor

public void addParfactor(fove.Parfactor pf)
Adds the given parfactor to this model.


getParfactors

public java.util.List<fove.Parfactor> getParfactors()
Returns the parfactors in this model, in the order they were declared.

Returns:
unmodifiable list of parfactors

print

public void print(java.io.PrintStream s)
Prints this model to the given stream.


checkTypesAndScope

public boolean checkTypesAndScope()
Check types and scopes in the model. Also turns function names into Function objects, and variable names into LogicalVar objects. Returns true if no errors; otherwise prints error messages and returns false. The distinction between this method and compile is that this method does all its processing in the order in which functions were declared, whereas compile may jump around following the uses of nonrandom functions.


checkCompleteness

public boolean checkCompleteness()
Returns true if every random function has a dependency statement, or if the model contains at least one parfactor. Otherwise prints appropriate error messages and returns false.


compile

public int compile()
Does compilation steps that can only be done correctly once the model is complete. Prints messages to standard error if any errors are encountered. Returns the number of errors encountered.


nextCreationIndex

public static int nextCreationIndex()
Returns a number that is one greater than the last number returned by this method.


compareArgs

public static int compareArgs(java.lang.Object obj1,
                              java.lang.Object obj2)
Compares two objects that can serve as arguments to basic random variables. The overall order is: Booleans, then integers, then timesteps, then guaranteed objects of user-defined types, then tuple representations of non-guaranteed objects, then object identifiers. Non-guaranteed objects have their own comparison method based on depths and generating objects. Guaranteed objects are compared first by the order in which their types were defined, then based on order within their type.


compareArgTuples

public static int compareArgTuples(java.lang.Object[] objs1,
                                   java.lang.Object[] objs2)
Returns a number that is negative, positive, or zero according to whether objs1 comes before, after, or at the same place as objs2 in a lexicographic ordering.

Parameters:
objs1 - an array of BLOG objects that can serve as arguments
objs2 - an array of BLOG objects that can serve as arguments

getObjectIndex

public static int getObjectIndex(java.lang.Object obj)
Returns the index of the given object among objects of its type. The index of a Boolean value is 0 for TRUE and 1 for FALSE; the index of a natural number is the number itself; and the index for a user-defined guaranteed object is determined by the order in which guaranteed objects of that type were declared (starting at 0). Other objects do not have indices; this method returns -1 for them.