Add method overload for fflib_ArrayUtils.replaceValues (#70)
Adds compatibility with Boolean values
This commit is contained in:
+3
-1
@@ -16,4 +16,6 @@ package.xml
|
|||||||
**/*.ts
|
**/*.ts
|
||||||
**/tsconfig*.json
|
**/tsconfig*.json
|
||||||
**/*.tsbuildinfo
|
**/*.tsbuildinfo
|
||||||
**/eslint.config.mjs
|
**/eslint.config.mjs
|
||||||
|
|
||||||
|
**/graphql.config.yml
|
||||||
+3
-1
@@ -59,4 +59,6 @@ sfdx-source/apex-extensions-examples
|
|||||||
target/
|
target/
|
||||||
/.illuminatedCloud/
|
/.illuminatedCloud/
|
||||||
**/tsconfig*.json
|
**/tsconfig*.json
|
||||||
**/*.tsbuildinfo
|
**/*.tsbuildinfo
|
||||||
|
|
||||||
|
**/graphql.config.yml
|
||||||
@@ -400,6 +400,36 @@ public class fflib_ArrayUtils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes two maps and replaces the value of the source with the value of the replacement,
|
||||||
|
* where the source value matches the replacement key.
|
||||||
|
* The value will become null if the source value does not exists as key in replacement map
|
||||||
|
*
|
||||||
|
* @param source The map to replace its value
|
||||||
|
* @param replacement The map to use its value for replacement
|
||||||
|
*
|
||||||
|
* @return Returns a Map<{Source-key} Id, {Replacement-value} Id>
|
||||||
|
*/
|
||||||
|
public static Map<Id, Boolean> replaceValue(Map<Id, Id> source, Map<Id, Boolean> replacement)
|
||||||
|
{
|
||||||
|
Map<Id, Boolean> result = new Map<Id, Boolean>();
|
||||||
|
for (Id keyId : source.keySet())
|
||||||
|
{
|
||||||
|
Id sourceValue = source.get(keyId);
|
||||||
|
|
||||||
|
if (replacement.containsKey(sourceValue))
|
||||||
|
{
|
||||||
|
result.put(keyId, replacement.get(sourceValue));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// There is no replacement value for this keyId
|
||||||
|
result.put(keyId, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes two maps and replaces the value of the source with the values of the replacement,
|
* Takes two maps and replaces the value of the source with the values of the replacement,
|
||||||
* where the source value matches the replacement key.
|
* where the source value matches the replacement key.
|
||||||
|
|||||||
@@ -322,6 +322,34 @@ private class fflib_ArrayUtilsTest
|
|||||||
System.Assert.isNull(result.get(accountIdC));
|
System.Assert.isNull(result.get(accountIdC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void itShouldReplaceValueInTheMap_boolean()
|
||||||
|
{
|
||||||
|
Id accountIdA = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
Id accountIdB = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
Id accountIdC = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
Id contactIdA = fflib_IDGenerator.generate(Schema.Contact.SObjectType);
|
||||||
|
Id contactIdB = fflib_IDGenerator.generate(Schema.Contact.SObjectType);
|
||||||
|
Map<Id, Id> source = new Map<Id, Id>
|
||||||
|
{
|
||||||
|
accountIdA => contactIdA,
|
||||||
|
accountIdB => contactIdB,
|
||||||
|
accountIdC => fflib_IDGenerator.generate(Schema.Contact.SObjectType)
|
||||||
|
};
|
||||||
|
Map<Id, Boolean> replacement = new Map<Id, Boolean>
|
||||||
|
{
|
||||||
|
contactIdA => true,
|
||||||
|
contactIdB => false
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<Id, Boolean> result = fflib_ArrayUtils.replaceValue(source, replacement);
|
||||||
|
|
||||||
|
System.Assert.areEqual(3, result.size());
|
||||||
|
System.Assert.isTrue(result.get(accountIdA));
|
||||||
|
System.Assert.isFalse(result.get(accountIdB));
|
||||||
|
System.Assert.isNull(result.get(accountIdC));
|
||||||
|
}
|
||||||
|
|
||||||
@IsTest
|
@IsTest
|
||||||
static void itShouldReturnAllValuesForTheGivenIds()
|
static void itShouldReturnAllValuesForTheGivenIds()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user