Class SwiftMessageComparator
- java.lang.Object
-
- com.prowidesoftware.swift.utils.SwiftMessageComparator
-
- All Implemented Interfaces:
java.util.Comparator<SwiftMessage>
- Direct Known Subclasses:
AckMessageComparator
public class SwiftMessageComparator extends java.lang.Object implements java.util.Comparator<SwiftMessage>
An MT message comparator that compares all values from block 1 2 3, 4 and 5.By default the messages must be an exact match in order to be considered equal. This can be tailored for example to ignore EOLS in multiline fields, to ignore header sequence and session numbers or to ignore the trailer block. Specific text block fields can also indicated to be ignore when comparing the messages.
This implementation can be overwritten to add special compare implementations for each of the blocks or to setup the parameters in different ways.
Despite implementing the Comparator interface this class is useful to find a message 'almost equal' to another one but it is not intended to sort messages, since it does not provide ordering information of any kind.
NOTE: when both blocks being compared are null they are considered equals, even when they're actually empty.
- Since:
- 7.8.8
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
ignoreBlock2OptionalFields
protected boolean
ignoreBlock3
protected boolean
ignoreEolsInMultiline
Flag to enable different type of EOLs in multi-line valuesprotected boolean
ignoreHeaderSession
protected boolean
ignoreLocationFlag
protected boolean
ignoreLT
protected boolean
ignorePriority
protected boolean
ignoreTrailer
-
Constructor Summary
Constructors Constructor Description SwiftMessageComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addTagnameToIgnore(java.lang.String tagName)
Adds a tag in the block4 that will be ignore in the comparison.int
compare(SwiftMessage left, SwiftMessage right)
Compare the two given messages.boolean
compareB1(SwiftBlock1 left, SwiftBlock1 right)
Return true if blocks are equals in all values but the ones with the ignore flag.boolean
compareB2(SwiftBlock2 left, SwiftBlock2 right)
Return true if blocks are equals in all values but the ones with the ignore flag.boolean
compareTagListBlock(SwiftTagListBlock left, SwiftTagListBlock right)
Compare all tags in taglist from both given blocks.java.util.List<java.lang.String>
getTagnamesToIgnore()
boolean
isIgnoreBlock2OptionalFields()
boolean
isIgnoreBlock3()
boolean
isIgnoreEolsInMultiline()
boolean
isIgnoreHeaderSession()
boolean
isIgnoreLocationFlag()
boolean
isIgnoreLT()
boolean
isIgnorePriority()
boolean
isIgnoreTrailer()
void
setIgnoreBlock2OptionalFields(boolean ignoreBlock2OptionalFields)
When this is set to true, the Delivery Monitoring and Obsolescence Period of block 2 Input will be ignored in the comparison.void
setIgnoreBlock3(boolean ignoreBlock3)
If this is set to true, the whole block 3 will be ignored in the headers comparison.void
setIgnoreEolsInMultiline(boolean ignoreEolsInMultiline)
When this is set to true, different end of lines characters LF or CRLF will be considered the same.void
setIgnoreHeaderSession(boolean ignoreHeaderSession)
When this is set to true, the block 1 session and sequence numbers will be ignored in the comparison.void
setIgnoreLocationFlag(boolean ignoreLocationFlag)
If this is set to true, when comparing block 1 and block 2, the second digit of the location code (character at 8th position of the logical terminal addresses) will be ignored in the comparison.void
setIgnoreLT(boolean ignoreLT)
If this is set to true, when comparing block 1 and block 2, the Logical Terminal identifier will be ignored in the comparison.void
setIgnorePriority(boolean ignorePriority)
If this is set to true, the priority flag in block 2 will be ignored int the comparison.void
setIgnoreTrailer(boolean ignoreTrailer)
When this is set to true, the block 5 will be ignored in the comparison.void
setTagnamesToIgnore(java.util.List<java.lang.String> tagnamesToIgnore)
Sets a new list of tags in the block 4 that will be ignored in the comparison.
-
-
-
Field Detail
-
ignoreEolsInMultiline
protected boolean ignoreEolsInMultiline
Flag to enable different type of EOLs in multi-line values
-
ignoreHeaderSession
protected boolean ignoreHeaderSession
-
ignoreTrailer
protected boolean ignoreTrailer
-
ignoreBlock2OptionalFields
protected boolean ignoreBlock2OptionalFields
- Since:
- 8.0.3
-
ignoreLT
protected boolean ignoreLT
- Since:
- 9.1.3
-
ignoreLocationFlag
protected boolean ignoreLocationFlag
- Since:
- 9.1.3
-
ignoreBlock3
protected boolean ignoreBlock3
- Since:
- 9.1.6
-
ignorePriority
protected boolean ignorePriority
- Since:
- 9.1.6
-
-
Method Detail
-
compare
public int compare(SwiftMessage left, SwiftMessage right)
Compare the two given messages. Message parameters cannot be null.This implementation calls the specific comparator methods for blocks 1 and 2, and the generic tag list block comparator for other blocks
- Specified by:
compare
in interfacejava.util.Comparator<SwiftMessage>
- See Also:
compareB1(SwiftBlock1, SwiftBlock1)
,compareB2(SwiftBlock2, SwiftBlock2)
,compareTagListBlock(SwiftTagListBlock, SwiftTagListBlock)
-
compareB2
public boolean compareB2(SwiftBlock2 left, SwiftBlock2 right)
Return true if blocks are equals in all values but the ones with the ignore flag. Fields that can be ignored are the optional fields, the BIC LT identifier and the BIC location flag.
If both blocks null will returntrue
and one null and the other one not null will returnfalse
- Parameters:
left
- first block to compareright
- second block to compare- Returns:
- true if both blocks are equal or null, false otherwise
-
compareTagListBlock
public boolean compareTagListBlock(SwiftTagListBlock left, SwiftTagListBlock right)
Compare all tags in taglist from both given blocks.This implementation uses
Tag.equals(Object)
for fields comparison.NOTE a null or empty block is considered a blank block; then if both are blank this method returns
true
and if one of the blocks is blank and the other is not this method returnsfalse
- Parameters:
left
- first block to compareright
- second block to compare- Returns:
- true if both blocks are equal (or blank) and false in any other case
-
compareB1
public boolean compareB1(SwiftBlock1 left, SwiftBlock1 right)
Return true if blocks are equals in all values but the ones with the ignore flag. Fields that can be ignored are the session and sequence numbers, the BIC LT identifier and the BIC location flag. If both parameters are null it returnstrue
, since there is nothing to compare.- Parameters:
left
- block to compareright
- block to compare- Returns:
- true if left equals right (except mentioned fields) or both null, false otherwise
-
isIgnoreEolsInMultiline
public boolean isIgnoreEolsInMultiline()
- Returns:
- boolean value of ignoreEolsInMultiline property
- See Also:
setIgnoreEolsInMultiline(boolean)
-
setIgnoreEolsInMultiline
public void setIgnoreEolsInMultiline(boolean ignoreEolsInMultiline)
When this is set to true, different end of lines characters LF or CRLF will be considered the same.
-
getTagnamesToIgnore
public java.util.List<java.lang.String> getTagnamesToIgnore()
- Returns:
- tags to ignore list
-
setTagnamesToIgnore
public void setTagnamesToIgnore(java.util.List<java.lang.String> tagnamesToIgnore)
Sets a new list of tags in the block 4 that will be ignored in the comparison.
-
addTagnameToIgnore
public boolean addTagnameToIgnore(java.lang.String tagName)
Adds a tag in the block4 that will be ignore in the comparison.- Parameters:
tagName
- tag to add- Returns:
- true if tag was added
-
isIgnoreHeaderSession
public boolean isIgnoreHeaderSession()
- See Also:
setIgnoreHeaderSession(boolean)
-
setIgnoreHeaderSession
public void setIgnoreHeaderSession(boolean ignoreHeaderSession)
When this is set to true, the block 1 session and sequence numbers will be ignored in the comparison. Defaults to false.
-
isIgnoreTrailer
public boolean isIgnoreTrailer()
- See Also:
setIgnoreTrailer(boolean)
-
setIgnoreTrailer
public void setIgnoreTrailer(boolean ignoreTrailer)
When this is set to true, the block 5 will be ignored in the comparison. Defaults to false.
-
isIgnoreBlock2OptionalFields
public boolean isIgnoreBlock2OptionalFields()
- Since:
- 8.0.3
- See Also:
setIgnoreBlock2OptionalFields(boolean)
-
setIgnoreBlock2OptionalFields
public void setIgnoreBlock2OptionalFields(boolean ignoreBlock2OptionalFields)
When this is set to true, the Delivery Monitoring and Obsolescence Period of block 2 Input will be ignored in the comparison. Meaning different values for this optional fields in the compared blocks will return true as comparison result. Defaults to false.- Since:
- 8.0.3
-
isIgnoreLT
public boolean isIgnoreLT()
- Since:
- 9.1.3
- See Also:
setIgnoreLT(boolean)
-
setIgnoreLT
public void setIgnoreLT(boolean ignoreLT)
If this is set to true, when comparing block 1 and block 2, the Logical Terminal identifier will be ignored in the comparison. Meaning different values for the LT identifier such as FFFFUS33AXXX and FFFFUS33BXXX in the headers of the compared blocks will return true as comparison result. Defaults to false.- Since:
- 9.1.3
-
isIgnoreLocationFlag
public boolean isIgnoreLocationFlag()
- Since:
- 9.1.3
- See Also:
setIgnoreLocationFlag(boolean)
-
setIgnoreLocationFlag
public void setIgnoreLocationFlag(boolean ignoreLocationFlag)
If this is set to true, when comparing block 1 and block 2, the second digit of the location code (character at 8th position of the logical terminal addresses) will be ignored in the comparison. Meaning for example FFFFUS30AXXX and FFFFUS33AXXX in the headers of the compared blocks will return true as comparison result. Defaults to false.- Since:
- 9.1.3
-
isIgnoreBlock3
public boolean isIgnoreBlock3()
- Since:
- 9.1.6
- See Also:
setIgnoreBlock3(boolean)
-
setIgnoreBlock3
public void setIgnoreBlock3(boolean ignoreBlock3)
If this is set to true, the whole block 3 will be ignored in the headers comparison. Meaning a message with a with block 3 will match a message without it. Also messages with different fields or field values in their block 3 will also match. Defaults to false, meaning if block 3 is present in a message all fields in the block must match.- Since:
- 9.1.3
-
isIgnorePriority
public boolean isIgnorePriority()
- Since:
- 9.1.6
- See Also:
setIgnorePriority(boolean)
-
setIgnorePriority
public void setIgnorePriority(boolean ignorePriority)
If this is set to true, the priority flag in block 2 will be ignored int the comparison. Meaning a message with a normal priority will match a message with an urgent priority and so forth. Any combination of priorities in the messages will still produce a match. Defaults to false, meaning both message must have the same priority.- Since:
- 9.1.3
-
-