Class 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 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
    • Constructor Detail

      • SwiftMessageComparator

        public SwiftMessageComparator()
    • Method Detail

      • 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 return true and one null and the other one not null will return false
        Parameters:
        left - first block to compare
        right - 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 returns false

        Parameters:
        left - first block to compare
        right - 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 returns true, since there is nothing to compare.
        Parameters:
        left - block to compare
        right - 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
      • 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.
      • setIgnoreTrailer

        public void setIgnoreTrailer​(boolean ignoreTrailer)
        When this is set to true, the block 5 will be ignored in the comparison. Defaults to false.
      • 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
      • 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
      • 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
      • 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
      • 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