DuplicatePrintNumberIdentifiable
protocol DuplicatePrintNumberIdentifiable : UsedPrintNumberIdentifiable
A protocol for detecting duplicate print numbers used by a client application JSON files.
The protocol declares a single static variable for a dictionary of duplicate print numbers keyed by EntityLog EntityCode. Any instance conforming to the protocol will need to compile this dictionary for the duplicatePrintNumbersKeyedByEntityCode
parameter of the detectDuplicatePrintNumbersWithinEntityLogs(duplicatePrintNumbersKeyedByEntityCode:suppressAlert:) -> Bool
method.
The protocol can detect or verify the detection of two ‘types’ of duplicate: print numbers duplicated within individual EntityLogs and those duplicated across multiple EntityLogs.
Default versions of its methods are implemented in a protocol extension.
The default methods print alerts to the console specific to each type of duplicate.
Note
The protocol has not been made generic for reasons of legibility of intent. However it could easily be fully decoupled from Clarity should the need arise – generic placeholders would be needed for EntityLog, EntityLog.Message and EntityLog.Code.Alternatively the dictionary of EntityCodes keyed by duplicate print number could be compiled by MessageCollator and passed as an argument to detectDuplicatePrintNumbersAcrossEntityLogs(_ :suppressAlert:)->(Bool,[Int:[String]])
with a rewritten method signature. This would also require exposure of the default protocol ‘duplicate type 2’ print alert methods.
-
A static variable for storing a dictionary of duplicate print numbers keyed by EntityLog EntityCode.
Any instance conforming to the protocol will need to compile this dictionary for the
duplicatePrintNumbersKeyedByEntityCode
parameter of thedetectDuplicatePrintNumbersWithinEntityLogs(duplicatePrintNumbersKeyedByEntityCode:suppressAlert:) -> Bool
method.Declaration
Swift
static var duplicatePrintNumbersKeyedByEntityCode: [String : [Int]] { get set }
-
detectDuplicatePrintNumbersWithinEntityLogs(_:
Extension method_: ) A method that takes a dictionary of duplicate print numbers keyed by EntityCode and returns a Bool to verify whether any duplicate print numbers are contained in the dictionary. If any duplicates are found the method prints an alert to the console.
This method is used to print alerts relating to the ‘type 1’ duplicate: print numbers duplicated within individual EntityLogs.
If the incoming argument to the
duplicatePrintNumbersKeyedByEntityCode
is empty the method returns false otherwise it callsprintAlertForDuplicateType1(_:)
passing the parameter value as argument and returns true.Declaration
Swift
static func detectDuplicatePrintNumbersWithinEntityLogs(_ duplicatePrintNumbersKeyedByEntityCode: [String : [Int]], _ suppressAlert: Bool) -> Bool
Parameters
duplicatePrintNumbersKeyedByEntityCode
A dictionary of duplicate print numbers keyed by EntityCode.
suppressAlert
A Bool for suppressing the printing of an alert when duplicate print numbers have been detected. This is intended as a convenience for use during unit testing.
Return Value
A Bool that signifies whether any duplicate print numbers were contained in the incoming dictionary argument.
-
detectDuplicatePrintNumbersAcrossEntityLogs(_:
Extension method_: ) A method that takes an array of EntityLogs and returns a Bool to signify whether any duplicate print numbers have been detected across the EntityLogs. If any duplicates are found the method prints an alert to the console. The method also compiles and returns a tuple containing a dictionary of EntityCodes keyed by duplicate print number.
The method gets an array of integers representing all the print numbers used in the EntityLogs including duplicates across instances but not including duplicates within instances.
The array copies any uniqued duplicates to another local array
uniqueDuplicatePrintNumbersAcrossFiles
: this array is sorted and then filtered to remove any print numbers with the value0
from template files.If the
uniqueDuplicatePrintNumbersAcrossFiles
array is empty the method returns the valuefalse
with an empty dictionary. Otherwise the method calls ‘type 2 duplicate print alert methods, compiles a dictionary of EntityCodes keyed by duplicate print number and returns the dictionary with the valuetrue
.Note
The returned dictionary of EntityCodes keyed by duplicate print numberentityCodesKeyedByDuplicate
is compiled specifically for use by the test target.Declaration
Swift
static func detectDuplicatePrintNumbersAcrossEntityLogs(_ entityLogs: [EntityLog], _ suppressAlert: Bool) -> (isDuplicatesDetected: Bool, entityCodesKeyedByDuplicate: [Int : [String]])
Parameters
entityLogs
An array of EntityLogs.
suppressAlert
A Bool for suppressing the printing of an alert when duplicate print numbers have been detected. This is intended as a convenience for use during unit testing.
Return Value
A tuple that contains two elements:
- isDuplicatesDetected: A Bool that signifies whether any duplicate print numbers are detected existing across the EntityLogs of the
entityLogs
parameter argument. - entityCodesKeyedByDuplicate: A dictionary of EntityCodes keyed by duplicate print number. This is used exclusively for unit testing.
- isDuplicatesDetected: A Bool that signifies whether any duplicate print numbers are detected existing across the EntityLogs of the
-
printAlertForDuplicateType1(_:
Extension method) A method that takes a dictionary of duplicate print numbers keyed by EntityCode and prints an alert listing the duplicate print numbers contained in each EntityLog.
The alert is for the duplicate ‘type 1’ – duplicate print numbers detected within each EntityLog.
The method sorts and displays the list of print numbers numerically and alphabetically by EntityCode.
Declaration
Swift
fileprivate static func printAlertForDuplicateType1(_ duplicatePrintNumberDictionary: [String : [Int]])
Parameters
duplicatePrintNumberDictionary
A dictionary of duplicate print numbers keyed by EntityCode.
-
printAlertForDuplicateType2Header()
Extension methodA method that prints a common header for alerts of all occurrences of the duplicate ‘type 2’ – duplicate print numbers detected across multiple EntityLogs.
Declaration
Swift
fileprivate static func printAlertForDuplicateType2Header()
-
printAlertForDuplicateType2(_:
Extension method_: ) A method that takes a single duplicate print number
printNumber
and an array of EntityCodes. The method prints an alert listing each EntityCode that contains the duplicateprintNumber
.The alert is for the duplicate ‘type 2’ – duplicate print numbers detected across multiple EntityLogs.
Note
The method will be called once for each print number that is duplicated across multiple EntityCodes.
Declaration
Swift
fileprivate static func printAlertForDuplicateType2(_ printNumber: Int, _ entityCodeArray: [String])
Parameters
printNumber
An Int representing a duplicate print number.
entityCodeArray
An array of Strings representing EntityCodes that contain
printNumber
. -
printAdviceFooterForDuplicateType2()
Extension methodA method that prints a common footer for alerts of all occurrences of the duplicate ‘type 2’ – duplicate print numbers detected across multiple EntityLogs.
Declaration
Swift
fileprivate static func printAdviceFooterForDuplicateType2()
-
printAdviceFooterForAllDuplicates()
Extension methodA method that prints a common footer for both types of duplicate print number alert.
Declaration
Swift
static func printAdviceFooterForAllDuplicates()