Class Narrative
- java.lang.Object
-
- com.prowidesoftware.swift.model.field.Narrative
-
public class Narrative extends java.lang.Object
Models the value of fields containing narrative content. The content is normally text wrapped in lines but they also support the narrative to be structured with codewords.When the structured option is used, different line formats are supported depending on the actual field. In most of the fields the only element in the structured format is the actual text. However some fields can include currency and amount (for example: 73A, 71D, 71B, 73), country codes (for example 77B) or the narrative partitioned as a main narrative and a supplement (for example: 75, 76).
Supported line formats are:
Format 1 Line 1: /8a/[additional information] (Code)(Narrative) Lines 2-n: /8a/[additional information] (Code)(Narrative) [//continuation of additional information] (Narrative) Format 2 Line 1: /8c/[additional information] Code)(Narrative) Lines 2-n: /8c/[additional information] (Code)(Narrative) [//continuation of additional information] (Narrative) Format 3 Line 1: /8c/[3!a13d][additional information] (Code)(Currency)(Amount)(Narrative) Lines 2-6: /8c/[3!a13d][additional information] (Code)(Currency)(Amount)(Narrative) [//continuation of additional information] (Narrative) Format 4 Line 1: /8c/[additional information] (Code)(Narrative) Lines 2-3: [//continuation of additional information] (Narrative) Variant for cat 1 with country Line 1: /8c/2!a[//additional information] (Code)(Country)(Narrative) Lines 2-3: [//continuation of additional information] (Narrative) Format 5 Line 1: /2n/[supplement 1][/supplement2] (Query Number)(Narrative 1)(Narrative 2) Lines 2-6 /2n/[supplement 1][/supplement2] [//continuation of supplementary information] Format 6 Line 1: /6c/[additional information] (Code)(Narrative) Lines 2-100: /6c/[additional information] (Code)(Narrative) [continuation of additional information] (Narrative) (cannot start with slash) Format 7 Code between slashes at the beginning of a line Format 8 Free format codes in slashes, not necessary on new lines
This model is intended to be a generic container for any type of structured or unstructure narrative, for any narrative container field. When a component (currency, amount, country or supplement) does not apply to a field, it will be simply set to null by the parser.
- Since:
- 9.0.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Narrative.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Narrative.Builder
builder(int lineLength)
This builder allows creating the structured narrative with ease, just adding chunks of texts with optional codewords and extra fields.java.util.Set<java.lang.String>
codewords()
If the field has structured narrative returns a set of all codewords usedint
countStructured(java.lang.String codeword)
Count the occurrences of a given codeword in the structured narrativejava.util.List<StructuredNarrative>
getStructured()
Gets the structured part of the narrative, meaning the segments composed by a codeword and a structured text.StructuredNarrative
getStructured(java.lang.String codeword)
Gets the first structured narrative found for the given codeword.java.lang.String
getUnstructured()
Gets this unstructured content as a single String, meaning if the text was wrapped in lines this method will return the joined lines without separator.java.lang.String
getUnstructured(java.lang.String delimiter)
Gets this unstructured content as a single String, meaning if the text was wrapped in lines this method will return the joined lines.java.util.List<java.lang.String>
getUnstructuredFragments()
Returns the part of the field value that is not structured in codewords.java.lang.String
getValue()
Serializes this narrative components into the single string value (SWIFT format) adding new lines as necessaryboolean
isEmpty()
boolean
valid()
Simple validation to check that either the structured or unstructured content is set For the structured field theStructuredNarrative.valid()
method is used.
-
-
-
Method Detail
-
builder
public static Narrative.Builder builder(int lineLength)
This builder allows creating the structured narrative with ease, just adding chunks of texts with optional codewords and extra fields. It is intended to simplify construction of different line formats.The implementation splits the text into fragments up to the given length, with word wrapping.
Since the builder will do the line wrapping, the parameter text should not contain line breaks. If your text is already formatted into lines use the
NarrativeContainer.appendLine(String)
method or the field plain component setter when you have the compete formatted value.- Parameters:
lineLength
- specific field max line length, used for text wrapping
-
getStructured
public java.util.List<StructuredNarrative> getStructured()
Gets the structured part of the narrative, meaning the segments composed by a codeword and a structured text. See examples below.For field:
:77J:THREE (3) COMMERCIAL INVOICES INSTEAD OF FIVE (5) PRESENTED
the result will be empty since all the narrative content is unstructured.For field:
:72:/BNF/first line of beneficiary //second line of beneficiary supplementary unstructured data
the result will be a single entry for the "BNF" content including the narrative texts "first line of beneficiary" and "second line of beneficiary". Notice the "supplementary unstructured data" will not be part of the returned structured data since it is not the continuation for "BNF" but some additional unstructured content in the last field line.- Returns:
- the structured content or empty if no structured content is present
-
getStructured
public StructuredNarrative getStructured(java.lang.String codeword)
Gets the first structured narrative found for the given codeword.Notice codewords can be repeated for some fields, this method returns the first instance found.
- Parameters:
codeword
- an instruction codeword for the field such as: BNF, HOLD, NAME, PREVINST, etc..- Returns:
- found structured content for the codeword or null if the field does not have structured narrative or the structured narrative is not set for the codeword.
-
countStructured
public int countStructured(java.lang.String codeword)
Count the occurrences of a given codeword in the structured narrative- Parameters:
codeword
- an instruction codeword for the field such as: OCMT, CHGS, etc..- Returns:
- number of structured content with the parameter codeword or zero if none is found
-
getUnstructuredFragments
public java.util.List<java.lang.String> getUnstructuredFragments()
Returns the part of the field value that is not structured in codewords. See examples below.For field:
:77J:THREE (3) COMMERCIAL INVOICES INSTEAD OF FIVE (5) PRESENTED
the result will be the complete field value since all the narrative content is unstructured.For field:
:72:/BNF/dbln-111- RED-1,123.456-78/10/ //05 redemption monies supplementary unstructured data
the result will be "supplementary unstructured data" since that line at the end is unstructured content, not the continuation of the structured narrative for BNF codeword.If the text is wrapped in lines the result list contains one element per line. To get the unstructured narrative text as a simple joined string use
getUnstructured(String)
- Returns:
- the fragments of the unstructured text or an empty list if there is no unstructured text
-
getUnstructured
public java.lang.String getUnstructured()
Gets this unstructured content as a single String, meaning if the text was wrapped in lines this method will return the joined lines without separator.- Returns:
- the narrative fragments joined as a single string or null if the narrative does not have any text
-
getUnstructured
public java.lang.String getUnstructured(java.lang.String delimiter)
Gets this unstructured content as a single String, meaning if the text was wrapped in lines this method will return the joined lines.- Parameters:
delimiter
- optional delimiter, could be for example null, empty, space or line break.- Returns:
- the narrative fragments joined as a single string or null if the narrative does not have any text
-
isEmpty
public boolean isEmpty()
- Returns:
- true if non of the narrative fields are set
-
valid
public boolean valid()
Simple validation to check that either the structured or unstructured content is set For the structured field theStructuredNarrative.valid()
method is used.
-
codewords
public java.util.Set<java.lang.String> codewords()
If the field has structured narrative returns a set of all codewords used- Returns:
- found codewords or empty if none is found (content is unstructured)
-
getValue
public java.lang.String getValue()
Serializes this narrative components into the single string value (SWIFT format) adding new lines as necessary
-
-