public class Narrative
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
Narrative.Builder |
Modifier and Type | Method and 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 used
|
int |
countStructured(java.lang.String codeword)
Count the occurrences of a given codeword in the structured narrative
|
java.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 necessary
|
boolean |
isEmpty() |
boolean |
valid()
Simple validation to check that either the structured or unstructured content is set
For the structured field the
StructuredNarrative.valid() method is used. |
public static Narrative.Builder builder(int lineLength)
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.
lineLength
- specific field max line length, used for text wrappingpublic java.util.List<StructuredNarrative> getStructured()
For field:
:77J:THREE (3) COMMERCIAL INVOICES INSTEAD OF FIVE (5) PRESENTEDthe 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 datathe 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.
public StructuredNarrative getStructured(java.lang.String codeword)
Notice codewords can be repeated for some fields, this method returns the first instance found.
codeword
- an instruction codeword for the field such as: BNF, HOLD, NAME, PREVINST, etc..public int countStructured(java.lang.String codeword)
codeword
- an instruction codeword for the field such as: OCMT, CHGS, etc..public java.util.List<java.lang.String> getUnstructuredFragments()
For field:
:77J:THREE (3) COMMERCIAL INVOICES INSTEAD OF FIVE (5) PRESENTEDthe 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 datathe 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)
public java.lang.String getUnstructured()
public java.lang.String getUnstructured(java.lang.String delimiter)
delimiter
- optional delimiter, could be for example null, empty, space or line break.public boolean isEmpty()
public boolean valid()
StructuredNarrative.valid()
method is used.public java.util.Set<java.lang.String> codewords()
public java.lang.String getValue()