edu.ucla.belief
Class FiniteVariableImpl

Object
  extended by VariableImpl
      extended by FiniteVariableImpl
All Implemented Interfaces:
FiniteVariable, Variable, Cloneable, Comparable
Direct Known Subclasses:
StandardNodeImpl

public class FiniteVariableImpl
extends VariableImpl
implements FiniteVariable

A class for representing finite variables. It consists of a name as well as a list of possible values.


Field Summary
 
Fields inherited from class VariableImpl
id, INT_NUM_PROPERTIES, theCollator, userobject
 
Constructor Summary
FiniteVariableImpl(FiniteVariable toCopy)
           
FiniteVariableImpl(FiniteVariable toCopy, DSLNodeType type, CPTShell shell)
           
FiniteVariableImpl(String id, List instances)
           
FiniteVariableImpl(String id, Object[] instances)
          Creates a new Finite variable.
 
Method Summary
 Object clone()
           
 boolean contains(Object instance)
           
static FiniteVariableImpl debugInstance()
           
static Map deepCloneMapTypesToShells(FiniteVariable toCopy)
           
static Collection findVariablesForType(Collection bn, DSLNodeType target, Collection ret)
          moved from DSLNodeType 20081110
 CPTShell getCPTShell()
           
 CPTShell getCPTShell(DSLNodeType type)
           
 DSLNodeType getDSLNodeType()
          moved from DSLNode 010905
 int grep(Filter filter, Collection results)
           
 int grep(Matcher matcher, boolean invert, Collection results)
           
 int grep(Pattern pattern, boolean invert, Collection results)
           
 int index(Object instance)
          Returns the index associated with the instance.
 boolean insert(int index, Object instance)
           
 Object instance(int index)
          Returns the instance associated with the index.
 Object instance(String name)
          Returns the instance represented by the string.
 List instances()
           
 Object remove(int index)
           
 Object set(int index, Object objNew)
           
 void setCPTShell(CPTShell shell)
          Deprecated.  
 void setCPTShell(DSLNodeType type, CPTShell shell)
           
 void setDSLNodeType(DSLNodeType newVal)
          moved from DSLNode 010905
 int size()
          Returns the number of possible values.
static long size(Collection vars)
          Returns the number of instantiations of the collection of variables.
static FiniteVariable thereExists(Collection bn, DSLNodeType target)
          moved from DSLNodeType 20081110
 String toString()
           
 
Methods inherited from class VariableImpl
compareTo, delete, forID, getEnumProperties, getID, getNumProperties, getProperty, getStringifier, getUserObject, index, initProperties, isStringifier, propertiesArrayCopy, setID, setProperty, setStringifier, setUserObject, validatePropertyNameAndID
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Variable
delete, getEnumProperties, getID, getProperty, getUserObject, setID, setProperty, setUserObject
 
Methods inherited from interface Comparable
compareTo
 

Constructor Detail

FiniteVariableImpl

public FiniteVariableImpl(String id,
                          Object[] instances)
Creates a new Finite variable.

Parameters:
name - the name the Variable will be known by.
instances - the list of instances this variable can take on. These may be of any type.

FiniteVariableImpl

public FiniteVariableImpl(String id,
                          List instances)

FiniteVariableImpl

public FiniteVariableImpl(FiniteVariable toCopy)
Since:
20020603

FiniteVariableImpl

public FiniteVariableImpl(FiniteVariable toCopy,
                          DSLNodeType type,
                          CPTShell shell)
Since:
20071225 xmas
Method Detail

grep

public int grep(Filter filter,
                Collection results)
Specified by:
grep in interface FiniteVariable
Parameters:
results - accumulate matches
Returns:
count matched
Since:
20070419

grep

public int grep(Pattern pattern,
                boolean invert,
                Collection results)
Specified by:
grep in interface FiniteVariable
Parameters:
invert - invert the sense of the grep, i.e. add non-matches
results - accumulate matches
Returns:
count matched
Since:
20070329

grep

public int grep(Matcher matcher,
                boolean invert,
                Collection results)
Specified by:
grep in interface FiniteVariable
Parameters:
invert - invert the sense of the grep, i.e. add non-matches
results - accumulate matches
Returns:
count matched
Since:
20070329

deepCloneMapTypesToShells

public static Map deepCloneMapTypesToShells(FiniteVariable toCopy)
Since:
010905

clone

public Object clone()
Specified by:
clone in interface Variable
Specified by:
clone in class VariableImpl
Since:
060302

instances

public List instances()
Specified by:
instances in interface FiniteVariable

set

public Object set(int index,
                  Object objNew)
Specified by:
set in interface FiniteVariable

insert

public boolean insert(int index,
                      Object instance)
Specified by:
insert in interface FiniteVariable

remove

public Object remove(int index)
Specified by:
remove in interface FiniteVariable

getCPTShell

public CPTShell getCPTShell()
Specified by:
getCPTShell in interface FiniteVariable

setCPTShell

public void setCPTShell(CPTShell shell)
Deprecated. 

Specified by:
setCPTShell in interface FiniteVariable

getCPTShell

public CPTShell getCPTShell(DSLNodeType type)
Specified by:
getCPTShell in interface FiniteVariable
Since:
010905

setCPTShell

public void setCPTShell(DSLNodeType type,
                        CPTShell shell)
Specified by:
setCPTShell in interface FiniteVariable
Since:
010905

getDSLNodeType

public DSLNodeType getDSLNodeType()
Description copied from interface: FiniteVariable
moved from DSLNode 010905

Specified by:
getDSLNodeType in interface FiniteVariable
Since:
010905

setDSLNodeType

public void setDSLNodeType(DSLNodeType newVal)
Description copied from interface: FiniteVariable
moved from DSLNode 010905

Specified by:
setDSLNodeType in interface FiniteVariable
Since:
010905

findVariablesForType

public static Collection findVariablesForType(Collection bn,
                                              DSLNodeType target,
                                              Collection ret)
moved from DSLNodeType 20081110

Since:
20051107

thereExists

public static FiniteVariable thereExists(Collection bn,
                                         DSLNodeType target)
moved from DSLNodeType 20081110

Since:
20051107

size

public int size()
Returns the number of possible values.

Specified by:
size in interface FiniteVariable

instance

public Object instance(int index)
Returns the instance associated with the index.

Specified by:
instance in interface FiniteVariable

instance

public Object instance(String name)
Returns the instance represented by the string. Linearly searches the instances, so should be used sparingly.

Specified by:
instance in interface FiniteVariable
Specified by:
instance in interface Variable

index

public int index(Object instance)
Returns the index associated with the instance. Returns -1 if instance is not one of the values this variable can take on.

Specified by:
index in interface FiniteVariable

contains

public boolean contains(Object instance)
Specified by:
contains in interface FiniteVariable

toString

public String toString()
Overrides:
toString in class Object

size

public static long size(Collection vars)
Returns the number of instantiations of the collection of variables. It returns a long only because reasonable sized sets sometimes overflow ints.


debugInstance

public static FiniteVariableImpl debugInstance()
Since:
031003


Copyright 2010 UCLA Automated Reasoning Group