org.deduced
Class DeducedUtilities

java.lang.Object
  extended by org.deduced.DeducedUtilities

public final class DeducedUtilities
extends java.lang.Object

Utility methods to analyze property collections

Author:
Steve McDuff

Constructor Summary
DeducedUtilities()
           
 
Method Summary
private static void addAllModelLayersInListToNameReferenceFinder(NameReferenceFinderImplementation nameReferenceFinder, PropertyCollection<?,?> layerList)
          parse a List of possible model layers And Add them all to a name Reference finder
private static void addModelLayerCollectionListToNameReferenceFinder(PropertyCollection<?,?> modelLayer, NameReferenceFinderImplementation nameReferenceFinder)
          add Model Layer collection List To Name Reference Finder
private static void addModelLayerDependentModelListToNameReferenceFinder(PropertyCollection<?,?> modelLayer, NameReferenceFinderImplementation nameReferenceFinder)
          add Model Layer Dependent Model List To Name Reference Finder
private static void addModelLayerToNameReferenceFinderIfNameIsValid(PropertyCollection<?,?> modelLayer, NameReferenceFinderImplementation nameReferenceFinder)
          add Model Layer To Name Reference Finder only if it has a valid name
private static void addPossibleModelLayerAndChildModelsToNameReferenceFinder(PropertyCollection<?,?> modelLayer, NameReferenceFinderImplementation nameReferenceFinder)
          add Model Layer and child models To Name Reference Finder
private static void clearRemainingArraySpace(int clearStartIndex, java.lang.Object[] arrayToClear)
          Reset all array slots to null starting with clearStartIndex until the end of the array
static
<T> T[]
copyArrayToArray(T[] arrayToModify, java.lang.Object[] sourceArray, int size)
          Utility method used to convert a source array to a destination array.
static
<T,V> T[]
copyCollectionToArray(T[] array, java.util.Collection<V> collectionToConvert)
          Utility method used to convert a collection to an array.
static NameReferenceFinder createNamedReferenceFinderFromModelLayer(PropertyCollection<?,?> modelLayer)
          create a Named Reference Finder From a Model Layer
static void deleteQuietly(PropertyCollection<?,?> collectionToDelete)
          delete a collection quietly
static PropertyCollection<?,?> findChildByName(PropertyCollection<?,?> listToSearch, java.lang.String nameToFind)
          find a child property collection by name
static
<K,V,CK,X extends PropertyCollection<CK,? super V>>
X
findChildPropertyCollection(PropertyCollection<K,X> collectionToSearch, CK keyOnChildCollection, V valueOnChildCollection)
          Find a child collection from the collection to search that has a property matching the specified key and value
static
<K,V,CK,X extends PropertyCollection<CK,? super V>>
X
findChildPropertyCollectionByValueInstance(PropertyCollection<K,X> collectionToSearch, CK keyOnChildCollection, V valueOnChildCollection)
          Find a child collection from the collection to search that has a property matching the specified key and value with the identity == operator.
static
<K,V,CK,X extends PropertyCollection<CK,V>>
K
findChildPropertyCollectionKey(PropertyCollection<K,X> collectionToSearch, CK keyOnChildCollection, V valueOnChildCollection)
          Find a child collection from the collection to search that has a property matching the specified key and value
static PropertyCollection<?,?> findPackageInSchema(PropertyCollection<?,?> schema, java.lang.String[] packageNameList)
          find a property package in a schema
static boolean getBooleanProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a boolean property form a collection
static java.lang.String getCollectionName(PropertyCollection<?,?> collection)
          Fetch the name from a collection.
static PropertyCollection<?,?> getCollectionProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a PropertyCollection property form a collection
static PropertyCollection<?,?> getCollectionRoot(PropertyCollection<?,?> collection)
          Fetch the root object that owns the whole object tree in which the specified collection is a part of.
static int getDistanceBetweenTypes(PropertyCollection<?,?> objectType, PropertyCollection<?,?> testType)
          finds out how many inheritance level is required to reach type
private static int getDistanceOnAbstractCollection(PropertyCollection<?,?> objectType, PropertyCollection<?,?> testType, int level)
          internal recursive method to find the inheritance distance between two types.
static double getDoubleProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a double property form a collection
static float getFloatProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a float property form a collection
protected static PropertyCollection<?,?> getInstanceType(PropertyCollection<?,?> collection)
          Get the value of the instance : instance type
static int getIntegerProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a integer property form a collection
protected static java.lang.String getNamePropertyValue(PropertyCollection<?,?> namedCollection)
          get Name Property Value
static java.util.List<PropertyCollection<?,?>> getOrderedParentList(PropertyCollection<?,?> collection)
          fetch the list of parents from the root node to the specified collection
protected static PropertyCollection<?,?> getParentList(PropertyCollection<?,?> collection)
          Get the value of the instance : parent list
static PropertyCollection<?,?> getParentOfType(PropertyCollection<?,?> propertyCollection, PropertyCollection<?,?> modelType)
          fetch the parent of a collection that matches a certain type
static PropertyCollection<?,?> getPropertyCollectionTypeType()
          Utility method to get the basic PropertyCollectionType type
protected static PropertyCollection<?,?> getPropertyInstanceList(PropertyCollection<?,?> collection)
          Get the value of the instance : property instance list
static PropertyCollection<?,?> getPropertyPackagePropertyPackageList(PropertyCollection<?,?> collection)
          Utility method to get the list of sub package from a property package
static java.lang.String getStringProperty(PropertyCollection<?,?> collection, java.lang.Object key)
          Utility method to get a String property form a collection
static boolean isInstanceOf(PropertyCollection<?,?> objectType, PropertyCollection<?,?> testType)
          Check if the object type contains the test type in it's parent hierarchy
protected static boolean isInstanceReference(PropertyCollection<?,?> instance)
          return the is reference flag of a property instance.
static boolean isInstanceTypeCollection(PropertyCollection<?,?> instance)
          check to see if the instance type of a property instance is a property collection
private static boolean isModelLayer(PropertyCollection<?,?> possibleModelLayer)
          test if a collection is a model layer
static boolean isParentCollection(PropertyCollection<?,?> possibleParent, PropertyCollection<?,?> possibleChild)
          check to see if a possible parent is a parent of the specified child collection
static boolean isTypeCollection(PropertyCollection<?,?> type)
          check if a type is used to define a property collection type
static
<K,V> void
removeListenerSilent(PropertyCollection<K,V> collection, PropertyListener<? super K,? super V> listener)
          remove a property Listener Silently to a collection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeducedUtilities

public DeducedUtilities()
Method Detail

isInstanceOf

public static boolean isInstanceOf(PropertyCollection<?,?> objectType,
                                   PropertyCollection<?,?> testType)
Check if the object type contains the test type in it's parent hierarchy

Parameters:
objectType - the object type
testType - the type that might be a parent
Returns:
true if the test type is a parent of the object type.

getDistanceBetweenTypes

public static int getDistanceBetweenTypes(PropertyCollection<?,?> objectType,
                                          PropertyCollection<?,?> testType)
finds out how many inheritance level is required to reach type

Parameters:
objectType - the lower type
testType - the parent type
Returns:
the number of inheritance steps between the two types. Returns -1 if there is no relationship. 0 if the types are the same.

getDistanceOnAbstractCollection

private static int getDistanceOnAbstractCollection(PropertyCollection<?,?> objectType,
                                                   PropertyCollection<?,?> testType,
                                                   int level)
internal recursive method to find the inheritance distance between two types.

Parameters:
objectType - the object type
testType - the type that might be in the parent list of the object type
level - the current inheritance level depth
Returns:
the inheritance level depth or Integer.MAX_VALUE if there are no relationships between the types.

getOrderedParentList

public static java.util.List<PropertyCollection<?,?>> getOrderedParentList(PropertyCollection<?,?> collection)
fetch the list of parents from the root node to the specified collection

Parameters:
collection - the last collection
Returns:
the list of parents from the root node to the specified collection

getCollectionRoot

public static PropertyCollection<?,?> getCollectionRoot(PropertyCollection<?,?> collection)
Fetch the root object that owns the whole object tree in which the specified collection is a part of.

Parameters:
collection - the collection in the tree
Returns:
the root parent

copyCollectionToArray

public static <T,V> T[] copyCollectionToArray(T[] array,
                                              java.util.Collection<V> collectionToConvert)
Utility method used to convert a collection to an array. The first array used as a parameter will be modified to contain the list of values contained in the collection. If the array is too small, it will be enlarged to fit the size of the collection. If the array is too big, remaining slots in the array will be set to null

Type Parameters:
T - the object type in the array to modify and return
V - the type of value from the collection to convert to array
Parameters:
array - the array that might be modified if the array is big enough
collectionToConvert - the collection that will be read and used to fill the returned array
Returns:
the array of values contained in the collection to convert

clearRemainingArraySpace

private static void clearRemainingArraySpace(int clearStartIndex,
                                             java.lang.Object[] arrayToClear)
Reset all array slots to null starting with clearStartIndex until the end of the array

Parameters:
clearStartIndex - the start index that will be used to clear the array
arrayToClear - the array to start clearing

copyArrayToArray

public static <T> T[] copyArrayToArray(T[] arrayToModify,
                                       java.lang.Object[] sourceArray,
                                       int size)
Utility method used to convert a source array to a destination array. The first array used as a parameter will be modified to contain the list of values contained in the sourceArray. If the array is too small, it will be enlarged to fit the size of the collection. If the array is too big, remaining slots in the array will be set to null

Type Parameters:
T - the object type in the array to modify and return
Parameters:
arrayToModify - the array that might be modified if the array is big enough
sourceArray - the array that will be read and used to fill the returned array
size - size of the source array to copy.
Returns:
the array of values contained in the collection to convert

getCollectionName

public static java.lang.String getCollectionName(PropertyCollection<?,?> collection)
Fetch the name from a collection.

Parameters:
collection - the collection from which to fetch the name
Returns:
the name of the collection. If the collection is null, null is returned. If the collection isn't of type : NamedPropertyCollection, null is returned.

getPropertyPackagePropertyPackageList

public static PropertyCollection<?,?> getPropertyPackagePropertyPackageList(PropertyCollection<?,?> collection)
Utility method to get the list of sub package from a property package

Parameters:
collection - the property package
Returns:
the child package list

getBooleanProperty

public static boolean getBooleanProperty(PropertyCollection<?,?> collection,
                                         java.lang.Object key)
Utility method to get a boolean property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a native boolean

getIntegerProperty

public static int getIntegerProperty(PropertyCollection<?,?> collection,
                                     java.lang.Object key)
Utility method to get a integer property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a native integer

getFloatProperty

public static float getFloatProperty(PropertyCollection<?,?> collection,
                                     java.lang.Object key)
Utility method to get a float property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a native float

getDoubleProperty

public static double getDoubleProperty(PropertyCollection<?,?> collection,
                                       java.lang.Object key)
Utility method to get a double property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a native double

getStringProperty

public static java.lang.String getStringProperty(PropertyCollection<?,?> collection,
                                                 java.lang.Object key)
Utility method to get a String property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a String

getCollectionProperty

public static PropertyCollection<?,?> getCollectionProperty(PropertyCollection<?,?> collection,
                                                            java.lang.Object key)
Utility method to get a PropertyCollection property form a collection

Parameters:
collection - the collection from which to fetch the value
key - the property key
Returns:
the property value as a PropertyCollection

getPropertyCollectionTypeType

public static PropertyCollection<?,?> getPropertyCollectionTypeType()
Utility method to get the basic PropertyCollectionType type

Returns:
the basic PropertyCollectionType type

isInstanceTypeCollection

public static boolean isInstanceTypeCollection(PropertyCollection<?,?> instance)
check to see if the instance type of a property instance is a property collection

Parameters:
instance - the property instance
Returns:
true if the instance type is a property collection type

isTypeCollection

public static boolean isTypeCollection(PropertyCollection<?,?> type)
check if a type is used to define a property collection type

Parameters:
type - the type to verify
Returns:
true if the type is a property collection

findPackageInSchema

public static PropertyCollection<?,?> findPackageInSchema(PropertyCollection<?,?> schema,
                                                          java.lang.String[] packageNameList)
find a property package in a schema

Parameters:
schema - the schema to search from
packageNameList - the list of package names
Returns:
the matching package

findChildByName

public static PropertyCollection<?,?> findChildByName(PropertyCollection<?,?> listToSearch,
                                                      java.lang.String nameToFind)
find a child property collection by name

Parameters:
listToSearch - the list of named property collections
nameToFind - the name to find
Returns:
the first child collection that matches the required name

getParentOfType

public static PropertyCollection<?,?> getParentOfType(PropertyCollection<?,?> propertyCollection,
                                                      PropertyCollection<?,?> modelType)
fetch the parent of a collection that matches a certain type

Parameters:
propertyCollection - the collection to search from
modelType - the type to look for
Returns:
the matched parent of type

findChildPropertyCollectionKey

public static <K,V,CK,X extends PropertyCollection<CK,V>> K findChildPropertyCollectionKey(PropertyCollection<K,X> collectionToSearch,
                                                                                           CK keyOnChildCollection,
                                                                                           V valueOnChildCollection)
Find a child collection from the collection to search that has a property matching the specified key and value

Type Parameters:
K - the key type on the collection to search
V - the value type to search for on the child collections
CK - the key type on the child collections
X - the type of child collections on the collection to search
Parameters:
collectionToSearch - the collection to search
keyOnChildCollection - the child property key
valueOnChildCollection - the value of the child property
Returns:
the key of the child collection

findChildPropertyCollection

public static <K,V,CK,X extends PropertyCollection<CK,? super V>> X findChildPropertyCollection(PropertyCollection<K,X> collectionToSearch,
                                                                                                CK keyOnChildCollection,
                                                                                                V valueOnChildCollection)
Find a child collection from the collection to search that has a property matching the specified key and value

Type Parameters:
K - the key type on the collection to search
V - the value type to search for on the child collections
CK - the key type on the child collections
X - the type of child collections on the collection to search
Parameters:
collectionToSearch - the collection to search
keyOnChildCollection - they key of the child property
valueOnChildCollection - the value of the child property
Returns:
the child collection

findChildPropertyCollectionByValueInstance

public static <K,V,CK,X extends PropertyCollection<CK,? super V>> X findChildPropertyCollectionByValueInstance(PropertyCollection<K,X> collectionToSearch,
                                                                                                               CK keyOnChildCollection,
                                                                                                               V valueOnChildCollection)
Find a child collection from the collection to search that has a property matching the specified key and value with the identity == operator.

Type Parameters:
K - the key type on the collection to search
V - the value type to search for on the child collections
CK - the key type on the child collections
X - the type of child collections on the collection to search
Parameters:
collectionToSearch - the collection to search
keyOnChildCollection - they key of the child property
valueOnChildCollection - the value of the child property
Returns:
the child collection

isParentCollection

public static boolean isParentCollection(PropertyCollection<?,?> possibleParent,
                                         PropertyCollection<?,?> possibleChild)
check to see if a possible parent is a parent of the specified child collection

Parameters:
possibleParent - the possible parent
possibleChild - the possible child collection
Returns:
true if the possible parent is a parent of the child collection. False otherwise.

removeListenerSilent

public static <K,V> void removeListenerSilent(PropertyCollection<K,V> collection,
                                              PropertyListener<? super K,? super V> listener)
remove a property Listener Silently to a collection

Type Parameters:
K - the collection key type
V - the collection value type
Parameters:
listener - the listener to remove
collection - the collection from which to remove the listener

deleteQuietly

public static void deleteQuietly(PropertyCollection<?,?> collectionToDelete)
delete a collection quietly

Parameters:
collectionToDelete - the collection to delete

createNamedReferenceFinderFromModelLayer

public static NameReferenceFinder createNamedReferenceFinderFromModelLayer(PropertyCollection<?,?> modelLayer)
                                                                    throws java.lang.IllegalArgumentException
create a Named Reference Finder From a Model Layer

Parameters:
modelLayer - the model layer
Returns:
the created name reference finder
Throws:
java.lang.IllegalArgumentException - if the model isn't an instance of deduced model layer.

addPossibleModelLayerAndChildModelsToNameReferenceFinder

private static void addPossibleModelLayerAndChildModelsToNameReferenceFinder(PropertyCollection<?,?> modelLayer,
                                                                             NameReferenceFinderImplementation nameReferenceFinder)
add Model Layer and child models To Name Reference Finder

Parameters:
modelLayer - the model layer to add
nameReferenceFinder - the name reference finder in which to add the model and it's child models.

isModelLayer

private static boolean isModelLayer(PropertyCollection<?,?> possibleModelLayer)
test if a collection is a model layer

Parameters:
possibleModelLayer - the possible model layer
Returns:
true if the collection is a model layer

addModelLayerDependentModelListToNameReferenceFinder

private static void addModelLayerDependentModelListToNameReferenceFinder(PropertyCollection<?,?> modelLayer,
                                                                         NameReferenceFinderImplementation nameReferenceFinder)
add Model Layer Dependent Model List To Name Reference Finder

Parameters:
modelLayer - the model layer to use
nameReferenceFinder - the name reference finder to use

addModelLayerCollectionListToNameReferenceFinder

private static void addModelLayerCollectionListToNameReferenceFinder(PropertyCollection<?,?> modelLayer,
                                                                     NameReferenceFinderImplementation nameReferenceFinder)
add Model Layer collection List To Name Reference Finder

Parameters:
modelLayer - the model layer to use
nameReferenceFinder - the name reference finder to use

addModelLayerToNameReferenceFinderIfNameIsValid

private static void addModelLayerToNameReferenceFinderIfNameIsValid(PropertyCollection<?,?> modelLayer,
                                                                    NameReferenceFinderImplementation nameReferenceFinder)
add Model Layer To Name Reference Finder only if it has a valid name

Parameters:
modelLayer - the model layer to add
nameReferenceFinder - the name reference finder in which to register the model layer

getNamePropertyValue

protected static java.lang.String getNamePropertyValue(PropertyCollection<?,?> namedCollection)
get Name Property Value

This method is used to remove dependencies from the deduced package to the deduced.implementation package. The normal method to use is the one found in the generated implementation.

Parameters:
namedCollection - the named collection
Returns:
the collection name

addAllModelLayersInListToNameReferenceFinder

private static void addAllModelLayersInListToNameReferenceFinder(NameReferenceFinderImplementation nameReferenceFinder,
                                                                 PropertyCollection<?,?> layerList)
parse a List of possible model layers And Add them all to a name Reference finder

Parameters:
nameReferenceFinder - the name reference finder to fill
layerList - the list of layers

isInstanceReference

protected static boolean isInstanceReference(PropertyCollection<?,?> instance)
return the is reference flag of a property instance.

This method is used to remove dependencies from the deduced package to the deduced.implementation package. The normal method to use is the one found in the generated implementation.

Parameters:
instance - the instance from which to fetch the reference flag.
Returns:
the reference flag.

getParentList

protected static PropertyCollection<?,?> getParentList(PropertyCollection<?,?> collection)
Get the value of the instance : parent list

This method is used to remove dependencies from the deduced package to the deduced.implementation package. The normal method to use is the one found in the generated implementation.

Parameters:
collection - new collection from which to fetch the value
Returns:
parent list

getPropertyInstanceList

protected static PropertyCollection<?,?> getPropertyInstanceList(PropertyCollection<?,?> collection)
Get the value of the instance : property instance list

This method is used to remove dependencies from the deduced package to the deduced.implementation package. The normal method to use is the one found in the generated implementation.

Parameters:
collection - new collection from which to fetch the value
Returns:
property instance list

getInstanceType

protected static PropertyCollection<?,?> getInstanceType(PropertyCollection<?,?> collection)
Get the value of the instance : instance type

This method is used to remove dependencies from the deduced package to the deduced.implementation package. The normal method to use is the one found in the generated implementation.

Parameters:
collection - new collection from which to fetch the value
Returns:
instance type