Class Tag

  • All Implemented Interfaces:
    java.io.Serializable

    public class Tag
    extends java.lang.Object
    implements java.io.Serializable
    Representation of an MT field in a message as a plain key/value tuple.

    The "Tag" naming is used in the SWIFT standard to refer the fields identifiers composed by a number and an optional letter option, for example 32A. This class is used to model the complete field structure including both the field name ("Tag") and the field value.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String name
      Name of the tag, usually a number that may be followed by a letter.
      protected UnparsedTextList unparsedTexts
      List of unparsed texts.
      protected java.lang.String value
      Value of the corresponding tag.
    • Constructor Summary

      Constructors 
      Constructor Description
      Tag()
      Default constructor.
      Tag​(Tag tag)
      Copy constructor.
      Tag​(UnparsedTextList unparsedText)
      Constructor for an unparsed text list
      Tag​(java.lang.String inner)
      Create a tag from the value in inner.
      Tag​(java.lang.String inner, UnparsedTextList unparsedText)
      Constructor for tag encoded value and an unparsed text list
      Tag​(java.lang.String tagname, java.lang.String value)
      Create a tag with the given tagname and value
      Tag​(java.lang.String tagname, java.lang.String value, UnparsedTextList unparsedText)
      Constructor for tag name and value and an unparsed text list
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Field asField()
      Creates a Field instance for the given Tag object.
      boolean contains​(java.lang.String searchStr)
      equivalent to StringUtils.contains(tag.getValue(), searchStr)
      boolean contains​(java.lang.String... values)
      Tell if this tag value contains any of the given values.
      boolean equals​(java.lang.Object o)  
      boolean equalsIgnoreCR​(Tag other)
      Similar to equals(Object) but ignoring carriage returns characters in tag values.
      java.lang.String getLetterOption()
      Iterate the current tagname and return only letters as told by Character.isLetter(char)
      java.lang.String getName()
      Get the name of this tag
      int getNameAsInt()
      Attempt to parse the tag name as an integer.
      java.lang.Integer getNumber()
      Iterate the current tagname and return only number as told by Character.isDigit(char)
      UnparsedTextList getUnparsedTexts()
      returns the unparsed text list
      java.lang.Integer getUnparsedTextsSize()
      returns the size of the unparsed text list
      java.lang.String getValue()
      Get the value of the tag.
      Notice that in some cases the value can be null, for example the value of the "DLM" tag in this block:
      {5:{CHK:F9351591947F}{SYS:1610010606VNDZBET2AXXX0019000381}{DLM:}}
      int hashCode()  
      boolean isNumber​(int n)
      Tells if this tagname is a given number, so the integer 58 will match 58A and 58D.
      void setName​(java.lang.String name)
      Set the tag name
      void setNameValue​(java.lang.String name, java.lang.String value)
      Shorthand equivalent to calling first setName(String) and then setValue(String)
      void setUnparsedTexts​(UnparsedTextList texts)
      sets the list of unparsed texts
      void setValue​(java.lang.String value)
      Sets the value of this tag.
      boolean startsWith​(java.lang.String prefix)
      equivalent to StringUtils.startsWith(tag.getValue(), prefix)
      java.lang.String toString()  
      void unparsedTextAddText​(SwiftMessage message)
      adds a new unparsed text from a message
      void unparsedTextAddText​(java.lang.String text)
      adds a new unparsed text
      SwiftMessage unparsedTextGetAsMessage​(java.lang.Integer index)
      get an unparsed text as a parsed swift message
      java.lang.String unparsedTextGetText​(java.lang.Integer index)
      get an unparsed text
      java.lang.Boolean unparsedTextIsMessage​(java.lang.Integer index)
      decides if a specific text (by index) is likely a SWIFT FIN message.
      protected void unparsedTextVerify()
      verifies that the unparsed text list exists
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • name

        protected java.lang.String name
        Name of the tag, usually a number that may be followed by a letter.
      • value

        protected java.lang.String value
        Value of the corresponding tag.
      • unparsedTexts

        protected UnparsedTextList unparsedTexts
        List of unparsed texts. For performance reasons, this will be null until really needed.
    • Constructor Detail

      • Tag

        public Tag()
        Default constructor.
      • Tag

        public Tag​(Tag tag)
        Copy constructor.
        Parameters:
        tag - source tag to copy content from
        Since:
        9.2.11
      • Tag

        public Tag​(java.lang.String inner)
        Create a tag from the value in inner.

        If inner contains one ':' character, the string before is set as the tag name and the rest as the value. If inner contains more than one ':' characters, then the first value is used as previously described. If no ':' character is found the whole string is set as the tag value and the tag name is kept null (useful for bloc data)

        Maps:

         "" -> name=null, value=null
         "foo" -> name=null, value=foo
         ":foo" -> name=null, value=foo
         "foo:" -> name=foo, value=null
         "foo:bar" -> name=foo, value=bar
         
        Parameters:
        inner - the string to build the tag
        Throws:
        java.lang.IllegalArgumentException - if inner is null
      • Tag

        public Tag​(java.lang.String tagname,
                   java.lang.String value)
        Create a tag with the given tagname and value
        Parameters:
        tagname - name of this tag
        value - the value of this tag
        Throws:
        java.lang.IllegalArgumentException - if parameter tagname is null
      • Tag

        public Tag​(UnparsedTextList unparsedText)
        Constructor for an unparsed text list
        Parameters:
        unparsedText - the list of unparsed texts
        See Also:
        Tag()
      • Tag

        public Tag​(java.lang.String inner,
                   UnparsedTextList unparsedText)
        Constructor for tag encoded value and an unparsed text list
        Parameters:
        inner - the string to build the tag
        unparsedText - the list of unparsed texts
        Throws:
        java.lang.IllegalArgumentException - if parameter inner is null
        See Also:
        Tag(String)
      • Tag

        public Tag​(java.lang.String tagname,
                   java.lang.String value,
                   UnparsedTextList unparsedText)
        Constructor for tag name and value and an unparsed text list
        Parameters:
        tagname - name of this tag
        value - the value of this tag
        unparsedText - the list of unparsed texts
        Throws:
        java.lang.IllegalArgumentException - if parameter tagname or value are null
        See Also:
        Tag(String, String)
    • Method Detail

      • getName

        public java.lang.String getName()
        Get the name of this tag
        Returns:
        a string with the current tag name
      • setName

        public void setName​(java.lang.String name)
        Set the tag name
        Parameters:
        name - the name of the tag to be set
        Throws:
        java.lang.IllegalArgumentException - if parameter name is null
      • getValue

        public java.lang.String getValue()
        Get the value of the tag.
        Notice that in some cases the value can be null, for example the value of the "DLM" tag in this block:
        {5:{CHK:F9351591947F}{SYS:1610010606VNDZBET2AXXX0019000381}{DLM:}}
        Returns:
        a string with the value of the tag or null if the value was not set
      • setValue

        public void setValue​(java.lang.String value)
        Sets the value of this tag.
        Parameters:
        value - the value for the tag, may be null
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • unparsedTextVerify

        protected void unparsedTextVerify()
        verifies that the unparsed text list exists
      • getUnparsedTexts

        public UnparsedTextList getUnparsedTexts()
        returns the unparsed text list
        Returns:
        the unparsed text attached to this tag object
      • setUnparsedTexts

        public void setUnparsedTexts​(UnparsedTextList texts)
        sets the list of unparsed texts
        Parameters:
        texts - the new list of unparsed texts (may be null)
      • getUnparsedTextsSize

        public java.lang.Integer getUnparsedTextsSize()
        returns the size of the unparsed text list
        Returns:
        the count of unparsed texts attached to this tag object
      • unparsedTextIsMessage

        public java.lang.Boolean unparsedTextIsMessage​(java.lang.Integer index)
        decides if a specific text (by index) is likely a SWIFT FIN message. Exceptions are inherited from base implementation methods.
        Parameters:
        index - the unparsed text number
        Returns:
        true if the unparsed text at position index is a full SWIFT message
        Throws:
        java.lang.IllegalArgumentException - if parameter index is null
        java.lang.IndexOutOfBoundsException - if parameter index is out of bounds
      • unparsedTextGetText

        public java.lang.String unparsedTextGetText​(java.lang.Integer index)
        get an unparsed text
        Parameters:
        index - the unparsed text number
        Returns:
        the requested text
        Throws:
        java.lang.IllegalArgumentException - if parameter index is null
        java.lang.IndexOutOfBoundsException - if parameter index is out of bounds
      • unparsedTextGetAsMessage

        public SwiftMessage unparsedTextGetAsMessage​(java.lang.Integer index)
        get an unparsed text as a parsed swift message
        Parameters:
        index - the unparsed text number
        Returns:
        the unparsed text at position index parsed into a SwiftMessage object
        Throws:
        java.lang.IllegalArgumentException - if parameter index is null
      • unparsedTextAddText

        public void unparsedTextAddText​(java.lang.String text)
        adds a new unparsed text
        Parameters:
        text - the unparsed text to append
        Throws:
        java.lang.IllegalArgumentException - if parameter text is null
      • unparsedTextAddText

        public void unparsedTextAddText​(SwiftMessage message)
        adds a new unparsed text from a message
        Parameters:
        message - the message to be appended
        Throws:
        java.lang.IllegalArgumentException - if parameter message is null
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equalsIgnoreCR

        public boolean equalsIgnoreCR​(Tag other)
        Similar to equals(Object) but ignoring carriage returns characters in tag values. Meaning CRLF in any of the tags will match both CRLF in the other tag and just LF in the other tag
        Parameters:
        other - another tag to compare
        Returns:
        true if both tags are equals despite the CR
        Since:
        7.9.3
      • getNameAsInt

        public int getNameAsInt()
        Attempt to parse the tag name as an integer. Note that for 15A this method will return -1
        Returns:
        the resulting value of parsing the tagname as an integer or -1 if an error occurs
      • isNumber

        public boolean isNumber​(int n)
        Tells if this tagname is a given number, so the integer 58 will match 58A and 58D.
        Parameters:
        n - the number that this tagname will be compared to
        Returns:
        true if this tagname starts with the given number or false in any other case
      • getNumber

        public java.lang.Integer getNumber()
        Iterate the current tagname and return only number as told by Character.isDigit(char)
        Returns:
        an integer containing the numeric of the tagname or null if no digits are found
        Since:
        6.2
      • getLetterOption

        public java.lang.String getLetterOption()
        Iterate the current tagname and return only letters as told by Character.isLetter(char)
        Returns:
        a string containing only letter characters of the tagname or null if no letters are found
      • contains

        public boolean contains​(java.lang.String... values)
        Tell if this tag value contains any of the given values. This method is case sensitive. It handles null values.
        Parameters:
        values - variable list of values to test
        Returns:
        true if the value of this tag is one of the given values. returns false in any other case, including a null or empty list of values
      • setNameValue

        public void setNameValue​(java.lang.String name,
                                 java.lang.String value)
        Shorthand equivalent to calling first setName(String) and then setValue(String)
        Parameters:
        name - the tagname
        value - the tagvalue
      • startsWith

        public boolean startsWith​(java.lang.String prefix)
        equivalent to StringUtils.startsWith(tag.getValue(), prefix)
      • contains

        public boolean contains​(java.lang.String searchStr)
        equivalent to StringUtils.contains(tag.getValue(), searchStr)
      • asField

        public Field asField()
        Creates a Field instance for the given Tag object.
        Returns:
        a specific field object (example: Field32A) or null if exceptions occur during object creation.
        See Also:
        Field.getField(Tag)