korat.finitization.impl
Class ObjSet

java.lang.Object
  extended by korat.finitization.impl.FieldDomain
      extended by korat.finitization.impl.ObjSet
All Implemented Interfaces:
IFieldDomain, IObjSet

public class ObjSet
extends FieldDomain
implements IObjSet

Author:
Aleksandar Milicevic

Nested Class Summary
(package private) static class ObjSet.CacheElement
           
 
Field Summary
private  List<ObjSet.CacheElement> cache
           
protected  List<ClassDomain> domains
           
private  boolean isCacheValid
           
private  boolean nullAllowed
           
 
Fields inherited from class korat.finitization.impl.FieldDomain
classOfField
 
Constructor Summary
ObjSet(Class classOfField)
           
ObjSet(String classOfFieldName)
           
 
Method Summary
 boolean addClassDomain(IClassDomain domain)
          Adds new class domain.
 Object[] getAllObjects()
          Returns all objest in entire IObjSet.Those are all objects that can be assigned to the field that this IFieldDomain is assigned to.
 ClassDomain getClassDomain(int classDomainIndex)
          Returns the class domain for the given index

primitive types should return null.

 ClassDomain getClassDomainFor(int objectIndex)
          Finds the class domain for given object index by calling getClassDomainFor(objectIndex) and returns the following class domain.
 int getClassDomainIndexFor(int objectIndex)
          Given the index of object in this field domain, returns index of that object in its class domain.
 List<IClassDomain> getClassDomains()
          Returns the list of all class domains
 int getIndexOfFirstObjectInNextClassDomain(int objectIndex)
           
 ClassDomain getNextClassDomainFor(int objectIndex)
          Finds the class domain for given object index by calling getClassDomainFor(objectIndex) and returns the following class domain.
 int getNumberOfElements()
          Number of all elements in this field domain.
 int getNumOfClassDomains()
          Number of class domains contained in this field domain.
 Object getObject(int objectIndex)
          Returns object with the given index in entire ObjSet.
 Object[] getObjectsOfClass(Class cls)
          Returns instances (direct or indirect) of the given class in entire IObjSet
 Object[] getObjectsOfClass(int classDomainIndex)
          Returns instances of the class domain with the given index in this ObjSet.
 int getSizeOfClassDomain(int classDomainIndex)
          Number of object in the class domain which is at a classDomainIndex position in the list of all class domains within this field domain.
 boolean isArrayType()
          Does this field domain represent array type.
 boolean isNullAllowed()
          Is null allowed or not.
 boolean isPrimitiveType()
          Does this field domain represent primitive type.
 boolean removeClassDomain(IClassDomain domain)
          Removes class domain from this IObjSet
 ClassDomain removeClassDomain(int index)
          Removes class domain from IObjSet
 void setNullAllowed(boolean allowed)
          Sets whether null is allowed or not.
private  void updateCache()
           
 
Methods inherited from class korat.finitization.impl.FieldDomain
checkClassDomainIndex, checkObjectIndex, getClassOfField
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface korat.finitization.IFieldDomain
getClassOfField
 

Field Detail

cache

private List<ObjSet.CacheElement> cache

isCacheValid

private boolean isCacheValid

domains

protected List<ClassDomain> domains

nullAllowed

private boolean nullAllowed
Constructor Detail

ObjSet

ObjSet(Class classOfField)

ObjSet

ObjSet(String classOfFieldName)
 throws ClassNotFoundException
Throws:
ClassNotFoundException
Method Detail

updateCache

private void updateCache()

addClassDomain

public boolean addClassDomain(IClassDomain domain)
Description copied from interface: IObjSet
Adds new class domain. classOfObjects of the given IClassDomain must be assignable to the classOfField of this IObjSet.

Specified by:
addClassDomain in interface IObjSet
Parameters:
domain - Class domain
Returns:
if class domain is already added, return false else return true
Throws:
IllegalArgumentException - - if this field is not assignable from the given class domain
See Also:
IFieldDomain.getClassOfField(), IClassDomain.getClassOfObjects(), IFieldDomain, IClassDomain

removeClassDomain

public boolean removeClassDomain(IClassDomain domain)
Description copied from interface: IObjSet
Removes class domain from this IObjSet

Specified by:
removeClassDomain in interface IObjSet
Parameters:
domain - Class domain to be removed
Returns:
returns true if domain existed in this field domain

removeClassDomain

public ClassDomain removeClassDomain(int index)
Description copied from interface: IObjSet
Removes class domain from IObjSet

Specified by:
removeClassDomain in interface IObjSet
Parameters:
index - index of class domain to be removed. If index is out of bounds, should return null instead of throwing an exception
Returns:
removed class domain
See Also:
IObjSet.removeClassDomain(IClassDomain)

getClassDomains

public List<IClassDomain> getClassDomains()
Description copied from interface: IObjSet
Returns the list of all class domains

Specified by:
getClassDomains in interface IObjSet
Returns:
list of all class domains

getClassDomain

public ClassDomain getClassDomain(int classDomainIndex)
Description copied from class: FieldDomain
Returns the class domain for the given index

primitive types should return null.

Specified by:
getClassDomain in class FieldDomain
Parameters:
classDomainIndex - - the index of the class domain
Returns:
class domain

getClassDomainFor

public ClassDomain getClassDomainFor(int objectIndex)
Description copied from class: FieldDomain
Finds the class domain for given object index by calling getClassDomainFor(objectIndex) and returns the following class domain.

Primitive types should return null.

Specified by:
getClassDomainFor in class FieldDomain
Parameters:
objectIndex - - the index of the given object
Returns:
the class domain following the class domain that contains given object.
See Also:


getNextClassDomainFor

public ClassDomain getNextClassDomainFor(int objectIndex)
Description copied from class: FieldDomain
Finds the class domain for given object index by calling getClassDomainFor(objectIndex) and returns the following class domain.

Primitive typess should return null.

Specified by:
getNextClassDomainFor in class FieldDomain
Parameters:
objectIndex - - the index of the given object
Returns:
the class domain following the class domain that contains given object.
See Also:


getNumOfClassDomains

public int getNumOfClassDomains()
Description copied from class: FieldDomain
Number of class domains contained in this field domain.

Primitive types should return 1.

Specified by:
getNumOfClassDomains in interface IFieldDomain
Specified by:
getNumOfClassDomains in class FieldDomain
Returns:
number of class domains in this field domain
See Also:
IPrimitiveTypeSet

getSizeOfClassDomain

public int getSizeOfClassDomain(int classDomainIndex)
Description copied from class: FieldDomain
Number of object in the class domain which is at a classDomainIndex position in the list of all class domains within this field domain.

Primitive types should return -1 if classDomainIndex is different than 0, or getNumberOfElements() else.

Specified by:
getSizeOfClassDomain in class FieldDomain
Parameters:
classDomainIndex - - class domain index
Returns:
number of objects in domain with index classDomainIndex
See Also:


getNumberOfElements

public int getNumberOfElements()
Description copied from class: FieldDomain
Number of all elements in this field domain. These are all elements that can be assigned to a field associated with this field domain in the process of generating test cases.

Specified by:
getNumberOfElements in interface IFieldDomain
Specified by:
getNumberOfElements in class FieldDomain
Returns:
overall number of elements in field domain

isPrimitiveType

public boolean isPrimitiveType()
Description copied from interface: IFieldDomain
Does this field domain represent primitive type.

Specified by:
isPrimitiveType in interface IFieldDomain
Returns:
true for primitive data types and strings, false otherwise

isArrayType

public boolean isArrayType()
Description copied from interface: IFieldDomain
Does this field domain represent array type.

Specified by:
isArrayType in interface IFieldDomain
Returns:
true if class of this FieldDomain is array, false otherwise

getAllObjects

public Object[] getAllObjects()
Description copied from interface: IObjSet
Returns all objest in entire IObjSet.Those are all objects that can be assigned to the field that this IFieldDomain is assigned to.

Specified by:
getAllObjects in interface IObjSet
Returns:
all objects in this field domain.

getObjectsOfClass

public Object[] getObjectsOfClass(Class cls)
Description copied from interface: IObjSet
Returns instances (direct or indirect) of the given class in entire IObjSet

Specified by:
getObjectsOfClass in interface IObjSet
Parameters:
cls - base class
Returns:
objects of this field domain which are instances (direct or indirect) of the given class. If there are no such objects, returns zero-size array
See Also:
IObjSet.getAllObjects()

getObjectsOfClass

public Object[] getObjectsOfClass(int classDomainIndex)
Returns instances of the class domain with the given index in this ObjSet.

Parameters:
classDomainIndex - index of the class domain within this field domain
Returns:
objects of the class domain with the given index or zero-size array if classDomainIndex is invalid.
See Also:
getObjectsOfClass(Class), getObject(int), getAllObjects()

getObject

public Object getObject(int objectIndex)
Returns object with the given index in entire ObjSet.

Parameters:
objectIndex - - zero based index of the object in this field domain
Returns:
requested object. If isNullAllowed evaluates to true, the zero-index object in the ObjSet is always null. Also returns null if index is out of bounds.
See Also:
getAllObjects(), getObjectsOfClass(Class), getObjectsOfClass(int)

setNullAllowed

public void setNullAllowed(boolean allowed)
Description copied from interface: IObjSet
Sets whether null is allowed or not. By default null is not allowed.

Specified by:
setNullAllowed in interface IObjSet
Parameters:
allowed - whether null value is allowed.
See Also:
IObjSet.isNullAllowed()

isNullAllowed

public boolean isNullAllowed()
Description copied from interface: IObjSet
Is null allowed or not.

Specified by:
isNullAllowed in interface IObjSet
Returns:
is null allowed
See Also:
IObjSet.isNullAllowed()

getIndexOfFirstObjectInNextClassDomain

public int getIndexOfFirstObjectInNextClassDomain(int objectIndex)
Specified by:
getIndexOfFirstObjectInNextClassDomain in class FieldDomain

getClassDomainIndexFor

public int getClassDomainIndexFor(int objectIndex)
Description copied from class: FieldDomain
Given the index of object in this field domain, returns index of that object in its class domain.

For primitive types it's the same as the input parameter objectIndex because primitive type field domains conceptually contain exactly one class domain.

Specified by:
getClassDomainIndexFor in class FieldDomain
Parameters:
objectIndex - - index of object in the field domain
Returns:
index of object in its class domain