From d5bfc3c48c01776ac58b4d0e3d7fef416a53888f Mon Sep 17 00:00:00 2001 From: Wim Velzeboer Date: Tue, 6 Jul 2021 16:32:38 +0100 Subject: [PATCH] Add documentation for fflib_Criteria --- README.md | 7 +- docs/README.asciidoc | 49 +- docs/fflib_Criteria.asciidoc | 432 ++++++++++++++++++ .../classes/criteria/fflib_Criteria.cls | 84 ++-- .../{ArrayUtils.cls => fflib_ArrayUtils.cls} | 6 +- ...meta.xml => fflib_ArrayUtils.cls-meta.xml} | 0 .../classes/utils/fflib_ArrayUtilsTest.cls} | 68 +-- .../utils/fflib_ArrayUtilsTest.cls-meta.xml} | 0 8 files changed, 561 insertions(+), 85 deletions(-) create mode 100644 docs/fflib_Criteria.asciidoc rename sfdx-source/apex-extensions/main/default/classes/utils/{ArrayUtils.cls => fflib_ArrayUtils.cls} (98%) rename sfdx-source/apex-extensions/main/default/classes/utils/{ArrayUtils.cls-meta.xml => fflib_ArrayUtils.cls-meta.xml} (100%) rename sfdx-source/apex-extensions/{main/default/classes/utils/ArrayUtilsTest.cls => tests/classes/utils/fflib_ArrayUtilsTest.cls} (71%) rename sfdx-source/apex-extensions/{main/default/classes/utils/ArrayUtilsTest.cls-meta.xml => tests/classes/utils/fflib_ArrayUtilsTest.cls-meta.xml} (100%) diff --git a/README.md b/README.md index 08b8cc6..2396c09 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,8 @@ A hands-on training session is also available to learn how to translate a user-s ## Method Reference 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 -[ApexDocs](./docs). +[ApexDocs](./docs/README.asciidoc). ## 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 ## 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 diff --git a/docs/README.asciidoc b/docs/README.asciidoc index 9461c20..adce1ae 100644 --- a/docs/README.asciidoc +++ b/docs/README.asciidoc @@ -1,10 +1,53 @@ = Method Reference == Core classes - - +- fflib_ArrayUtils +- fflib_Comparator +- link:fflib_Criteria.asciidoc[fflib_Criteria] +- fflib_Operator +- fflib_OperatorUtils == Features === Application -- link:fflib_AppBinding.asciidoc[fflib_AppBinding] \ No newline at end of file +* *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 diff --git a/docs/fflib_Criteria.asciidoc b/docs/fflib_Criteria.asciidoc new file mode 100644 index 0000000..afc9b98 --- /dev/null +++ b/docs/fflib_Criteria.asciidoc @@ -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 + +- <> + +Changes the default comparator for each criteria to OR +- <> + +Changes the default comparator for each criteria to AND +- <> + +Adds a sub criteria with OR comparator +- <> + +Adds a sub criteria with AND comparator +- <> + +Add an equal to criteria comparing a fields value to a given value +- <> + +Evaluates the stored criteria based on the given SObject +- <> + +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 +- < values)>> + +Checks if the given sets contains the fields values +- <> + +Compares the fields values to be less or equal to the given value +- <> + +Compares the fields values to be greater or equal to the given value +- <> + +Add an equal to criteria comparing a fields value to a given value +- < values)>> + +Checks if the given sets does not contain the fields values +- <> + +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 values) +Checks if the given sets contains the fields values + +==== _Signature_ +```java +public virtual fflib_Criteria inSet(Schema.SObjectField field, Set 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{'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 values) +Checks if the given sets does not contain the fields values + +==== _Signature_ +```java +public fflib_Criteria notInSet(Schema.SObjectField field, Set 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{'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 + +___ \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/default/classes/criteria/fflib_Criteria.cls b/sfdx-source/apex-extensions/main/default/classes/criteria/fflib_Criteria.cls index 1805f10..4e6274a 100644 --- a/sfdx-source/apex-extensions/main/default/classes/criteria/fflib_Criteria.cls +++ b/sfdx-source/apex-extensions/main/default/classes/criteria/fflib_Criteria.cls @@ -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 values) + public virtual fflib_Criteria inSet(Schema.SObjectField field, Set values) { return inSet(field, new fflib_Objects(new List(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 ''; diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtils.cls b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls similarity index 98% rename from sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtils.cls rename to sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls index 8c1c732..90b05d7 100644 --- a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtils.cls +++ b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls @@ -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 diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtils.cls-meta.xml b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls-meta.xml similarity index 100% rename from sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtils.cls-meta.xml rename to sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls-meta.xml diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtilsTest.cls b/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls similarity index 71% rename from sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtilsTest.cls rename to sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls index 4d9028e..c240706 100644 --- a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtilsTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls @@ -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 {'123', '456', '789'}, - ArrayUtils.objectToString( + fflib_ArrayUtils.objectToString( new List {123, 456, 789} ) ); @@ -24,7 +24,7 @@ private class ArrayUtilsTest { System.assertEquals( new List {'123', '456', '789'}, - ArrayUtils.objectToString( + fflib_ArrayUtils.objectToString( new List {'123', '456', '789'} ) ); @@ -35,7 +35,7 @@ private class ArrayUtilsTest { System.assertEquals( new List(), - ArrayUtils.objectToString( + fflib_ArrayUtils.objectToString( new List() ) ); @@ -46,7 +46,7 @@ private class ArrayUtilsTest { System.assertEquals( new List {'1', '2', '3'}, - ArrayUtils.objectToString( + fflib_ArrayUtils.objectToString( new Set {1, 2, 3} ) ); @@ -59,7 +59,7 @@ private class ArrayUtilsTest Id idB = fflib_IDGenerator.generate(Account.SObjectType); System.assertEquals( new Set {idA, idB}, - ArrayUtils.objectToIds( + fflib_ArrayUtils.objectToIds( new Set { (Object) idA, @@ -79,7 +79,7 @@ private class ArrayUtilsTest (Object) 'B', (Object) 'A' }, - ArrayUtils.reverse( + fflib_ArrayUtils.reverse( new List { (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) new Account(Name = 'A'), @@ -121,7 +121,7 @@ private class ArrayUtilsTest 'TEST B', 'TEST C' }, - ArrayUtils.upperCase( + fflib_ArrayUtils.upperCase( new List { 'test a', @@ -137,7 +137,7 @@ private class ArrayUtilsTest { System.assertEquals( new List {'abc', 'def'}, - ArrayUtils.lowerCase( + fflib_ArrayUtils.lowerCase( new List {'ABC', 'DEF'} ) ); @@ -147,28 +147,28 @@ private class ArrayUtilsTest static void testIsEmpty() { List aNull = null; - System.assertEquals(true, ArrayUtils.isEmpty(aNull)); - System.assertEquals(true, ArrayUtils.isEmpty(new List {})); - System.assertEquals(false, ArrayUtils.isEmpty(new List {'a'})); - System.assertEquals(false, ArrayUtils.isEmpty(new List {'a', 'b'})); - System.assertEquals(true, ArrayUtils.isEmpty(new List {})); - System.assertEquals(false, ArrayUtils.isEmpty(new List {1})); - System.assertEquals(false, ArrayUtils.isEmpty(new List {1, 2})); + System.assertEquals(true, fflib_ArrayUtils.isEmpty(aNull)); + System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List {})); + System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List {'a'})); + System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List {'a', 'b'})); + System.assertEquals(true, fflib_ArrayUtils.isEmpty(new List {})); + System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List {1})); + System.assertEquals(false, fflib_ArrayUtils.isEmpty(new List {1, 2})); } @IsTest static void testIsNotEmpty() { List aNull = null; - System.assertEquals(false, ArrayUtils.isNotEmpty(aNull)); - System.assertEquals(false, ArrayUtils.isNotEmpty(new List {})); - System.assertEquals(true, ArrayUtils.isNotEmpty(new List {'a'})); - System.assertEquals(true, ArrayUtils.isNotEmpty(new List {'a', 'b'})); - System.assertEquals(false, ArrayUtils.isNotEmpty(new List {})); - System.assertEquals(true, ArrayUtils.isNotEmpty(new List {1})); - System.assertEquals(true, ArrayUtils.isNotEmpty(new List {1, 2})); - System.assertEquals(false, ArrayUtils.isNotEmpty(new List {})); - System.assertEquals(true, ArrayUtils.isNotEmpty(new List {new Account(Name = 'test')})); + System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(aNull)); + System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List {})); + System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List {'a'})); + System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List {'a', 'b'})); + System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List {})); + System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List {1})); + System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List {1, 2})); + System.assertEquals(false, fflib_ArrayUtils.isNotEmpty(new List {})); + System.assertEquals(true, fflib_ArrayUtils.isNotEmpty(new List {new Account(Name = 'test')})); } @IsTest @@ -178,7 +178,7 @@ private class ArrayUtilsTest List 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 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()), + null, fflib_ArrayUtils.maxDatetime(new List()), '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 sorted = ArrayUtils.cloneAndSort(unsorted); + List sorted = fflib_ArrayUtils.cloneAndSort(unsorted); System.assertNotEquals(unsorted, sorted, 'The original object was modified, something went wrong with the cloning'); System.assertEquals(new List {-7, 1, 2, 30, 76}, sorted, 'Incorrect sorted list returned'); } @@ -232,7 +232,7 @@ private class ArrayUtilsTest List objects = new List {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'); diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtilsTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls-meta.xml similarity index 100% rename from sfdx-source/apex-extensions/main/default/classes/utils/ArrayUtilsTest.cls-meta.xml rename to sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls-meta.xml