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 fiels, 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 |
ignoreEolsInMultiline
Flag to enable different type of EOLs in multi-line values
|
protected boolean |
ignoreHeaderSession |
protected boolean |
ignoreTrailer |
Constructor and Description |
---|
SwiftMessageComparator() |
Modifier and Type | Method and Description |
---|---|
boolean |
addTagnameToIgnore(java.lang.String o) |
int |
compare(SwiftMessage m1,
SwiftMessage m2)
Compare the two given messages.
|
boolean |
compareB1(SwiftBlock1 b1,
SwiftBlock1 b2)
Return true if blocks are equals in all values except session and sequence number and false in any other case (including one of them being null)
If both parameters are null it returns
true , since there is nothing to compare. |
boolean |
compareB2(SwiftBlock2 o1,
SwiftBlock2 o2)
Compares all elements of block2.
|
boolean |
compareTagListBlock(SwiftTagListBlock o1,
SwiftTagListBlock o2)
Compare all tags in taglist from both given blocks.
|
java.util.List<java.lang.String> |
getTagnamesToIgnore() |
boolean |
isIgnoreEolsInMultiline() |
boolean |
isIgnoreHeaderSession() |
boolean |
isIgnoreTrailer() |
void |
setIgnoreEolsInMultiline(boolean ignoreEolsInMultiline) |
void |
setIgnoreHeaderSession(boolean ignoreHeaderSession) |
void |
setIgnoreTrailer(boolean ignoreTrailer) |
void |
setTagnamesToIgnore(java.util.List<java.lang.String> tagnamesToIgnore) |
protected boolean ignoreEolsInMultiline
protected boolean ignoreHeaderSession
protected boolean ignoreTrailer
public int compare(SwiftMessage m1, SwiftMessage m2)
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 o1, SwiftBlock2 o2)
true
and one null and the other one not null will return false
o1
- o2
- true
if both blocks are null or equal (from ACK point of view) or false in any other casepublic boolean compareTagListBlock(SwiftTagListBlock o1, SwiftTagListBlock o2)
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
o1
- first block to compareo2
- second block to comparepublic boolean compareB1(SwiftBlock1 b1, SwiftBlock1 b2)
true
, since there is nothing to compare.b1
- block to compareb2
- block to comparepublic boolean isIgnoreEolsInMultiline()
public void setIgnoreEolsInMultiline(boolean ignoreEolsInMultiline)
ignoreEolsInMultiline
- public java.util.List<java.lang.String> getTagnamesToIgnore()
public void setTagnamesToIgnore(java.util.List<java.lang.String> tagnamesToIgnore)
tagnamesToIgnore
- public boolean addTagnameToIgnore(java.lang.String o)
o
- tag to addpublic boolean isIgnoreHeaderSession()
public void setIgnoreHeaderSession(boolean ignoreHeaderSession)
public boolean isIgnoreTrailer()
public void setIgnoreTrailer(boolean ignoreTrailer)