org.deduced.rule
Class DeductionRuleLibrary

java.lang.Object
  extended by org.deduced.rule.DeductionRuleLibrary
All Implemented Interfaces:
DeductionRuleAnalyzer<java.lang.Object>
Direct Known Subclasses:
GetFormattedMultiLanguageTextRule, GetMultiLanguageTextRule, IsCreateTypeValidRule, IsEnumerationValidRule, IsNullableValidRule, IsNumberValidRule, IsReferenceTypeValidRule, IsStringValidRule, SetIsValidBasedOnErrorMessageRule

public abstract class DeductionRuleLibrary
extends java.lang.Object
implements DeductionRuleAnalyzer<java.lang.Object>

DeductionRuleLibrary offers a set of quick methods to implement deduction rules

Author:
Steve McDuff

Nested Class Summary
static class DeductionRuleLibrary.CompareResult
          CompareResult is an utility class to store a collection and a value
 
Field Summary
private static java.text.SimpleDateFormat DATE_FORMAT
          date format
private static java.util.logging.Logger LOGGER
          Logger
private static java.text.SimpleDateFormat TIME_FORMAT
          time format
 
Constructor Summary
DeductionRuleLibrary()
           
 
Method Summary
static PropertyCollection addReferenceToList(PropertyCollection referenceToAdd, PropertyCollection list, boolean allowDuplicateReference)
          add a reference to a list.
private static void addToRemoveListIfNotMatched(boolean removeUnmatchedValues, java.util.List<PropertyCollection> objectsToRemove, java.util.Collection valuesToMatchClone, PropertyCollection currentCollection)
          add a collection To the Remove List If Not Matched
private static void addToRemoveListIfPropertyNotMatched(boolean removeUnmatchedValues, java.util.List<PropertyCollection> objectsToRemove, java.util.Collection valuesToMatchClone, PropertyCollection currentCollection, java.lang.Object propertyKey)
          add a collection To the Remove List If Not Matched
static Filter and(Filter firstFilter, Filter secondFilter)
          create an "and" filter
static Filter bigger(java.lang.Object value)
          Create a bigger than filter.
static Filter biggerOrEqual(java.lang.Object value)
          Create a bigger or equal to filter.
static void clearPropertyCollection(PropertyCollection<?,?> collectionToClear)
          clear a Property Collection by removing all it's children and deleting them if they are owned by this collection.
static java.util.List<java.util.Calendar> createDateIncrementList(java.util.Calendar firstDate, java.util.Calendar secondDate, long incrementInMilliseconds)
          create a Date Increment List starting with the smallest date.
static PropertyCollection createObject(PropertyCollection typeToCreate, RuleExecutionContext context)
          create an Object
static PropertyCollection createObjectsMatchingAllValues(java.util.List setValuesToMatch, PropertyCollection listToAddMissingValues, PropertyCollection instanceToMatch, PropertyCollection typeToCreate, boolean deleteUnmatchedValues, RuleExecutionContext context)
          create Objects Matching All Values and add them to the specified list
static PropertyCollection createObjectsMatchingAllValues(java.util.List valuesToMatch, PropertyCollection listToAddMissingValues, PropertyCollection instanceToMatch, PropertyCollection typeToCreate, RuleExecutionContext context)
          create Objects Matching All Values and add them to the specified list
static PropertyCollection createObjectsMatchingAllValuesInOrderedList(java.util.List setValuesToMatch, PropertyCollection listToAddMissingValues, PropertyCollection instanceToMatch, PropertyCollection typeToCreate, boolean deleteUnmatchedValues, RuleExecutionContext context)
          create Objects Matching All Values and add them to the specified ordered list
static PropertyCollection createObjectsMatchingAllValuesInOrderedList(java.util.List valuesToMatch, PropertyCollection listToAddMissingValues, PropertyCollection instanceToMatch, PropertyCollection typeToCreate, RuleExecutionContext context)
          create Objects Matching All Values and add them to the specified ordered list
static PropertyCollection<?,?> createOrReuseListToMatchType(PropertyCollection<?,?> currentList, PropertyCollection<?,?> requiredListType, PropertyCollection<?,?> fixedInstance, ModelFactory factory)
          create Or Reuse a List To Match a desired list type.
private static void createUnmatchedValues(PropertyCollection listToAddMissingValues, PropertyCollection<?,?> collectionTypeToCreate, java.lang.Object instanceKey, java.util.List valuesToMatchClone, ModelFactory modelFactory)
          createUnmatchedValues
private static void createUnmatchedValuesInOrderedList(PropertyCollection listToAddMissingValues, PropertyCollection<?,?> collectionTypeToCreate, java.lang.Object instanceKey, PropertyCollection<?,?> orderingTypeToCreate, java.lang.Object orderingValueKey, java.util.List valuesToMatchClone, ModelFactory modelFactory)
          createUnmatchedValuesInOrderedList
static void debug(java.lang.String message)
          utility method to output messages in the console quickly
static boolean equals(java.lang.Object object1, java.lang.Object object2)
           Compares two objects for equality, where either one or both objects may be null.
static Filter equalTo(java.lang.Object equalValue)
          create a filter to where objects have to equal a specific value
static PropertyCollection fillList(PropertyCollection listToFill, java.util.List objectsToAddToList, boolean removeUnmatchedValues)
          fill a List with a list of objects.
private static void fillListCreateUnmatchedValues(PropertyCollection listToFill, java.util.Collection valuesToMatchClone)
          fill List Create Unmatched Values
private static void fillListExtractMatchesValues(boolean removeUnmatchedValues, java.util.List currentValueCollectionList, java.util.List<PropertyCollection> objectsToRemove, java.util.Collection valuesToMatchClone)
          fill List Extract Matches Values
private static void fillListRemoveUnmatchedValues(PropertyCollection listToFill, boolean isReference, java.util.List<PropertyCollection> objectsToRemove)
          fill List Remove Unmatched Values
static void fillListWithSpecifiedTypes(PropertyCollection listToFill, ModelFactory factory, boolean deleteUnmatchedValues, PropertyCollection<?,?>... typesToCreate)
          fill a List With the Specified property collection Types by analyzing the list content and creating the missing objects and optionally deleting objects of which the type wasn't matched.
static PropertyCollection fillOrderedList(PropertyCollection listToFill, java.util.List objectsToAddToList, boolean removeUnmatchedValues, RuleExecutionContext context)
          fill an ordered List with a list of objects.
private static void fillOrderedListCreateUnmatchedValues(PropertyCollection listToFill, java.util.Collection valuesToMatchClone, java.lang.Object valueKey, PropertyCollection typeToCreate, ModelFactory factory)
          fill List Create Unmatched Values
protected static void fillOrderedListExtractMatchesValues(boolean removeUnmatchedValues, java.util.List currentValueCollectionList, java.util.List<PropertyCollection> objectsToRemove, java.util.Collection valuesToMatchClone, java.lang.Object valueKey)
          fill ordered List Extract Matches Values
static void fillOrderedListWithSpecifiedTypes(PropertyCollection listToFill, ModelFactory factory, boolean deleteUnmatchedValues, PropertyCollection<?,?>... typesToCreate)
          fill an ordered list with the specified property collection types by analyzing the list content and creating the missing objects and optionally deleting objects of which the type wasn't matched.
static
<T> java.util.List<T>
filter(java.util.List<T> listToFilter, Filter condition)
          filter a list based on a filter
static java.lang.Object filterList(java.util.Collection listToFilter, boolean nullOnMultipleResult)
          filter a collection to extract a single object from it.
static PropertyCollection<?,?> filterList(PropertyCollection<?,?> listToFilter, boolean nullOnMultipleResult)
          filter property collection to extract a single object from it.
static
<T> T
filterList(T[] listToFilter, boolean nullOnMultipleResult)
          filter an array property collection to extract a single object from it.
private static DeductionRuleLibrary.CompareResult findMaximumResult(java.util.List collectionList, PropertyCollection instanceToCompare)
          find the maximum result in the list of property collection for the specified instance
private static DeductionRuleLibrary.CompareResult findMinimumResult(java.util.List<?> collectionList, PropertyCollection<?,?> instanceToCompare)
          find the minimum result in the list of property collection for the specified instance
static PropertyCollection findParentOfType(PropertyCollection searchPoint, PropertyCollection type, boolean matchExactType)
          find Parent Of Type
static java.lang.String formatDate(java.util.Calendar value)
          format a date to show the year, month and day
static java.lang.String formatDate(java.util.Calendar value, java.lang.String dateFormat)
          format Date to a string with a specific display format
static java.lang.String formatTime(java.util.Calendar value)
          format Time
static PropertyCollection<?,?> getModelFromCollection(PropertyCollection<?,?> collection)
          get the Model layer associated with a Collection
static PropertyCollectionController getPropertyCollectionController(PropertyCollection<?,?> controlLayer, PropertyCollection<?,?> collection)
          get the Property Collection Controller from the control layer
private static java.lang.String getReferenceString(boolean isReference)
          get Reference description String
private static java.util.List<PropertyCollection<?,?>> getTypeCreationList(PropertyCollection<?,?>[] typesToCreate)
          getTypeCreationList : utility method to fetch a modifiable list from a type creation array.
static Filter instanceOf(java.lang.Object type)
          create a filter to where objects have to be of a specific type
private static boolean isContextValid(RuleExecutionContext context)
          is Context Valid
private static boolean isCreationOptionsValid(java.util.List valuesToMatch, PropertyCollection listToAddMissingValues, PropertyCollection instanceToMatch, PropertyCollection typeToCreate, RuleExecutionContext context)
          test if the options used to create collections are all valid
private static boolean isTypeToCreateValid(PropertyCollection<?,?> typeToCreate)
          is Type To Create Valid
static PropertyCollection maximumCollection(java.util.List collectionList, PropertyCollection instanceToCompare)
          find the property collection in the list that has the maximum value for the specified instance
static java.lang.Object maximumValue(java.util.List collectionList, PropertyCollection instanceToCompare)
          find the maximum value in the list of property collection for the specified instance
static java.util.List merge(java.util.List firstList, java.util.List secondList)
          merge two list of objects together and return a list that contains the objects of the first list followed by the second list.
static PropertyCollection minimumCollection(java.util.List collectionList, PropertyCollection instanceToCompare)
          find the property collection in the list that has the minimum value for the specified instance
static java.lang.Object minimumValue(java.util.List collectionList, PropertyCollection instanceToCompare)
          find the minimum value in the list of property collection for the specified instance
static Filter not(Filter otherFilter)
          Create a reverse filter
static Filter or(Filter firstFilter, Filter secondFilter)
          create an "or" filter
static Filter property(PropertyCollection<?,?> instance, Filter propertyValueFilter)
          create a filter based on the value of a property and a filter applied to that value
protected static void removeAlreadyMatchedOrderedListValues(boolean deleteUnmatchedValues, java.lang.Object valueKey, java.lang.Object instanceKey, java.util.List valuesToMatchClone, java.util.List<PropertyCollection> valuesToRemove, java.lang.Object possibleCollection, PropertyCollection<?,?> objectCreationType)
          remove Already Matched Ordered List Values
private static void removeAlreadyMatchedValues(boolean deleteUnmatchedValues, java.lang.Object instanceKey, java.util.List valuesToMatchClone, java.util.List<PropertyCollection> valuesToRemove, java.lang.Object possibleCollection, PropertyCollection<?,?> objectCreationType)
          remove Already Matched Values
static Filter same(java.lang.Object sameInstance)
          create a filter to where objects have to be the same as a specific value
static Filter smaller(java.lang.Object value)
          Create a smaller than filter.
static Filter smallerOrEqual(java.lang.Object value)
          Create a smaller or equal to filter.
static int sum(java.lang.Integer first, java.lang.Integer second)
          sum two integers
static double sum(java.util.List listOfNumbers)
          sum a list of numbers
private static void updateMaximumResultBasedOnCollection(DeductionRuleLibrary.CompareResult retVal, java.lang.Object instanceIdentityKey, PropertyCollection collection)
          update Maximum Result Based On Collection
private static void updateMinimumResultWithCollection(DeductionRuleLibrary.CompareResult retVal, java.lang.Object instanceIdentityKey, PropertyCollection<?,?> collection)
          update Minimum Result With Collection
private static void validateAddTypeToList(PropertyCollection list, PropertyCollection<?,?> typeToAdd, boolean reference)
          validate if an object of the specified property collection type can be added to a property collection
private static void validateAddTypeWithInstance(PropertyCollection<?,?> typeToAdd, boolean reference, PropertyCollection valueInstance)
          validate Add Type With Instance
private static void validateTypesToCreate(java.util.List<PropertyCollection<?,?>> createList, PropertyCollection instance)
          validate the Types To Create in the specified instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.deduced.DeductionRuleAnalyzer
analyzeRule
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER
Logger


DATE_FORMAT

private static final java.text.SimpleDateFormat DATE_FORMAT
date format


TIME_FORMAT

private static final java.text.SimpleDateFormat TIME_FORMAT
time format

Constructor Detail

DeductionRuleLibrary

public DeductionRuleLibrary()
Method Detail

filterList

public static java.lang.Object filterList(java.util.Collection listToFilter,
                                          boolean nullOnMultipleResult)
filter a collection to extract a single object from it. This method will return the first object in the list.

Parameters:
listToFilter - the list to filter
nullOnMultipleResult - if this flag is set to true and the list contains more than 1 object, null will be returned.
Returns:
a single object from the list

filterList

public static PropertyCollection<?,?> filterList(PropertyCollection<?,?> listToFilter,
                                                 boolean nullOnMultipleResult)
filter property collection to extract a single object from it. This method will return the first object in the list.

Parameters:
listToFilter - the list to filter
nullOnMultipleResult - if this flag is set to true and the list contains more than 1 object, null will be returned.
Returns:
a single object from the list

filterList

public static <T> T filterList(T[] listToFilter,
                               boolean nullOnMultipleResult)
filter an array property collection to extract a single object from it. This method will return the first object in the list.

Type Parameters:
T - the type of object in the array
Parameters:
listToFilter - the list to filter
nullOnMultipleResult - if this flag is set to true and the list contains more than 1 object, null will be returned.
Returns:
a single object from the list

sum

public static int sum(java.lang.Integer first,
                      java.lang.Integer second)
sum two integers

Parameters:
first - the first integer
second - the second integer
Returns:
the sum of both integers. This method will overflow if the sum of both values is larger or smaller than what can be contained in an integer.

sum

public static double sum(java.util.List listOfNumbers)
sum a list of numbers

Parameters:
listOfNumbers - the list of numbers
Returns:
the sum of all the numbers

minimumCollection

public static PropertyCollection minimumCollection(java.util.List collectionList,
                                                   PropertyCollection instanceToCompare)
find the property collection in the list that has the minimum value for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the collection that has the smallest value

minimumValue

public static java.lang.Object minimumValue(java.util.List collectionList,
                                            PropertyCollection instanceToCompare)
find the minimum value in the list of property collection for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the smallest value

findMinimumResult

private static DeductionRuleLibrary.CompareResult findMinimumResult(java.util.List<?> collectionList,
                                                                    PropertyCollection<?,?> instanceToCompare)
find the minimum result in the list of property collection for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the smallest result

updateMinimumResultWithCollection

private static void updateMinimumResultWithCollection(DeductionRuleLibrary.CompareResult retVal,
                                                      java.lang.Object instanceIdentityKey,
                                                      PropertyCollection<?,?> collection)
update Minimum Result With Collection

Parameters:
retVal - the compare result to update
instanceIdentityKey - the instance key to read
collection - the collection to read

maximumCollection

public static PropertyCollection maximumCollection(java.util.List collectionList,
                                                   PropertyCollection instanceToCompare)
find the property collection in the list that has the maximum value for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the collection that has the maximum value

maximumValue

public static java.lang.Object maximumValue(java.util.List collectionList,
                                            PropertyCollection instanceToCompare)
find the maximum value in the list of property collection for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the maximum value

findMaximumResult

private static DeductionRuleLibrary.CompareResult findMaximumResult(java.util.List collectionList,
                                                                    PropertyCollection instanceToCompare)
find the maximum result in the list of property collection for the specified instance

Parameters:
collectionList - the collection list to search in
instanceToCompare - the instance to look for in the comparison of values
Returns:
the maximum result

updateMaximumResultBasedOnCollection

private static void updateMaximumResultBasedOnCollection(DeductionRuleLibrary.CompareResult retVal,
                                                         java.lang.Object instanceIdentityKey,
                                                         PropertyCollection collection)
update Maximum Result Based On Collection

Parameters:
retVal - the result to update
instanceIdentityKey - the instance key to read
collection - the collection to read

formatDate

public static java.lang.String formatDate(java.util.Calendar value)
format a date to show the year, month and day

Parameters:
value - the value to format
Returns:
the formatted string

formatTime

public static java.lang.String formatTime(java.util.Calendar value)
format Time

Parameters:
value - the time to format in a string
Returns:
the formatted string

formatDate

public static java.lang.String formatDate(java.util.Calendar value,
                                          java.lang.String dateFormat)
format Date to a string with a specific display format

Parameters:
value - the value to format
dateFormat - the date format
Returns:
the formatted date

fillList

public static PropertyCollection fillList(PropertyCollection listToFill,
                                          java.util.List objectsToAddToList,
                                          boolean removeUnmatchedValues)
fill a List with a list of objects.

Parameters:
listToFill - the list to fill
objectsToAddToList - objects to add to the list
removeUnmatchedValues - if this option is set to true, all the objects in the original list that don't match the list of objects to add will be removed.
Returns:
the filled list. Same as the listToFill parameter.

fillOrderedList

public static PropertyCollection fillOrderedList(PropertyCollection listToFill,
                                                 java.util.List objectsToAddToList,
                                                 boolean removeUnmatchedValues,
                                                 RuleExecutionContext context)
fill an ordered List with a list of objects.

Parameters:
listToFill - the ordered list to fill
objectsToAddToList - objects to add to the list
removeUnmatchedValues - if this option is set to true, all the objects in the original list that don't match the list of objects to add will be removed.
context - the rule execution context
Returns:
the filled list. Same as the listToFill parameter.

fillListExtractMatchesValues

private static void fillListExtractMatchesValues(boolean removeUnmatchedValues,
                                                 java.util.List currentValueCollectionList,
                                                 java.util.List<PropertyCollection> objectsToRemove,
                                                 java.util.Collection valuesToMatchClone)
fill List Extract Matches Values

Parameters:
removeUnmatchedValues - the option to remove unmatched values
currentValueCollectionList - the list of all the values that need to be matched
objectsToRemove - the list of objects to potentially remove
valuesToMatchClone - the values to match

fillOrderedListExtractMatchesValues

protected static void fillOrderedListExtractMatchesValues(boolean removeUnmatchedValues,
                                                          java.util.List currentValueCollectionList,
                                                          java.util.List<PropertyCollection> objectsToRemove,
                                                          java.util.Collection valuesToMatchClone,
                                                          java.lang.Object valueKey)
fill ordered List Extract Matches Values

Parameters:
removeUnmatchedValues - the option to remove unmatched values
currentValueCollectionList - the list of all the values that need to be matched
objectsToRemove - the list of objects to potentially remove
valuesToMatchClone - the values to match
valueKey - the value key from which to fetch the value on the ordering type

fillListCreateUnmatchedValues

private static void fillListCreateUnmatchedValues(PropertyCollection listToFill,
                                                  java.util.Collection valuesToMatchClone)
fill List Create Unmatched Values

Parameters:
listToFill - the list to fill
valuesToMatchClone - the values to add

fillOrderedListCreateUnmatchedValues

private static void fillOrderedListCreateUnmatchedValues(PropertyCollection listToFill,
                                                         java.util.Collection valuesToMatchClone,
                                                         java.lang.Object valueKey,
                                                         PropertyCollection typeToCreate,
                                                         ModelFactory factory)
fill List Create Unmatched Values

Parameters:
listToFill - the list to fill
valuesToMatchClone - the values to add
valueKey - the value key to use
typeToCreate - the type to create
factory - the model factory to use to create the ordering type

fillListRemoveUnmatchedValues

private static void fillListRemoveUnmatchedValues(PropertyCollection listToFill,
                                                  boolean isReference,
                                                  java.util.List<PropertyCollection> objectsToRemove)
fill List Remove Unmatched Values

Parameters:
listToFill - the list to fill
isReference - is the value to remove by reference
objectsToRemove - the list of values to remove

addToRemoveListIfPropertyNotMatched

private static void addToRemoveListIfPropertyNotMatched(boolean removeUnmatchedValues,
                                                        java.util.List<PropertyCollection> objectsToRemove,
                                                        java.util.Collection valuesToMatchClone,
                                                        PropertyCollection currentCollection,
                                                        java.lang.Object propertyKey)
add a collection To the Remove List If Not Matched

Parameters:
removeUnmatchedValues - option to remove unmatched values
objectsToRemove - the object to remove list
valuesToMatchClone - the values to match
currentCollection - the current collection
propertyKey - the property key used to extract the value on the ordering type

addToRemoveListIfNotMatched

private static void addToRemoveListIfNotMatched(boolean removeUnmatchedValues,
                                                java.util.List<PropertyCollection> objectsToRemove,
                                                java.util.Collection valuesToMatchClone,
                                                PropertyCollection currentCollection)
add a collection To the Remove List If Not Matched

Parameters:
removeUnmatchedValues - option to remove unmatched values
objectsToRemove - the object to remove list
valuesToMatchClone - the values to match
currentCollection - the current collection

createObject

public static PropertyCollection createObject(PropertyCollection typeToCreate,
                                              RuleExecutionContext context)
create an Object

Parameters:
typeToCreate - the type of object to create
context - the rule execution context
Returns:
the created object

createObjectsMatchingAllValues

public static PropertyCollection createObjectsMatchingAllValues(java.util.List valuesToMatch,
                                                                PropertyCollection listToAddMissingValues,
                                                                PropertyCollection instanceToMatch,
                                                                PropertyCollection typeToCreate,
                                                                RuleExecutionContext context)
create Objects Matching All Values and add them to the specified list

Parameters:
valuesToMatch - the values to match
listToAddMissingValues - the list to fill
instanceToMatch - the instance where to set the value on each created object
typeToCreate - the type of object to create
context - the rule execution context
Returns:
the list that was filled. Same as listToAddMissingValues

createObjectsMatchingAllValuesInOrderedList

public static PropertyCollection createObjectsMatchingAllValuesInOrderedList(java.util.List valuesToMatch,
                                                                             PropertyCollection listToAddMissingValues,
                                                                             PropertyCollection instanceToMatch,
                                                                             PropertyCollection typeToCreate,
                                                                             RuleExecutionContext context)
create Objects Matching All Values and add them to the specified ordered list

Parameters:
valuesToMatch - the values to match
listToAddMissingValues - the ordered list to fill
instanceToMatch - the instance where to set the value on each created object
typeToCreate - the type of object to create
context - the rule execution context
Returns:
the list that was filled. Same as listToAddMissingValues

createObjectsMatchingAllValuesInOrderedList

public static PropertyCollection createObjectsMatchingAllValuesInOrderedList(java.util.List setValuesToMatch,
                                                                             PropertyCollection listToAddMissingValues,
                                                                             PropertyCollection instanceToMatch,
                                                                             PropertyCollection typeToCreate,
                                                                             boolean deleteUnmatchedValues,
                                                                             RuleExecutionContext context)
create Objects Matching All Values and add them to the specified ordered list

Parameters:
setValuesToMatch - the values to match
listToAddMissingValues - the ordered list to fill
instanceToMatch - the instance where to set the value on each created object
typeToCreate - the type of object to create
deleteUnmatchedValues - if this option is set to true, all the objects in the original list that don't match the list of values to add will be removed.
context - the rule execution context
Returns:
the list that was filled. Same as listToAddMissingValues

createObjectsMatchingAllValues

public static PropertyCollection createObjectsMatchingAllValues(java.util.List setValuesToMatch,
                                                                PropertyCollection listToAddMissingValues,
                                                                PropertyCollection instanceToMatch,
                                                                PropertyCollection typeToCreate,
                                                                boolean deleteUnmatchedValues,
                                                                RuleExecutionContext context)
create Objects Matching All Values and add them to the specified list

Parameters:
setValuesToMatch - the values to match
listToAddMissingValues - the list to fill
instanceToMatch - the instance where to set the value on each created object
typeToCreate - the type of object to create
deleteUnmatchedValues - if this option is set to true, all the objects in the original list that don't match the list of values to add will be removed.
context - the rule execution context
Returns:
the list that was filled. Same as listToAddMissingValues

isCreationOptionsValid

private static boolean isCreationOptionsValid(java.util.List valuesToMatch,
                                              PropertyCollection listToAddMissingValues,
                                              PropertyCollection instanceToMatch,
                                              PropertyCollection typeToCreate,
                                              RuleExecutionContext context)
test if the options used to create collections are all valid

Parameters:
valuesToMatch - the list of values to match
listToAddMissingValues - the list on which to add the missing values
instanceToMatch - the instance to match
typeToCreate - the type to create
context - the context. The context must have a valid model factory
Returns:
true if all the parameters are correct to proceed with object creation

isTypeToCreateValid

private static boolean isTypeToCreateValid(PropertyCollection<?,?> typeToCreate)
is Type To Create Valid

Parameters:
typeToCreate - the type to create
Returns:
true if the type is valid

isContextValid

private static boolean isContextValid(RuleExecutionContext context)
is Context Valid

Parameters:
context - the context
Returns:
true if the context is valid

createUnmatchedValues

private static void createUnmatchedValues(PropertyCollection listToAddMissingValues,
                                          PropertyCollection<?,?> collectionTypeToCreate,
                                          java.lang.Object instanceKey,
                                          java.util.List valuesToMatchClone,
                                          ModelFactory modelFactory)
createUnmatchedValues

Parameters:
listToAddMissingValues - the list on which to add the missing values
collectionTypeToCreate - the type of collection to create
instanceKey - the instance key to set
valuesToMatchClone - the list of values for which we should create collections
modelFactory - the model factory used for creation

createUnmatchedValuesInOrderedList

private static void createUnmatchedValuesInOrderedList(PropertyCollection listToAddMissingValues,
                                                       PropertyCollection<?,?> collectionTypeToCreate,
                                                       java.lang.Object instanceKey,
                                                       PropertyCollection<?,?> orderingTypeToCreate,
                                                       java.lang.Object orderingValueKey,
                                                       java.util.List valuesToMatchClone,
                                                       ModelFactory modelFactory)
createUnmatchedValuesInOrderedList

Parameters:
listToAddMissingValues - the list on which to add the missing values
collectionTypeToCreate - the type of collection to create
instanceKey - the instance key to set
orderingTypeToCreate - the ordering type to create
orderingValueKey - the key to the value property on the created ordering type
valuesToMatchClone - the list of values for which we should create collections
modelFactory - the model factory used for creation

removeAlreadyMatchedValues

private static void removeAlreadyMatchedValues(boolean deleteUnmatchedValues,
                                               java.lang.Object instanceKey,
                                               java.util.List valuesToMatchClone,
                                               java.util.List<PropertyCollection> valuesToRemove,
                                               java.lang.Object possibleCollection,
                                               PropertyCollection<?,?> objectCreationType)
remove Already Matched Values

Parameters:
deleteUnmatchedValues - option to delete unmatched values
instanceKey - the instance key to read
valuesToMatchClone - the values to match list
valuesToRemove - the values to remove list
possibleCollection - the possible collection to remove
objectCreationType - the type of object that should be created in the list

removeAlreadyMatchedOrderedListValues

protected static void removeAlreadyMatchedOrderedListValues(boolean deleteUnmatchedValues,
                                                            java.lang.Object valueKey,
                                                            java.lang.Object instanceKey,
                                                            java.util.List valuesToMatchClone,
                                                            java.util.List<PropertyCollection> valuesToRemove,
                                                            java.lang.Object possibleCollection,
                                                            PropertyCollection<?,?> objectCreationType)
remove Already Matched Ordered List Values

Parameters:
deleteUnmatchedValues - option to delete unmatched values
valueKey - the key to fetch the value on the ordering type
instanceKey - the instance key to read
valuesToMatchClone - the values to match list
valuesToRemove - the values to remove list
possibleCollection - the possible collection to remove
objectCreationType - the type of object to create

createDateIncrementList

public static java.util.List<java.util.Calendar> createDateIncrementList(java.util.Calendar firstDate,
                                                                         java.util.Calendar secondDate,
                                                                         long incrementInMilliseconds)
create a Date Increment List starting with the smallest date.

Parameters:
firstDate - the first date inclusively. If null, the returned list will be empty.
secondDate - the second date inclusively. If null, the returned list will be empty.
incrementInMilliseconds - the increment between each step in milliseconds. The method will return an empty list if this value is zero. A negative value will be converted to a positive value for increment.
Returns:
the created list of calendar.

filter

public static <T> java.util.List<T> filter(java.util.List<T> listToFilter,
                                           Filter condition)
filter a list based on a filter

Type Parameters:
T - Type of objects in the list to filter
Parameters:
listToFilter - the list to filter
condition - the condition filter
Returns:
the filtered list. This list will always be different from the listToFilter parameter. It can be manipulated on it's own.

bigger

public static Filter bigger(java.lang.Object value)
Create a bigger than filter.

Parameters:
value - the bigger than value on the filter.
Returns:
the created filter

smaller

public static Filter smaller(java.lang.Object value)
Create a smaller than filter.

Parameters:
value - the smaller than value on the filter.
Returns:
the created filter

biggerOrEqual

public static Filter biggerOrEqual(java.lang.Object value)
Create a bigger or equal to filter.

Parameters:
value - the bigger or equal to value on the filter.
Returns:
the created filter

smallerOrEqual

public static Filter smallerOrEqual(java.lang.Object value)
Create a smaller or equal to filter.

Parameters:
value - the smaller or equal to value on the filter.
Returns:
the created filter

not

public static Filter not(Filter otherFilter)
Create a reverse filter

Parameters:
otherFilter - the filter to reverse
Returns:
the created filter

equalTo

public static Filter equalTo(java.lang.Object equalValue)
create a filter to where objects have to equal a specific value

Parameters:
equalValue - the equal value
Returns:
the created filter

property

public static Filter property(PropertyCollection<?,?> instance,
                              Filter propertyValueFilter)
create a filter based on the value of a property and a filter applied to that value

Parameters:
instance - the property instance to filter
propertyValueFilter - the filter to apply to the value
Returns:
the created filter

same

public static Filter same(java.lang.Object sameInstance)
create a filter to where objects have to be the same as a specific value

Parameters:
sameInstance - the same value
Returns:
the created filter

instanceOf

public static Filter instanceOf(java.lang.Object type)
create a filter to where objects have to be of a specific type

Parameters:
type - the type to match
Returns:
the created filter

and

public static Filter and(Filter firstFilter,
                         Filter secondFilter)
create an "and" filter

Parameters:
firstFilter - first filter
secondFilter - second filter
Returns:
the created filter

or

public static Filter or(Filter firstFilter,
                        Filter secondFilter)
create an "or" filter

Parameters:
firstFilter - first filter
secondFilter - second filter
Returns:
the created filter

findParentOfType

public static PropertyCollection findParentOfType(PropertyCollection searchPoint,
                                                  PropertyCollection type,
                                                  boolean matchExactType)
find Parent Of Type

Parameters:
searchPoint - the collection to search for a parent of the specified type
type - the type of the parent we are looking for
matchExactType - if this option is true, the parents must match the exact specified type to be returned. Otherwise any type that derives from the specified type will be returned.
Returns:
the parent matching the type. Null if no matching parents could be found.

merge

public static java.util.List merge(java.util.List firstList,
                                   java.util.List secondList)
merge two list of objects together and return a list that contains the objects of the first list followed by the second list.

Parameters:
firstList - the first list to add. This parameter can be null.
secondList - the second list to add. This parameter can be null.
Returns:
the merged list. This value is never null, even if both inputs are.

debug

public static void debug(java.lang.String message)
utility method to output messages in the console quickly

Parameters:
message - the message to show

addReferenceToList

public static PropertyCollection addReferenceToList(PropertyCollection referenceToAdd,
                                                    PropertyCollection list,
                                                    boolean allowDuplicateReference)
add a reference to a list. This method will ensure that it is valid to add such a reference. It will also check for duplicate references if they aren't allowed.

Parameters:
referenceToAdd - the reference to add. If this parameter is null, nothing occurs.
list - the list to which we are adding the reference. If this parameter is null, nothing occurs.
allowDuplicateReference - flag indicating if the list is allowed to contain duplicate references of the same object.
Returns:
the list after it was modified
Throws:
java.lang.IllegalArgumentException - if the list doesn't allow addition of references of the specified type or if the list doesn't contain references.

validateAddTypeToList

private static void validateAddTypeToList(PropertyCollection list,
                                          PropertyCollection<?,?> typeToAdd,
                                          boolean reference)
validate if an object of the specified property collection type can be added to a property collection

Parameters:
list - the property collection list
typeToAdd - the type to add
reference - is the add a reference
Throws:
java.lang.IllegalArgumentException - if the type to add can't be added.

validateAddTypeWithInstance

private static void validateAddTypeWithInstance(PropertyCollection<?,?> typeToAdd,
                                                boolean reference,
                                                PropertyCollection valueInstance)
validate Add Type With Instance

Parameters:
typeToAdd - the type to add
reference - is the type to add by reference
valueInstance - the instance to validate against
Throws:
java.lang.IllegalArgumentException - if the type or the reference flag doesn't match the instance.

getReferenceString

private static java.lang.String getReferenceString(boolean isReference)
get Reference description String

Parameters:
isReference - is a reference
Returns:
the reference description

getModelFromCollection

public static PropertyCollection<?,?> getModelFromCollection(PropertyCollection<?,?> collection)
get the Model layer associated with a Collection

Parameters:
collection - the collection from which to find the model layer
Returns:
the model layer. Null if not found.

getPropertyCollectionController

public static PropertyCollectionController getPropertyCollectionController(PropertyCollection<?,?> controlLayer,
                                                                           PropertyCollection<?,?> collection)
get the Property Collection Controller from the control layer

Parameters:
controlLayer - the control layer
collection - the collection from which to fetch the controller
Returns:
the matched controller. Null if the controller couldn't be found.

clearPropertyCollection

public static void clearPropertyCollection(PropertyCollection<?,?> collectionToClear)
clear a Property Collection by removing all it's children and deleting them if they are owned by this collection.

Parameters:
collectionToClear - the collection to clear.

createOrReuseListToMatchType

public static PropertyCollection<?,?> createOrReuseListToMatchType(PropertyCollection<?,?> currentList,
                                                                   PropertyCollection<?,?> requiredListType,
                                                                   PropertyCollection<?,?> fixedInstance,
                                                                   ModelFactory factory)
create Or Reuse a List To Match a desired list type. If the requiredListType is valid and the fixedInstance is valid and the factory is valid and the current list is null or the type of the current list doesn't match the desired type, then a new list is created. Otherwise, the current list is returned.

Parameters:
currentList - the current list
requiredListType - the required list type
fixedInstance - the list fixed instance
factory - the factory used to create the new list if necessary
Returns:
the list that is either created or reused.

fillListWithSpecifiedTypes

public static void fillListWithSpecifiedTypes(PropertyCollection listToFill,
                                              ModelFactory factory,
                                              boolean deleteUnmatchedValues,
                                              PropertyCollection<?,?>... typesToCreate)
fill a List With the Specified property collection Types by analyzing the list content and creating the missing objects and optionally deleting objects of which the type wasn't matched.

Parameters:
listToFill - the list to fill. If null, nothing will be done.
factory - the factory used to populate the list. If null, nothing will be done.
deleteUnmatchedValues - option to delete unmatched values. If set to true, any objects in the list that has a type that isn't requested in the creation will be deleted.
typesToCreate - the list of types of objects to create if necessary. It is possible to specify the same object type multiple times if necessary. If a type is defined more than once, than this method will ensure that the list contains the same number of objects that match that type.
Throws:
java.lang.IllegalArgumentException - if the list values are by reference or if the types to create don't match the list instance type.

validateTypesToCreate

private static void validateTypesToCreate(java.util.List<PropertyCollection<?,?>> createList,
                                          PropertyCollection instance)
validate the Types To Create in the specified instance

Parameters:
createList - the list of type to create
instance - the instance to use
Throws:
java.lang.IllegalArgumentException - if the instance is by reference or if the types to create don't match the instance type.

fillOrderedListWithSpecifiedTypes

public static void fillOrderedListWithSpecifiedTypes(PropertyCollection listToFill,
                                                     ModelFactory factory,
                                                     boolean deleteUnmatchedValues,
                                                     PropertyCollection<?,?>... typesToCreate)
fill an ordered list with the specified property collection types by analyzing the list content and creating the missing objects and optionally deleting objects of which the type wasn't matched.

Parameters:
listToFill - the list to fill. If null, nothing will be done.
factory - the factory used to populate the list. If null, nothing will be done.
deleteUnmatchedValues - option to delete unmatched values. If set to true, any objects in the list that has a type that isn't requested in the creation will be deleted.
typesToCreate - the list of types of objects to create if necessary. It is possible to specify the same object type multiple times if necessary. If a type is defined more than once, than this method will ensure that the list contains the same number of objects that match that type.
Throws:
java.lang.IllegalArgumentException - if the list isn't an ordered list or if the ordered values are by reference or if the types to create don't match the ordering value type.

getTypeCreationList

private static java.util.List<PropertyCollection<?,?>> getTypeCreationList(PropertyCollection<?,?>[] typesToCreate)
getTypeCreationList : utility method to fetch a modifiable list from a type creation array.

Parameters:
typesToCreate - the array of types to create
Returns:
the list of types to create. This output will never be null. If the input is null or empty, an empty list will be returned.

equals

public static boolean equals(java.lang.Object object1,
                             java.lang.Object object2)

Compares two objects for equality, where either one or both objects may be null.

 ObjectUtils.equals(null, null)                  = true
 ObjectUtils.equals(null, "")                    = false
 ObjectUtils.equals("", null)                    = false
 ObjectUtils.equals("", "")                      = true
 ObjectUtils.equals(Boolean.TRUE, null)          = false
 ObjectUtils.equals(Boolean.TRUE, "true")        = false
 ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE)  = true
 ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false
 

Parameters:
object1 - the first object, may be null
object2 - the second object, may be null
Returns:
true if the values of both objects are the same