Add documentation for fflib_Criteria

This commit is contained in:
Wim Velzeboer
2021-07-06 16:32:38 +01:00
parent 014c145d9a
commit d5bfc3c48c
8 changed files with 561 additions and 85 deletions
@@ -64,7 +64,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Name = 'Example' OR AccountNumber = '1234567'
*/
public fflib_Criteria orCriteria()
public virtual fflib_Criteria orCriteria()
{
this.type = 'OR';
return this;
@@ -75,10 +75,10 @@ public virtual with sharing class fflib_Criteria
* By default the comparator is set to AND,
* so this method should only be used in custom implementations extended from fflib_Criteria
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new MyCustomCriteria()
* new fflib_Criteria()
* .andCriteria()
* .equalTo(Account.Name, 'Example')
* .equalTo(Account.AccountNumber, '1234567')
@@ -86,7 +86,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Name = 'Example' AND AccountNumber = '1234567'
*/
public fflib_Criteria andCriteria()
public virtual fflib_Criteria andCriteria()
{
this.type = 'AND';
return this;
@@ -97,7 +97,7 @@ public virtual with sharing class fflib_Criteria
*
* @param subCriteria The condition of the sub criteria
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -110,7 +110,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Account.Name = 'Example' AND (Account.AccountNumber = '0001' OR Account.AccountNumber = '0002')
*/
public fflib_Criteria addOrCriteria(fflib_Criteria subCriteria)
public virtual fflib_Criteria addOrCriteria(fflib_Criteria subCriteria)
{
subCriteria.orCriteria();
subCriteria.setEmbraced(true);
@@ -123,7 +123,7 @@ public virtual with sharing class fflib_Criteria
*
* @param subCriteria The condition of the sub criteria
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -137,7 +137,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Name = 'Example' OR (AccountNumber = '0001' AND ShippingCountry = 'USA')
*/
public fflib_Criteria addAndCriteria(fflib_Criteria subCriteria)
public virtual fflib_Criteria addAndCriteria(fflib_Criteria subCriteria)
{
subCriteria.andCriteria();
subCriteria.setEmbraced(true);
@@ -146,12 +146,12 @@ public virtual with sharing class fflib_Criteria
}
/**
* add an equal to criteria comparing a fields value to a given value
* Add an equal to criteria comparing a fields value to a given value
*
* @param field The sObjectField to evaluate
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -160,19 +160,19 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Name = 'Example'
*/
public fflib_Criteria equalTo(Schema.SObjectField field, Object value)
public virtual fflib_Criteria equalTo(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.EQUALS, value));
return this;
}
/**
* add a not equal to criteria while comparing a fields value to a given value
* Add a not equal to criteria while comparing a fields value to a given value
*
* @param field The sObjectField to evaluate
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -181,7 +181,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Name != 'Example'
*/
public fflib_Criteria notEqualTo(Schema.SObjectField field, Object value)
public virtual fflib_Criteria notEqualTo(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.NOT_EQUALS, value));
return this;
@@ -194,7 +194,7 @@ public virtual with sharing class fflib_Criteria
*
* @return The Boolean result of the evaluated criteria
*/
public Boolean evaluate(Object record)
public virtual Boolean evaluate(Object record)
{
if (this.evaluators.isEmpty()) return true;
@@ -215,13 +215,13 @@ public virtual with sharing class fflib_Criteria
}
/**
* compares the fields values to be greater or equal to the given value
* Compares the fields values to be greater or equal to the given value
* Evaluates to false if the field value is null
*
* @param field The field to use its value
* @param field The Schema.sObjectField to use its value
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -230,20 +230,20 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* AnnualRevenue >= 54321
*/
public fflib_Criteria greaterOrEqualTo(Schema.SObjectField field, Object value)
public virtual fflib_Criteria greaterOrEqualTo(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.GREATER_THAN_OR_EQUAL_TO, value));
return this;
}
/**
* compares the fields values to be greater or equal to the given value
* Compares the fields values to be greater or equal to the given value
* Evaluates to false if the field value is null
*
* @param field The field to use its value
* @param field The Schema.SObjectField to use its value
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -252,20 +252,20 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* AnnualRevenue > 54321
*/
public fflib_Criteria greaterThan(Schema.SObjectField field, Object value)
public virtual fflib_Criteria greaterThan(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.GREATER_THAN, value));
return this;
}
/**
* compares the fields values to be less or equal to the given value
* Compares the fields values to be less or equal to the given value
* Evaluates to true if the field value is null
*
* @param field The field to use its value
* @param field The Schema.SObjectField to use its value
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -274,7 +274,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* AnnualRevenue <= 54321
*/
public fflib_Criteria lessOrEqualTo(Schema.SObjectField field, Object value)
public virtual fflib_Criteria lessOrEqualTo(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.LESS_THAN_OR_EQUAL_TO, value));
return this;
@@ -282,13 +282,13 @@ public virtual with sharing class fflib_Criteria
/**
* compares the fields values to be greater or equal to the given value
* Compares the fields values to be greater or equal to the given value
* Evaluates to true if the field value is null
*
* @param field The field to use its value
* @param field The Schema.sObjectField to use its value
* @param value The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -297,19 +297,19 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* AnnualRevenue < 54321
*/
public fflib_Criteria lessThan(Schema.SObjectField field, Object value)
public virtual fflib_Criteria lessThan(Schema.SObjectField field, Object value)
{
evaluators.add(new FieldEvaluator(field, fflib_Operator.LESS_THAN, value));
return this;
}
/**
* checks if the given sets contains the fields values
* Checks if the given sets contains the fields values
*
* @param field The field to use its value
* @param values The value to be compared to the fields value
* @param field The Schema.sObjectField to use its value
* @param values The values to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -318,7 +318,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates:
* Account.Type IN ('Customer','Competitor','Partner')
*/
public fflib_Criteria inSet(Schema.SObjectField field, Set<Object> values)
public virtual fflib_Criteria inSet(Schema.SObjectField field, Set<Object> values)
{
return inSet(field, new fflib_Objects(new List<Object>(values)));
}
@@ -361,7 +361,7 @@ public virtual with sharing class fflib_Criteria
* @param field The field to use its value
* @param values The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -377,12 +377,12 @@ public virtual with sharing class fflib_Criteria
}
/**
* checks if the given sets contains the fields values
* Checks if the given sets does not contain the fields values
*
* @param field The field to use its value
* @param field The Schema.sObjectField to use its value
* @param values The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -434,7 +434,7 @@ public virtual with sharing class fflib_Criteria
* @param field The field to use its value
* @param values The value to be compared to the fields value
*
* @return Instance of fflib_Criteria
* @return An instance of itself to enable method chaining
*
* @example
* new fflib_Criteria()
@@ -454,7 +454,7 @@ public virtual with sharing class fflib_Criteria
*
* @return The "where" part in the SOQL statement
*/
public String toSOQL()
public virtual String toSOQL()
{
if (this.evaluators.isEmpty()) return '';
@@ -1,5 +1,5 @@
/**
* File Name: Array
* File Name: fflib_ArrayUtils
* @description
*
* @author architect ir. Wilhelmus G.J. Velzeboer
@@ -28,10 +28,10 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ArrayUtils
public class fflib_ArrayUtils
{
/* private constructor to prevent instantiation */
private ArrayUtils() {}
private fflib_ArrayUtils() {}
/**
* Creates a clone from the provided list and returns the sorted list
@@ -1,11 +1,11 @@
/**
* File Name: ArrayTest
* File Name: fflib_ArrayUtilsTest
* @description
*
* @author architect ir. Wilhelmus G.J. Velzeboer | wvelzebo@its.jnj.com
* @author architect ir. Wilhelmus G.J. Velzeboer | wim@velzeboer.nl
*/
@IsTest(IsParallel=true)
private class ArrayUtilsTest
private class fflib_ArrayUtilsTest
{
@IsTest
@@ -13,7 +13,7 @@ private class ArrayUtilsTest
{
System.assertEquals(
new List<String> {'123', '456', '789'},
ArrayUtils.objectToString(
fflib_ArrayUtils.objectToString(
new List<Object> {123, 456, 789}
)
);
@@ -24,7 +24,7 @@ private class ArrayUtilsTest
{
System.assertEquals(
new List<String> {'123', '456', '789'},
ArrayUtils.objectToString(
fflib_ArrayUtils.objectToString(
new List<Object> {'123', '456', '789'}
)
);
@@ -35,7 +35,7 @@ private class ArrayUtilsTest
{
System.assertEquals(
new List<String>(),
ArrayUtils.objectToString(
fflib_ArrayUtils.objectToString(
new List<Object>()
)
);
@@ -46,7 +46,7 @@ private class ArrayUtilsTest
{
System.assertEquals(
new List<String> {'1', '2', '3'},
ArrayUtils.objectToString(
fflib_ArrayUtils.objectToString(
new Set<Object> {1, 2, 3}
)
);
@@ -59,7 +59,7 @@ private class ArrayUtilsTest
Id idB = fflib_IDGenerator.generate(Account.SObjectType);
System.assertEquals(
new Set<Id> {idA, idB},
ArrayUtils.objectToIds(
fflib_ArrayUtils.objectToIds(
new Set<Object>
{
(Object) idA,
@@ -79,7 +79,7 @@ private class ArrayUtilsTest
(Object) 'B',
(Object) 'A'
},
ArrayUtils.reverse(
fflib_ArrayUtils.reverse(
new List<Object>
{
(Object) 'A',
@@ -100,7 +100,7 @@ private class ArrayUtilsTest
(SObject) new Account(Name = 'B'),
(SObject) new Account(Name = 'A')
},
ArrayUtils.reverse(
fflib_ArrayUtils.reverse(
new List<SObject>
{
(SObject) new Account(Name = 'A'),
@@ -121,7 +121,7 @@ private class ArrayUtilsTest
'TEST B',
'TEST C'
},
ArrayUtils.upperCase(
fflib_ArrayUtils.upperCase(
new List<String>
{
'test a',
@@ -137,7 +137,7 @@ private class ArrayUtilsTest
{
System.assertEquals(
new List<String> {'abc', 'def'},
ArrayUtils.lowerCase(
fflib_ArrayUtils.lowerCase(
new List<String> {'ABC', 'DEF'}
)
);
@@ -147,28 +147,28 @@ private class ArrayUtilsTest
static void testIsEmpty()
{
List<String> aNull = null;
System.assertEquals(true, ArrayUtils.isEmpty(aNull));
System.assertEquals(true, ArrayUtils.isEmpty(new List<String> {}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<String> {'a'}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<String> {'a', 'b'}));
System.assertEquals(true, ArrayUtils.isEmpty(new List<Integer> {}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<Integer> {1}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<Integer> {1, 2}));
System.assertEquals(true, fflib_ArrayUtils.isEmpty(aNull));
System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List<String> {}));
System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<String> {'a'}));
System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<String> {'a', 'b'}));
System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List<Integer> {}));
System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<Integer> {1}));
System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<Integer> {1, 2}));
}
@IsTest
static void testIsNotEmpty()
{
List<String> aNull = null;
System.assertEquals(false, ArrayUtils.isNotEmpty(aNull));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<String> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<String> {'a'}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<String> {'a', 'b'}));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<Integer> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Integer> {1}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Integer> {1, 2}));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<Account> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Account> {new Account(Name = 'test')}));
System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(aNull));
System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<String> {}));
System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<String> {'a'}));
System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<String> {'a', 'b'}));
System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<Integer> {}));
System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Integer> {1}));
System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Integer> {1, 2}));
System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<Account> {}));
System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Account> {new Account(Name = 'test')}));
}
@IsTest
@@ -178,7 +178,7 @@ private class ArrayUtilsTest
List<Datetime> datetimes = generateDateTimes();
// WHEN - we request the maxDatetime
Datetime maxDatetime = ArrayUtils.maxDatetime(datetimes);
Datetime maxDatetime = fflib_ArrayUtils.maxDatetime(datetimes);
// THEN - the highest Datetime should be returned
System.assertEquals(datetimes.get(1), maxDatetime);
@@ -191,7 +191,7 @@ private class ArrayUtilsTest
List<Datetime> datetimes = generateDateTimes();
// WHEN - we request the maxDatetime
Datetime maxDatetime = ArrayUtils.minDatetime(datetimes);
Datetime maxDatetime = fflib_ArrayUtils.minDatetime(datetimes);
// THEN - the highest Datetime should be returned
System.assertEquals(datetimes.get(4), maxDatetime);
@@ -201,11 +201,11 @@ private class ArrayUtilsTest
static void itShouldHandleNullInputsForMaxDatatime()
{
System.assertEquals(
null, ArrayUtils.maxDatetime(new List<Datetime>()),
null, fflib_ArrayUtils.maxDatetime(new List<Datetime>()),
'maxDatetime method was unable to handle an empty list as input'
);
System.assertEquals(
null, ArrayUtils.maxDatetime(null),
null, fflib_ArrayUtils.maxDatetime(null),
'maxDatetime method was unable to handle null as input'
);
}
@@ -220,7 +220,7 @@ private class ArrayUtilsTest
};
// WHEN - we request the a cloned and sorted list
List<Integer> sorted = ArrayUtils.cloneAndSort(unsorted);
List<Integer> sorted = fflib_ArrayUtils.cloneAndSort(unsorted);
System.assertNotEquals(unsorted, sorted, 'The original object was modified, something went wrong with the cloning');
System.assertEquals(new List<Integer> {-7, 1, 2, 30, 76}, sorted, 'Incorrect sorted list returned');
}
@@ -232,7 +232,7 @@ private class ArrayUtilsTest
List<Object> objects = new List<Object> {1, 2, 3, 9, 4, 7, 8};
// WHEN - we request the last value
Object result = ArrayUtils.lastValue(objects);
Object result = fflib_ArrayUtils.lastValue(objects);
// THEN - the highest Datetime should be returned
System.assertEquals(8, result, 'Did not return the last value in the list of objects');