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
+4 -3
View File
@@ -15,9 +15,8 @@ A hands-on training session is also available to learn how to translate a user-s
## Method Reference ## Method Reference
When you rather prefer the bare overview of classes, methods and their examples, When you rather prefer the bare overview of classes, methods and their examples,
instead of the nicely readable Wiki,
then you can find a full overview of the methods, their signatures and description in the then you can find a full overview of the methods, their signatures and description in the
[ApexDocs](./docs). [ApexDocs](./docs/README.asciidoc).
## Migrating from apex-commons ## Migrating from apex-commons
@@ -25,7 +24,9 @@ then you can find a full overview of the methods, their signatures and descripti
- [How to adapt](./docs/how-to-adapt.md) when coming from fflib-apex-common - [How to adapt](./docs/how-to-adapt.md) when coming from fflib-apex-common
## Contributing ## Contributing
Anyone is welcome to fork this repository and propose changes via pull-requests. Anyone is welcome to fork this repository and propose changes or complete new features via raising a pull-requests.
You can also have a look at the open items in the [project(s)](./projects), feel free to pick an item from the kanban board!
## Donations ## Donations
+46 -3
View File
@@ -1,10 +1,53 @@
= Method Reference = Method Reference
== Core classes == Core classes
- fflib_ArrayUtils
- fflib_Comparator
- link:fflib_Criteria.asciidoc[fflib_Criteria]
- fflib_Operator
- fflib_OperatorUtils
== Features == Features
=== Application === Application
- link:fflib_AppBinding.asciidoc[fflib_AppBinding] * *Interfaces*
- fflib_IDomainFactory
- fflib_ISelectorFactory
- fflib_IServiceFactory
- fflib_IUnitOfWorkFactory
* *Classic*
- fflib_ClassicDomainFactory
- fflib_ClassicSelectorFactory
- fflib_ClassicServiceFactory
- fflib_ClassicTriggerHandlerFactory
- fflib_ClassicUnitOfWorkFactory
* *Dynamic*
** *Interfaces*
*** fflib_IAppBinding
*** fflib_IAppBindingModule
*** fflib_IAppBindingResolver
*** fflib_IAppBindingRouter
*** fflib_IAppBindings.cls
** link:fflib_AppBinding.asciidoc[fflib_AppBinding]
** fflib_AppBindingMetaDataModule
** fflib_AppBindingModule
** fflib_AppBindingResolver
** fflib_AppBindings
** fflib_AppBindingsSelector
** fflib_AppBindingType
** fflib_DynamicAppFactory
** fflib_DynamicDomainFactory
** fflib_DynamicSelectorFactory
** fflib_DynamicServiceFactory
** fflib_SharingMode
=== Primitive Domains
- Dates
- DateTimes
- Decimals
- Doubles
- Ids
- Integers
- Longs
- SObjects
- Strings
+432
View File
@@ -0,0 +1,432 @@
= fflib_Criteria Class
:Author: Wilhelmus G.J. Velzeboer
:Email: wim@velzeboer.nl
:Date: 2021
:Revision: version 1
A evaluator based on criteria
== Methods
- <<orCriteria, orCriteria()>> +
Changes the default comparator for each criteria to OR
- <<andCriteria, andCriteria()>> +
Changes the default comparator for each criteria to AND
- <<addOrCriteria, addOrCriteria(fflib_Criteria subCriteria)>> +
Adds a sub criteria with OR comparator
- <<addAndCriteria, addAndCriteria(fflib_Criteria subCriteria)>> +
Adds a sub criteria with AND comparator
- <<equalTo, equalTo(Schema.SObjectField field, Object value)>> +
Add an equal to criteria comparing a fields value to a given value
- <<evaluate, evaluate(Object record)>> +
Evaluates the stored criteria based on the given SObject
- <<greaterOrEqualTo, greaterOrEqualTo(Schema.SObjectField field, Object value)>> +
Compares the fields values to be greater or equal to the given value
- <<greaterThan, greaterThan(Schema.SObjectField field, Object value)>> +
Compares the fields values to be greater or equal to the given value
- <<inSet, inSet(Schema.SObjectField field, Set<Object> values)>> +
Checks if the given sets contains the fields values
- <<lessOrEqualTo, lessOrEqualTo(Schema.SObjectField field, Object value)>> +
Compares the fields values to be less or equal to the given value
- <<lessThan, lessThan(Schema.SObjectField field, Object value)>> +
Compares the fields values to be greater or equal to the given value
- <<notEqualTo, notEqualTo(Schema.SObjectField field, Object value)>> +
Add an equal to criteria comparing a fields value to a given value
- <<notInSet, notInSet(Schema.SObjectField field, Set<Date> values)>> +
Checks if the given sets does not contain the fields values
- <<toSQL, toSOQL()>> +
Generates the SOQL equivalent of the criteria provided
[[orCriteria]]
=== orCriteria()
Changes the default comparator for each criteria to OR
==== _Signature_
```java
public virtual fflib_Criteria orCriteria()
```
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.orCriteria()
.equalTo(Account.Name, 'Example')
.equalTo(Account.AccountNumber, '1234567')
// Evaluates:
// Name = 'Example' OR AccountNumber = '1234567'
```
___
[[andCriteria]]
=== andCriteria()
Changes the default comparator for each criteria to AND. +
By default the comparator is set to AND, so this method should only be used in custom implementations extended from fflib_Criteria.
==== _Signature_
```java
public virtual fflib_Criteria andCriteria()
```
==== _Example_
```java
new fflib_Criteria()
.andCriteria()
.equalTo(Account.Name, 'Example')
.equalTo(Account.AccountNumber, '1234567')
// Evaluates:
// Name = 'Example' AND AccountNumber = '1234567'
```
==== _Returns_
An instance of itself to enable method chaining
___
[[addOrCriteria]]
=== addOrCriteria(fflib_Criteria subCriteria)
Adds a sub criteria with OR comparator
==== _Signature_
```java
public virtual fflib_Criteria addOrCriteria(fflib_Criteria subCriteria)
```
==== _Parameters_
_subCriteria_ +
The condition of the sub criteria
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.equalTo(Account.Name, 'Example')
.addOrCriteria(
new fflib_Criteria()
.equalTo(Account.AccountNumber, '0001')
.equalTo(Account.AccountNumber, '0002'))
// Evaluates:
// Account.Name = 'Example' AND (Account.AccountNumber = '0001' OR Account.AccountNumber = '0002')
```
___
[[addAndCriteria]]
=== addAndCriteria(fflib_Criteria subCriteria)
Adds a sub criteria with AND comparator
==== _Signature_
```java
public virtual fflib_Criteria addAndCriteria(fflib_Criteria subCriteria)
```
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.orCriteria()
.equalTo(Account.Name, 'Example')
.addAndCriteria(
new fflib_Criteria()
.equalTo(Account.AccountNumber, '0001')
.equalTo(Account.ShippingCountry, 'USA'))
// Evaluates:
// Name = 'Example' OR (AccountNumber = '0001' AND ShippingCountry = 'USA')
```
___
[[equalTo]]
=== equalTo(Schema.SObjectField field, Object value)
Add an equal to criteria comparing a fields value to a given value
==== _Signature_
```java
public virtual fflib_Criteria equalTo(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to evaluate
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.equalTo(Account.Name, 'Example')
// Evaluates:
// Name = 'Example'
```
___
[[evaluate]]
=== evaluate(Object record)
Evaluates the stored criteria based on the given SObject
==== _Signature_
```java
public virtual Boolean evaluate(Object record)
```
==== _Parameters_
_**record**_ +
The SObject to evaluate
==== _Returns_
The Boolean result of the evaluated criteria
==== _Example_
```java
Account record = new Account( Name = 'Example );
System.assert(
new fflib_Criteria()
.equalTo(Account.Name, 'Example')
.evaluate(record)
);
```
___
[[greaterOrEqualTo]]
=== greaterOrEqualTo(Schema.SObjectField field, Object value)
Compares the fields values to be greater or equal to the given value.
Evaluates to false if the field value is null.
==== _Signature_
```java
public virtual fflib_Criteria greaterOrEqualTo(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.greaterOrEqualTo(Account.AnnualRevenue, 54321)
// Evaluates:
// AnnualRevenue >= 54321
```
___
[[greaterThan]]
=== greaterThan(Schema.SObjectField field, Object value)
Compares the fields values to be greater or equal to the given value
Evaluates to false if the field value is null
==== _Signature_
```java
public virtual fflib_Criteria greaterThan(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.greaterThan(Account.AnnualRevenue, 54321)
// Evaluates:
// AnnualRevenue > 54321
```
___
[[inSet]]
=== inSet(Schema.SObjectField field, Set<Object> values)
Checks if the given sets contains the fields values
==== _Signature_
```java
public virtual fflib_Criteria inSet(Schema.SObjectField field, Set<Object> values)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**values**_ +
The values to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.inSet(Account.Type, new Set<Object>{'Customer', 'Competitor', 'Partner'})
// Evaluates:
// Account.Type IN ('Customer','Competitor','Partner')
```
___
[[lessOrEqualTo]]
=== lessOrEqualTo(Schema.SObjectField field, Object value)
Compares the fields values to be less or equal to the given value
Evaluates to true if the field value is null
==== _Signature_
```java
public virtual fflib_Criteria lessOrEqualTo(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.lessOrEqualTo(Account.AnnualRevenue, 54321)
// Evaluates:
// AnnualRevenue > 54321
```
___
[[lessThan]]
=== lessThan(Schema.SObjectField field, Object value)
Compares the fields values to be less or equal to the given value
Evaluates to true if the field value is null
==== _Signature_
```java
public virtual fflib_Criteria lessThan(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.lessThan(Account.AnnualRevenue, 54321)
// Evaluates:
// AnnualRevenue < 54321
```
___
[[notEqualTo]]
=== notEqualTo(Schema.SObjectField field, Object value)
Add a not equal to criteria comparing a fields value to a given value
==== _Signature_
```java
public virtual fflib_Criteria notEqualTo(Schema.SObjectField field, Object value)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to evaluate
_**value**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.notEqualTo(Account.Name, 'Example')
// Evaluates:
// Name != 'Example'
```
___
[[notInSet]]
=== notInSet(Schema.SObjectField field, Set<Object> values)
Checks if the given sets does not contain the fields values
==== _Signature_
```java
public fflib_Criteria notInSet(Schema.SObjectField field, Set<Object> values)
```
==== _Parameters_
_**field**_ +
The Schema.sObjectField to use its value
_**values**_ +
The value to be compared to the fields value
==== _Returns_
An instance of itself to enable method chaining
==== _Example_
```java
new fflib_Criteria()
.notInSet(Account.Type, new Set<Object>{'Customer', 'Competitor', 'Partner'})
// Evaluates:
// Account.Type NOT IN ('Customer','Competitor','Partner')
```
___
[[toSQL]]
=== toSOQL()
Generates the SOQL equivalent of the criteria provided
==== _Signature_
```java
public virtual String toSOQL()
```
==== _Returns_
The "where" part in the SOQL statement
___
@@ -64,7 +64,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Name = 'Example' OR AccountNumber = '1234567' * Name = 'Example' OR AccountNumber = '1234567'
*/ */
public fflib_Criteria orCriteria() public virtual fflib_Criteria orCriteria()
{ {
this.type = 'OR'; this.type = 'OR';
return this; return this;
@@ -75,10 +75,10 @@ public virtual with sharing class fflib_Criteria
* By default the comparator is set to AND, * By default the comparator is set to AND,
* so this method should only be used in custom implementations extended from fflib_Criteria * 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 * @example
* new MyCustomCriteria() * new fflib_Criteria()
* .andCriteria() * .andCriteria()
* .equalTo(Account.Name, 'Example') * .equalTo(Account.Name, 'Example')
* .equalTo(Account.AccountNumber, '1234567') * .equalTo(Account.AccountNumber, '1234567')
@@ -86,7 +86,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Name = 'Example' AND AccountNumber = '1234567' * Name = 'Example' AND AccountNumber = '1234567'
*/ */
public fflib_Criteria andCriteria() public virtual fflib_Criteria andCriteria()
{ {
this.type = 'AND'; this.type = 'AND';
return this; return this;
@@ -97,7 +97,7 @@ public virtual with sharing class fflib_Criteria
* *
* @param subCriteria The condition of the sub criteria * @param subCriteria The condition of the sub criteria
* *
* @return Instance of fflib_Criteria * @return An instance of itself to enable method chaining
* *
* @example * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -110,7 +110,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Account.Name = 'Example' AND (Account.AccountNumber = '0001' OR Account.AccountNumber = '0002') * 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.orCriteria();
subCriteria.setEmbraced(true); subCriteria.setEmbraced(true);
@@ -123,7 +123,7 @@ public virtual with sharing class fflib_Criteria
* *
* @param subCriteria The condition of the sub criteria * @param subCriteria The condition of the sub criteria
* *
* @return Instance of fflib_Criteria * @return An instance of itself to enable method chaining
* *
* @example * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -137,7 +137,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Name = 'Example' OR (AccountNumber = '0001' AND ShippingCountry = 'USA') * 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.andCriteria();
subCriteria.setEmbraced(true); 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 field The sObjectField to evaluate
* @param value The value to be compared to the fields 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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -160,19 +160,19 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Name = 'Example' * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.EQUALS, value));
return this; 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 field The sObjectField to evaluate
* @param value The value to be compared to the fields 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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -181,7 +181,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Name != 'Example' * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.NOT_EQUALS, value));
return this; return this;
@@ -194,7 +194,7 @@ public virtual with sharing class fflib_Criteria
* *
* @return The Boolean result of the evaluated 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; 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 * 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 * @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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -230,20 +230,20 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* AnnualRevenue >= 54321 * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.GREATER_THAN_OR_EQUAL_TO, value));
return this; 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 * 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 * @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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -252,20 +252,20 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* AnnualRevenue > 54321 * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.GREATER_THAN, value));
return this; 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 * 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 * @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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -274,7 +274,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* AnnualRevenue <= 54321 * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.LESS_THAN_OR_EQUAL_TO, value));
return this; 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 * 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 * @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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -297,19 +297,19 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* AnnualRevenue < 54321 * 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)); evaluators.add(new FieldEvaluator(field, fflib_Operator.LESS_THAN, value));
return this; 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 field The Schema.sObjectField to use its value
* @param values The value to be compared to the fields 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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -318,7 +318,7 @@ public virtual with sharing class fflib_Criteria
* Evaluates: * Evaluates:
* Account.Type IN ('Customer','Competitor','Partner') * 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))); 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 field The field to use its value
* @param values The value to be compared to the fields 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 * @example
* new fflib_Criteria() * 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 * @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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -434,7 +434,7 @@ public virtual with sharing class fflib_Criteria
* @param field The field to use its value * @param field The field to use its value
* @param values The value to be compared to the fields 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 * @example
* new fflib_Criteria() * new fflib_Criteria()
@@ -454,7 +454,7 @@ public virtual with sharing class fflib_Criteria
* *
* @return The "where" part in the SOQL statement * @return The "where" part in the SOQL statement
*/ */
public String toSOQL() public virtual String toSOQL()
{ {
if (this.evaluators.isEmpty()) return ''; if (this.evaluators.isEmpty()) return '';
@@ -1,5 +1,5 @@
/** /**
* File Name: Array * File Name: fflib_ArrayUtils
* @description * @description
* *
* @author architect ir. Wilhelmus G.J. Velzeboer * @author architect ir. Wilhelmus G.J. Velzeboer
@@ -28,10 +28,10 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * 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. * 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 constructor to prevent instantiation */
private ArrayUtils() {} private fflib_ArrayUtils() {}
/** /**
* Creates a clone from the provided list and returns the sorted list * Creates a clone from the provided list and returns the sorted list
@@ -1,11 +1,11 @@
/** /**
* File Name: ArrayTest * File Name: fflib_ArrayUtilsTest
* @description * @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) @IsTest(IsParallel=true)
private class ArrayUtilsTest private class fflib_ArrayUtilsTest
{ {
@IsTest @IsTest
@@ -13,7 +13,7 @@ private class ArrayUtilsTest
{ {
System.assertEquals( System.assertEquals(
new List<String> {'123', '456', '789'}, new List<String> {'123', '456', '789'},
ArrayUtils.objectToString( fflib_ArrayUtils.objectToString(
new List<Object> {123, 456, 789} new List<Object> {123, 456, 789}
) )
); );
@@ -24,7 +24,7 @@ private class ArrayUtilsTest
{ {
System.assertEquals( System.assertEquals(
new List<String> {'123', '456', '789'}, new List<String> {'123', '456', '789'},
ArrayUtils.objectToString( fflib_ArrayUtils.objectToString(
new List<Object> {'123', '456', '789'} new List<Object> {'123', '456', '789'}
) )
); );
@@ -35,7 +35,7 @@ private class ArrayUtilsTest
{ {
System.assertEquals( System.assertEquals(
new List<String>(), new List<String>(),
ArrayUtils.objectToString( fflib_ArrayUtils.objectToString(
new List<Object>() new List<Object>()
) )
); );
@@ -46,7 +46,7 @@ private class ArrayUtilsTest
{ {
System.assertEquals( System.assertEquals(
new List<String> {'1', '2', '3'}, new List<String> {'1', '2', '3'},
ArrayUtils.objectToString( fflib_ArrayUtils.objectToString(
new Set<Object> {1, 2, 3} new Set<Object> {1, 2, 3}
) )
); );
@@ -59,7 +59,7 @@ private class ArrayUtilsTest
Id idB = fflib_IDGenerator.generate(Account.SObjectType); Id idB = fflib_IDGenerator.generate(Account.SObjectType);
System.assertEquals( System.assertEquals(
new Set<Id> {idA, idB}, new Set<Id> {idA, idB},
ArrayUtils.objectToIds( fflib_ArrayUtils.objectToIds(
new Set<Object> new Set<Object>
{ {
(Object) idA, (Object) idA,
@@ -79,7 +79,7 @@ private class ArrayUtilsTest
(Object) 'B', (Object) 'B',
(Object) 'A' (Object) 'A'
}, },
ArrayUtils.reverse( fflib_ArrayUtils.reverse(
new List<Object> new List<Object>
{ {
(Object) 'A', (Object) 'A',
@@ -100,7 +100,7 @@ private class ArrayUtilsTest
(SObject) new Account(Name = 'B'), (SObject) new Account(Name = 'B'),
(SObject) new Account(Name = 'A') (SObject) new Account(Name = 'A')
}, },
ArrayUtils.reverse( fflib_ArrayUtils.reverse(
new List<SObject> new List<SObject>
{ {
(SObject) new Account(Name = 'A'), (SObject) new Account(Name = 'A'),
@@ -121,7 +121,7 @@ private class ArrayUtilsTest
'TEST B', 'TEST B',
'TEST C' 'TEST C'
}, },
ArrayUtils.upperCase( fflib_ArrayUtils.upperCase(
new List<String> new List<String>
{ {
'test a', 'test a',
@@ -137,7 +137,7 @@ private class ArrayUtilsTest
{ {
System.assertEquals( System.assertEquals(
new List<String> {'abc', 'def'}, new List<String> {'abc', 'def'},
ArrayUtils.lowerCase( fflib_ArrayUtils.lowerCase(
new List<String> {'ABC', 'DEF'} new List<String> {'ABC', 'DEF'}
) )
); );
@@ -147,28 +147,28 @@ private class ArrayUtilsTest
static void testIsEmpty() static void testIsEmpty()
{ {
List<String> aNull = null; List<String> aNull = null;
System.assertEquals(true, ArrayUtils.isEmpty(aNull)); System.assertEquals(true, fflib_ArrayUtils.isEmpty(aNull));
System.assertEquals(true, ArrayUtils.isEmpty(new List<String> {})); System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List<String> {}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<String> {'a'})); System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<String> {'a'}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<String> {'a', 'b'})); System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<String> {'a', 'b'}));
System.assertEquals(true, ArrayUtils.isEmpty(new List<Integer> {})); System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List<Integer> {}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<Integer> {1})); System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<Integer> {1}));
System.assertEquals(false, ArrayUtils.isEmpty(new List<Integer> {1, 2})); System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List<Integer> {1, 2}));
} }
@IsTest @IsTest
static void testIsNotEmpty() static void testIsNotEmpty()
{ {
List<String> aNull = null; List<String> aNull = null;
System.assertEquals(false, ArrayUtils.isNotEmpty(aNull)); System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(aNull));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<String> {})); System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<String> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<String> {'a'})); System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<String> {'a'}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<String> {'a', 'b'})); System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<String> {'a', 'b'}));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<Integer> {})); System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<Integer> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Integer> {1})); System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Integer> {1}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Integer> {1, 2})); System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Integer> {1, 2}));
System.assertEquals(false, ArrayUtils.isNotEmpty(new List<Account> {})); System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List<Account> {}));
System.assertEquals(true, ArrayUtils.isNotEmpty(new List<Account> {new Account(Name = 'test')})); System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List<Account> {new Account(Name = 'test')}));
} }
@IsTest @IsTest
@@ -178,7 +178,7 @@ private class ArrayUtilsTest
List<Datetime> datetimes = generateDateTimes(); List<Datetime> datetimes = generateDateTimes();
// WHEN - we request the maxDatetime // WHEN - we request the maxDatetime
Datetime maxDatetime = ArrayUtils.maxDatetime(datetimes); Datetime maxDatetime = fflib_ArrayUtils.maxDatetime(datetimes);
// THEN - the highest Datetime should be returned // THEN - the highest Datetime should be returned
System.assertEquals(datetimes.get(1), maxDatetime); System.assertEquals(datetimes.get(1), maxDatetime);
@@ -191,7 +191,7 @@ private class ArrayUtilsTest
List<Datetime> datetimes = generateDateTimes(); List<Datetime> datetimes = generateDateTimes();
// WHEN - we request the maxDatetime // WHEN - we request the maxDatetime
Datetime maxDatetime = ArrayUtils.minDatetime(datetimes); Datetime maxDatetime = fflib_ArrayUtils.minDatetime(datetimes);
// THEN - the highest Datetime should be returned // THEN - the highest Datetime should be returned
System.assertEquals(datetimes.get(4), maxDatetime); System.assertEquals(datetimes.get(4), maxDatetime);
@@ -201,11 +201,11 @@ private class ArrayUtilsTest
static void itShouldHandleNullInputsForMaxDatatime() static void itShouldHandleNullInputsForMaxDatatime()
{ {
System.assertEquals( 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' 'maxDatetime method was unable to handle an empty list as input'
); );
System.assertEquals( System.assertEquals(
null, ArrayUtils.maxDatetime(null), null, fflib_ArrayUtils.maxDatetime(null),
'maxDatetime method was unable to handle null as input' '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 // 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.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'); 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}; List<Object> objects = new List<Object> {1, 2, 3, 9, 4, 7, 8};
// WHEN - we request the last value // WHEN - we request the last value
Object result = ArrayUtils.lastValue(objects); Object result = fflib_ArrayUtils.lastValue(objects);
// THEN - the highest Datetime should be returned // THEN - the highest Datetime should be returned
System.assertEquals(8, result, 'Did not return the last value in the list of objects'); System.assertEquals(8, result, 'Did not return the last value in the list of objects');