public class SwiftMessageComparator extends java.lang.Object implements java.util.Comparator<SwiftMessage>
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
ignoreBlock2OptionalFields |
protected boolean |
ignoreBlock3 |
protected boolean |
ignoreEolsInMultiline
Flag to enable different type of EOLs in multi-line values
|
protected boolean |
ignoreHeaderSession |
protected boolean |
ignoreLocationFlag |
protected boolean |
ignoreLT |
protected boolean |
ignorePriority |
protected boolean |
ignoreTrailer |
Constructor and Description |
---|
SwiftMessageComparator() |
Modifier and Type | Method and 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.
|
protected boolean ignoreEolsInMultiline
protected boolean ignoreHeaderSession
protected boolean ignoreTrailer
protected boolean ignoreBlock2OptionalFields
protected boolean ignoreLT
protected boolean ignoreLocationFlag
protected boolean ignoreBlock3
protected boolean ignorePriority
public int compare(SwiftMessage left, SwiftMessage right)
This implementation calls the specific comparator methods for blocks 1 and 2, and the generic tag list block comparator for other blocks
compare
in interface java.util.Comparator<SwiftMessage>
compareB1(SwiftBlock1, SwiftBlock1)
,
compareB2(SwiftBlock2, SwiftBlock2)
,
compareTagListBlock(SwiftTagListBlock, SwiftTagListBlock)
public boolean compareB2(SwiftBlock2 left, SwiftBlock2 right)
true
and one null and the other one not null will return false
left
- first block to compareright
- second block to comparepublic boolean compareTagListBlock(SwiftTagListBlock left, SwiftTagListBlock right)
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 returns false
left
- first block to compareright
- second block to comparepublic boolean compareB1(SwiftBlock1 left, SwiftBlock1 right)
true
, since there is nothing to compare.left
- block to compareright
- block to comparepublic boolean isIgnoreEolsInMultiline()
setIgnoreEolsInMultiline(boolean)
public void setIgnoreEolsInMultiline(boolean ignoreEolsInMultiline)
public java.util.List<java.lang.String> getTagnamesToIgnore()
public void setTagnamesToIgnore(java.util.List<java.lang.String> tagnamesToIgnore)
public boolean addTagnameToIgnore(java.lang.String tagName)
tagName
- tag to addpublic boolean isIgnoreHeaderSession()
setIgnoreHeaderSession(boolean)
public void setIgnoreHeaderSession(boolean ignoreHeaderSession)
public boolean isIgnoreTrailer()
setIgnoreTrailer(boolean)
public void setIgnoreTrailer(boolean ignoreTrailer)
public boolean isIgnoreBlock2OptionalFields()
setIgnoreBlock2OptionalFields(boolean)
public void setIgnoreBlock2OptionalFields(boolean ignoreBlock2OptionalFields)
public boolean isIgnoreLT()
setIgnoreLT(boolean)
public void setIgnoreLT(boolean ignoreLT)
public boolean isIgnoreLocationFlag()
setIgnoreLocationFlag(boolean)
public void setIgnoreLocationFlag(boolean ignoreLocationFlag)
public boolean isIgnoreBlock3()
setIgnoreBlock3(boolean)
public void setIgnoreBlock3(boolean ignoreBlock3)
public boolean isIgnorePriority()
setIgnorePriority(boolean)
public void setIgnorePriority(boolean ignorePriority)