Class Field
- java.lang.Object
-
- com.prowidesoftware.swift.model.field.Field
-
- All Implemented Interfaces:
JsonSerializable
,PatternContainer
- Direct Known Subclasses:
Field101
,Field102
,Field103
,Field104
,Field105
,Field106
,Field107
,Field108
,Field109
,Field110
,Field111
,Field113
,Field114
,Field115
,Field116
,Field117
,Field118
,Field119
,Field11A
,Field11R
,Field11S
,Field11T
,Field12
,Field120
,Field121
,Field122
,Field123
,Field124
,Field125
,Field126
,Field127
,Field128
,Field129
,Field12A
,Field12B
,Field12C
,Field12D
,Field12E
,Field12F
,Field12G
,Field12H
,Field12K
,Field12L
,Field12R
,Field12S
,Field130
,Field132
,Field133
,Field134
,Field135
,Field136
,Field137
,Field13A
,Field13B
,Field13C
,Field13D
,Field13E
,Field13J
,Field13K
,Field140
,Field141
,Field142
,Field143
,Field144
,Field14A
,Field14B
,Field14C
,Field14D
,Field14E
,Field14F
,Field14G
,Field14J
,Field14S
,Field151
,Field152
,Field153
,Field15A
,Field15B
,Field15C
,Field15D
,Field15E
,Field15F
,Field15G
,Field15H
,Field15I
,Field15J
,Field15K
,Field15L
,Field15M
,Field15N
,Field15O
,Field15P
,Field165
,Field16A
,Field16C
,Field16R
,Field16S
,Field171
,Field172
,Field173
,Field174
,Field175
,Field177
,Field179
,Field17A
,Field17B
,Field17E
,Field17F
,Field17G
,Field17H
,Field17I
,Field17L
,Field17M
,Field17N
,Field17O
,Field17P
,Field17Q
,Field17R
,Field17S
,Field17T
,Field17U
,Field17V
,Field17W
,Field17X
,Field17Y
,Field17Z
,Field18A
,Field18B
,Field18C
,Field18D
,Field19
,Field199
,Field19A
,Field19B
,Field19C
,Field19Y
,Field19Z
,Field20
,Field202
,Field203
,Field204
,Field206
,Field208
,Field209
,Field20C
,Field20D
,Field20E
,Field20U
,Field21
,Field21A
,Field21B
,Field21C
,Field21D
,Field21E
,Field21F
,Field21G
,Field21H
,Field21N
,Field21P
,Field21R
,Field21S
,Field21T
,Field22
,Field22A
,Field22B
,Field22C
,Field22D
,Field22E
,Field22F
,Field22G
,Field22H
,Field22J
,Field22K
,Field22L
,Field22M
,Field22N
,Field22P
,Field22Q
,Field22R
,Field22S
,Field22T
,Field22U
,Field22V
,Field22W
,Field22X
,Field22Y
,Field22Z
,Field23
,Field23A
,Field23B
,Field23C
,Field23D
,Field23E
,Field23F
,Field23G
,Field23H
,Field23R
,Field23S
,Field23X
,Field242
,Field243
,Field24B
,Field24D
,Field24E
,Field24G
,Field25
,Field251
,Field252
,Field253
,Field254
,Field255
,Field256
,Field257
,Field258
,Field259
,Field25A
,Field25D
,Field25F
,Field25G
,Field25P
,Field260
,Field263
,Field264
,Field26A
,Field26B
,Field26C
,Field26D
,Field26E
,Field26F
,Field26H
,Field26K
,Field26T
,Field27
,Field270
,Field271
,Field272
,Field27A
,Field28
,Field280
,Field281
,Field28C
,Field28D
,Field28E
,Field29B
,Field29D
,Field29E
,Field29F
,Field29H
,Field29J
,Field29K
,Field29L
,Field29M
,Field29N
,Field29P
,Field29S
,Field29U
,Field30
,Field301
,Field302
,Field303
,Field304
,Field305
,Field307
,Field30F
,Field30G
,Field30H
,Field30J
,Field30M
,Field30N
,Field30P
,Field30Q
,Field30S
,Field30T
,Field30U
,Field30V
,Field30X
,Field30Y
,Field30Z
,Field311
,Field312
,Field313
,Field31C
,Field31D
,Field31E
,Field31F
,Field31G
,Field31J
,Field31K
,Field31L
,Field31M
,Field31P
,Field31R
,Field31S
,Field31T
,Field31X
,Field329
,Field32A
,Field32B
,Field32C
,Field32D
,Field32E
,Field32F
,Field32G
,Field32H
,Field32K
,Field32M
,Field32Q
,Field32R
,Field32U
,Field330
,Field331
,Field332
,Field333
,Field334
,Field335
,Field336
,Field337
,Field338
,Field339
,Field33A
,Field33B
,Field33C
,Field33D
,Field33E
,Field33F
,Field33G
,Field33H
,Field33J
,Field33K
,Field33S
,Field33T
,Field340
,Field341
,Field342
,Field343
,Field344
,Field345
,Field346
,Field347
,Field348
,Field349
,Field34A
,Field34B
,Field34C
,Field34D
,Field34E
,Field34F
,Field34J
,Field34K
,Field34L
,Field34M
,Field34P
,Field34R
,Field34S
,Field34T
,Field34U
,Field34V
,Field34W
,Field34X
,Field35A
,Field35B
,Field35C
,Field35D
,Field35E
,Field35G
,Field35H
,Field35L
,Field35N
,Field35S
,Field35U
,Field36
,Field36B
,Field36C
,Field36D
,Field36E
,Field37A
,Field37B
,Field37C
,Field37D
,Field37E
,Field37F
,Field37G
,Field37H
,Field37J
,Field37K
,Field37L
,Field37M
,Field37P
,Field37R
,Field37U
,Field37V
,Field38A
,Field38D
,Field38E
,Field38G
,Field38H
,Field38J
,Field39A
,Field39B
,Field39C
,Field39D
,Field39E
,Field39M
,Field401
,Field405
,Field40A
,Field40B
,Field40C
,Field40D
,Field40E
,Field40F
,Field41A
,Field41D
,Field41F
,Field41G
,Field421
,Field422
,Field423
,Field424
,Field425
,Field42C
,Field42M
,Field42P
,Field431
,Field432
,Field433
,Field434
,Field43P
,Field43T
,Field443
,Field44A
,Field44B
,Field44C
,Field44D
,Field44E
,Field44F
,Field44H
,Field451
,Field45A
,Field45C
,Field45D
,Field45L
,Field461
,Field46A
,Field47A
,Field47E
,Field48
,Field48B
,Field48D
,Field49
,Field49A
,Field49D
,Field49F
,Field49G
,Field49H
,Field49J
,Field49K
,Field49L
,Field49Z
,Field50
,Field503
,Field50A
,Field50B
,Field50C
,Field50F
,Field51
,Field533
,Field59
,Field59A
,Field59F
,Field60F
,Field60M
,Field61
,Field619
,Field62F
,Field62M
,Field64
,Field65
,Field68A
,Field69A
,Field69B
,Field69C
,Field69D
,Field69E
,Field69F
,Field69J
,Field70C
,Field70D
,Field70E
,Field70F
,Field70G
,Field70H
,Field71A
,Field71C
,Field71F
,Field71G
,Field71N
,Field73R
,Field73S
,Field77C
,Field77E
,Field77F
,Field77H
,Field77L
,Field77T
,Field77U
,Field78
,Field78B
,Field79
,Field79Z
,Field80C
,Field86
,Field90A
,Field90B
,Field90C
,Field90D
,Field90E
,Field90F
,Field90J
,Field90K
,Field90L
,Field92A
,Field92B
,Field92C
,Field92D
,Field92F
,Field92H
,Field92J
,Field92K
,Field92L
,Field92M
,Field92N
,Field92P
,Field92R
,Field93A
,Field93B
,Field93C
,Field93D
,Field93E
,Field93F
,Field94A
,Field94B
,Field94C
,Field94D
,Field94E
,Field94F
,Field94G
,Field94H
,Field94L
,Field95C
,Field95L
,Field95V
,Field97A
,Field97B
,Field97C
,Field97D
,Field97E
,Field98A
,Field98B
,Field98C
,Field98D
,Field98E
,Field98F
,Field98G
,Field98H
,Field98J
,Field98K
,Field999
,Field99A
,Field99B
,Field99C
,OptionAPartyField
,OptionBPartyField
,OptionCPartyField
,OptionDPartyField
,OptionGPartyField
,OptionHPartyField
,OptionJPartyField
,OptionKPartyField
,OptionLPartyField
,OptionPPartyField
,OptionQPartyField
,OptionRPartyField
,OptionSPartyField
,OptionUPartyField
,StructuredNarrativeField
public abstract class Field extends java.lang.Object implements PatternContainer, JsonSerializable
Base class implemented by classes that provide general access to field components.- Since:
- 6.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.String>
components
Zero based list of field components in String format.
For example: for field content ":FOO//EUR1234 will be components[0]=FOO, components[1]=EUR and components[1]=1234protected java.util.Map<java.lang.String,java.lang.Integer>
labelMap
-
Constructor Summary
Constructors Modifier Constructor Description protected
Field(int components)
Creates a field with the list of components initialized to the given number of components.protected
Field(Field source)
Copy constructor.
Initializes the components list with a deep copy of the source components list.protected
Field(java.lang.String value)
Creates a new field and initializes its components with content from the parameter value.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
append(java.lang.StringBuilder result, int component)
Appends a not null field component to the builder.protected void
appendInLines(java.lang.StringBuilder sb, int componentStart, int componentEnd)
Append each component between componentStart and componentEnd in a new lines, empty components are ignoredprotected void
appendInLines(java.lang.StringBuilder sb, java.lang.String... lines)
Append each lines in a new lines, empty lines are ignoredTag
asTag()
Get the generic tag object of this field.int
componentNameToNumber(java.lang.String componentName)
Get the component number based on the component nameabstract java.lang.String
componentsPattern()
Deprecated.UsetypesPattern()
insteadabstract int
componentsSize()
Returns the defined amount of components.
This is not the amount of components present in the field instance, but the total amount of components that this field accepts as defined.boolean
equals(java.lang.Object obj)
Implementation of equals using EqualsBuilder from commons-langjava.lang.String
findComponentStartingWith(java.lang.String prefix)
Returns the first component starting with the given prefix value or null if not found.protected static java.lang.String
format(java.util.Calendar d)
protected static java.lang.String
formatAccount(java.lang.String a)
A formatted account with a fixed format nnnn-nnnnn-nnn-nprotected static java.lang.String
formatNumber(java.lang.Object aValue)
Format the given object as a money number without currency information in formatstatic Field
fromJson(java.lang.String json)
Creates a specific field instance from its JSON representation.static java.math.BigDecimal
getAsBigDecimal(java.lang.Number number)
Gets a BigDecimal from a generic Number argumentjava.lang.String
getComponent(int number)
Gets a specific component from the components list.java.lang.String
getComponent(java.lang.String componentName)
Gets a specific component (subfield) value given its name.java.lang.Object
getComponentAs(int component, java.lang.Class c)
Get the given component as the given object type.java.lang.Object
getComponentAs(java.lang.String componentName, java.lang.Class c)
Get the given component as the given object type.java.lang.Number
getComponentAsNumber(int component)
Get the given component as a number object This method internall y callsgetComponentAs(int, Class)
, and casts the resultjava.lang.Object
getComponentAsNumber(java.lang.String componentName)
Get the given component as a number object This method internal y callsgetComponentAsNumber(int)
, and casts the resultjava.lang.String
getComponentLabel(int number)
Returns english label for the component.java.lang.String
getComponentLabel(java.lang.String componentName)
Returns english label for the component.abstract java.util.List<java.lang.String>
getComponentLabels()
Returns english label for components.protected abstract java.util.Map<java.lang.Integer,java.lang.String>
getComponentMap()
Returns a mapping between component numbers and their label in camel case format.java.util.List<java.lang.String>
getComponents()
static Field
getField(Tag t)
Creates a Field instance for the given Tag object, using reflection.static Field
getField(java.lang.String name, java.lang.String value)
Creates a Field instance for the given it's name and and optional value, using reflection.static java.lang.String
getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence)
Same asgetLabel(String, String, String, Locale)
using default localestatic java.lang.String
getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
Returns the field business description name, using resource bundle from pw_swift_labels property files.static java.lang.String
getLabelComponents(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
Similar togetLabelComponents(String, String, String, Locale)
but returning the components property in bundleprotected abstract java.util.Map<java.lang.String,java.lang.Integer>
getLabelMap()
Returns a mapping between component labels and the internal component number.protected java.lang.String
getLine(Field cp, java.lang.Integer start, java.lang.Integer end, int offset)
Base implementation for subclasses getLine API.abstract java.lang.String
getName()
Returns the field's name composed by the field number and the letter option (if any)abstract java.lang.String
getValue()
Serializes the components into the a plain string value in SWIFT format.java.lang.String
getValueByCodeword(java.lang.String codeword)
Finds the first component starting with the given codeword between slashes, and returns the component subvalue.java.lang.String
getValueDisplay()
abstract java.lang.String
getValueDisplay(int component, java.util.Locale locale)
Returns a localized suitable for showing to humans string of a field component.java.lang.String
getValueDisplay(java.lang.String componentName, java.util.Locale locale)
Returns a localized suitable for showing to humans string of a field component.java.lang.String
getValueDisplay(java.util.Locale locale)
Get a localized, suitable for showing to humans string of the field values.int
hashCode()
Implementation of hashCode using HashCodeBuilder from commons-langprotected void
init(int components)
Initialize the list of components to the indicated size and sets all values to nullboolean
is(int componentNumber, java.lang.String compare)
Compares a specific component with the parameter valueboolean
is(java.lang.String compare)
Compares this field component 1 with the parameter value
Same asis(1, compare)
If the field has only one component this is the same as comparing against field valueboolean
is(java.lang.String... values)
Compares this field component 1 with the parameter values.boolean
is(java.lang.String compare1, java.lang.String compare2)
Compares this field components 1 and 2 with the parameter values.boolean
isEmpty()
Returns true if all field's components are blank or nullabstract boolean
isGeneric()
boolean
isLetterOption(char c)
Tell if this field is of a given letter option.boolean
isNameAnyOf(java.lang.String... names)
Compares the this fields's name with a list of names to checkabstract boolean
isOptional(int component)
java.lang.String
joinComponents()
Returns a string with all field's components joined.java.lang.String
joinComponents(boolean skipLast)
Returns a string with all field's components joined.java.lang.String
joinComponents(int start)
Returns a string with all field's components joinedjava.lang.String
joinComponents(int start, boolean skipLast)
Returns a string with joined components values.java.lang.Character
letterOption()
Return the letter option of this field as given by it classname or null if this field has no letter optionprotected java.util.Locale
notNull(java.util.Locale locale)
Ensures a not-null locale parameter.abstract void
parse(java.lang.String value)
Parses the parameter value into the internal components structure.void
setComponent(int number, java.lang.String value)
Inserts a component String value into the list of components, using the component number to position the value into the List.void
setComponent(java.lang.String componentName, java.lang.String value)
Inserts a component String value into the list of components, using the component name to position the value into the List.void
setComponents(java.util.List<java.lang.String> components)
java.lang.String
toJson()
Get a json representation of this message with expanded fields content.java.lang.String
toString()
Implementation of toString using ToStringBuilder from commons-langabstract java.lang.String
typesPattern()
Returns the field component types patternabstract java.lang.String
validatorPattern()
Returns the field's validator patternstatic boolean
validName(java.lang.String name)
Returns true if the field name is valid.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.prowidesoftware.swift.model.field.PatternContainer
parserPattern
-
-
-
-
Field Detail
-
components
protected java.util.List<java.lang.String> components
Zero based list of field components in String format.
For example: for field content ":FOO//EUR1234 will be components[0]=FOO, components[1]=EUR and components[1]=1234
-
labelMap
protected java.util.Map<java.lang.String,java.lang.Integer> labelMap
-
-
Constructor Detail
-
Field
protected Field(int components)
Creates a field with the list of components initialized to the given number of components.- Parameters:
components
- the number of components to initialize- See Also:
init(int)
-
Field
protected Field(java.lang.String value)
Creates a new field and initializes its components with content from the parameter value. The value is parsed withparse(String)
- Parameters:
value
- complete field value including separators and CRLF
-
Field
protected Field(Field source)
Copy constructor.
Initializes the components list with a deep copy of the source components list.- Parameters:
source
- a field instance to copy- Since:
- 7.7
-
-
Method Detail
-
formatNumber
protected static java.lang.String formatNumber(java.lang.Object aValue)
Format the given object as a money number without currency information in format- Returns:
- the formatted amount as String
-
format
protected static java.lang.String format(java.util.Calendar d)
- Parameters:
d
- Date object to format- Returns:
- the formatted date as dd/MM/yyyy or empty if exception occurs during formatting
-
formatAccount
protected static java.lang.String formatAccount(java.lang.String a)
A formatted account with a fixed format nnnn-nnnnn-nnn-n- Parameters:
a
- string with an account number or null- Returns:
- the formatted account or an empty String if param is null
-
getAsBigDecimal
public static java.math.BigDecimal getAsBigDecimal(java.lang.Number number)
Gets a BigDecimal from a generic Number argument- Returns:
- BigDecimal value of number parameter
-
getField
public static Field getField(Tag t)
Creates a Field instance for the given Tag object, using reflection. The created object is populated with parsed components data from the Tag.- Parameters:
t
- a tag with proper name and value content- Returns:
- a specific field object, ex: Field32A. Or null if exceptions occur during object creation.
-
getField
public static Field getField(java.lang.String name, java.lang.String value)
Creates a Field instance for the given it's name and and optional value, using reflection.- Parameters:
name
- a proper field name, ex: 32A, 22F, 20value
- an optional field value or null to create the field with no initial content- Returns:
- a specific field object (example: Field32A) or null if exceptions occur during object creation.
- Since:
- 7.8
-
getLabel
public static java.lang.String getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence)
Same asgetLabel(String, String, String, Locale)
using default locale- Since:
- 7.8
-
getLabel
public static java.lang.String getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
Returns the field business description name, using resource bundle from pw_swift_labels property files. Field names may be generic for all usages, or may differ for particular letter option, message type or even sequence of a message type. The property supports all this kind of definitions with generic labels and specific ones. The following example illustrate the precedence of bundle keys that are checked for field 50:
- 50K[103][B]
- 50a[103][B]
- 50K[103]
- 50a[103]
- 50K
- 50a
- 50
- Parameters:
fieldName
- field name of the field to retrieve its label, if the combination of number and letter option is provided then a specific label is returned; is the letter option is omitted then a more generic label is returned.mt
- optional indication of message type or null.sequence
- optional indication of sequence or null if does not apply for the specific MT and field.locale
- the locale for which a resource bundle is desired- Returns:
- a resource bundle based label for the given locale or the tag name, or the resource key if not found
-
getLabelComponents
public static java.lang.String getLabelComponents(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
Similar togetLabelComponents(String, String, String, Locale)
but returning the components property in bundle- Since:
- 7.8.4
-
validName
public static boolean validName(java.lang.String name)
Returns true if the field name is valid. Valid field names are for example: 20, 20C, 108- Parameters:
name
- a field name to validate- Returns:
- true if valid, false otherwise
- Since:
- 7.8
-
fromJson
public static Field fromJson(java.lang.String json)
Creates a specific field instance from its JSON representation.The implementation reads the "name" property in the JSON data, then calls the fromJson method in the specific Field subclass
- Returns:
- a specific field, for example Field32A, or null if the JSON data is not well-formed or contains an unrecognized field name
- See Also:
toJson()
-
init
protected void init(int components)
Initialize the list of components to the indicated size and sets all values to null- Parameters:
components
- the number of components to initialize- Since:
- 7.8
-
parse
public abstract void parse(java.lang.String value)
Parses the parameter value into the internal components structure. Used to update all components from a full new value, as an alternative to setting individual components. Previous components value is overwritten.
Implemented by subclasses with logic for each specific field structure.- Parameters:
value
- complete field value including separators and CRLF- Since:
- 7.8
-
toString
public java.lang.String toString()
Implementation of toString using ToStringBuilder from commons-lang- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Implementation of equals using EqualsBuilder from commons-lang- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Implementation of hashCode using HashCodeBuilder from commons-lang- Overrides:
hashCode
in classjava.lang.Object
-
appendInLines
protected void appendInLines(java.lang.StringBuilder sb, java.lang.String... lines)
Append each lines in a new lines, empty lines are ignored- Parameters:
sb
- must not be null, target bufferlines
- may be null or empty, nothing is done in this case
-
appendInLines
protected void appendInLines(java.lang.StringBuilder sb, int componentStart, int componentEnd)
Append each component between componentStart and componentEnd in a new lines, empty components are ignored- Parameters:
sb
- must not be null, target buffercomponentStart
- starting component number to addcomponentEnd
- ending component number to add
-
getComponents
public java.util.List<java.lang.String> getComponents()
- Returns:
- comopnents list
-
setComponents
public void setComponents(java.util.List<java.lang.String> components)
- Parameters:
components
- list to set
-
setComponent
public void setComponent(int number, java.lang.String value)
Inserts a component String value into the list of components, using the component number to position the value into the List.- Parameters:
number
- component number, first component of a field should be number onevalue
- String value of the parsed component (without component separators ':', '/', '//')
-
getComponent
public java.lang.String getComponent(int number)
Gets a specific component from the components list.- Parameters:
number
- one-based index of component, first component of a field should be number one- Returns:
- found component or null
-
setComponent
public void setComponent(java.lang.String componentName, java.lang.String value)
Inserts a component String value into the list of components, using the component name to position the value into the List.- Parameters:
componentName
- name of component to setvalue
- String value of the parsed component (without component separators ':', '/', '//')- Since:
- 9.3.12
-
componentNameToNumber
public int componentNameToNumber(java.lang.String componentName)
Get the component number based on the component name- Parameters:
componentName
- name of component to get- Returns:
- the component number or zero if the component name is not part of the field
- Since:
- 9.3.12
-
getComponent
public java.lang.String getComponent(java.lang.String componentName)
Gets a specific component (subfield) value given its name.- Parameters:
componentName
- name of component to get- Returns:
- found component or null if the component name is not part of the field or the value for the component is not set
- Since:
- 9.3.12
-
getValueDisplay
public java.lang.String getValueDisplay()
- See Also:
getValueDisplay(Locale)
-
getValueDisplay
public java.lang.String getValueDisplay(java.util.Locale locale)
Get a localized, suitable for showing to humans string of the field values. This method is overwritten when necessary by subclasses.- Parameters:
locale
- optional locale to format date and amounts, if null, the default locale is used- Returns:
- a concatenation of formated components with " " separator
- Since:
- 7.8
- See Also:
getValueDisplay(int, Locale)
-
getValueDisplay
public abstract java.lang.String getValueDisplay(int component, java.util.Locale locale)
Returns a localized suitable for showing to humans string of a field component.- Parameters:
component
- number of the component to displaylocale
- optional locale to format date and amounts, if null, the default locale is used- Returns:
- formatted component value or null if component number is invalid or not present
- Throws:
java.lang.IllegalArgumentException
- if component number is invalid for the field- Since:
- 7.8
-
getValueDisplay
public java.lang.String getValueDisplay(java.lang.String componentName, java.util.Locale locale)
Returns a localized suitable for showing to humans string of a field component.- Parameters:
componentName
- name of the component to displaylocale
- optional locale to format date and amounts, if null, the default locale is used- Returns:
- formatted component value or null if component name is invalid or not present
- Throws:
java.lang.IllegalArgumentException
- if component name is invalid for the field- Since:
- 9.3.12
-
getComponentAs
public java.lang.Object getComponentAs(java.lang.String componentName, java.lang.Class c)
Get the given component as the given object type. If the class is not recognized, it returns null, as well as if conversion fails.- Parameters:
componentName
- name of the component to retrieve- Throws:
java.lang.IllegalArgumentException
- if c is not any of: String, BIC, Currency, Number, BigDecimal Character or Integer- Since:
- 9.3.12
- See Also:
getComponent(int)
-
getComponentAs
public java.lang.Object getComponentAs(int component, java.lang.Class c)
Get the given component as the given object type. If the class is not recognized, it returns null, as well as if conversion fails.- Parameters:
component
- one-based index of the component to retrieve- Throws:
java.lang.IllegalArgumentException
- if c is not any of: String, BIC, Currency, Number, BigDecimal Character or Integer- See Also:
getComponent(int)
-
getComponentAsNumber
public java.lang.Object getComponentAsNumber(java.lang.String componentName)
Get the given component as a number object This method internal y callsgetComponentAsNumber(int)
, and casts the result- Since:
- 9.3.12
-
getComponentAsNumber
public java.lang.Number getComponentAsNumber(int component)
Get the given component as a number object This method internall y callsgetComponentAs(int, Class)
, and casts the result- Since:
- 7.8
-
joinComponents
public java.lang.String joinComponents(int start, boolean skipLast)
Returns a string with joined components values.- Parameters:
start
- starting index of components to join (zero based)skipLast
- if true the last component will not be included in the join, and where the "last" component is understood as the last not empty component (this is not necessary the last component of the field's component list.- Returns:
- s
-
joinComponents
public java.lang.String joinComponents(boolean skipLast)
Returns a string with all field's components joined.- Returns:
- s
- See Also:
joinComponents(int, boolean)
-
joinComponents
public java.lang.String joinComponents(int start)
Returns a string with all field's components joined- Returns:
- s
- See Also:
joinComponents(int, boolean)
-
joinComponents
public java.lang.String joinComponents()
Returns a string with all field's components joined.- Returns:
- s
- See Also:
joinComponents(int, boolean)
-
findComponentStartingWith
public java.lang.String findComponentStartingWith(java.lang.String prefix)
Returns the first component starting with the given prefix value or null if not found.- Returns:
- s
-
getValueByCodeword
public java.lang.String getValueByCodeword(java.lang.String codeword)
Finds the first component starting with the given codeword between slashes, and returns the component subvalue. For example, for the following field value
/ACC/BLABLABLA CrLf
//BLABLABLA CrLf
/INS/CITIUS33MIA CrLf
//BLABLABLA CrLf
A call to this method with parameter "INS" will return "CITIUS33MIA"- Returns:
- the found value or null if not found
- See Also:
findComponentStartingWith(String)
-
getValue
public abstract java.lang.String getValue()
Serializes the components into the a plain string value in SWIFT format.This method implementation is specific for each field. All not null components are appended to the result string with proper components separators like ':', slashes and CRLF.
For any valid field this is always true:
new Field(v)).getValue() = v
meaning plain value integrity must be preserved after parsing the value into components and serializing it back into the plain value. Conversely this may not be true when the parsed field value is invalid because the parser will do a best effort to gather as many valid components as possible and the serialization will also do a best effort to generate valid content.- Returns:
- SWIFT formatted value
-
isEmpty
public boolean isEmpty()
Returns true if all field's components are blank or null- Returns:
- true if all field's components are blank or null
-
getName
public abstract java.lang.String getName()
Returns the field's name composed by the field number and the letter option (if any)- Returns:
- the static value of FieldNN.NAME
-
componentsPattern
@Deprecated @ProwideDeprecated(phase3=SRU2023) public abstract java.lang.String componentsPattern()
Deprecated.UsetypesPattern()
instead
-
typesPattern
public abstract java.lang.String typesPattern()
Returns the field component types patternThis method returns a letter representing the type for each component in the Field. It supersedes the Components Pattern because it distinguishes between N (Number) and I (BigDecimal).
- Specified by:
typesPattern
in interfacePatternContainer
-
validatorPattern
public abstract java.lang.String validatorPattern()
Returns the field's validator pattern- Since:
- 7.8
-
isOptional
public abstract boolean isOptional(int component)
-
isGeneric
public abstract boolean isGeneric()
-
letterOption
public java.lang.Character letterOption()
Return the letter option of this field as given by it classname or null if this field has no letter option
-
isLetterOption
public boolean isLetterOption(char c)
Tell if this field is of a given letter option. letter is case sensitive
-
isNameAnyOf
public boolean isNameAnyOf(java.lang.String... names)
Compares the this fields's name with a list of names to check- Parameters:
names
- must not be null nor empty- Returns:
- true if this field names equals one in the list of names and false otherwise
- Throws:
java.lang.IllegalArgumentException
- if names is null or empty
-
is
public boolean is(java.lang.String compare)
Compares this field component 1 with the parameter value
Same asis(1, compare)
If the field has only one component this is the same as comparing against field value- Parameters:
compare
- string to compare- Returns:
- true if the first component is equal to the parameter
-
is
public boolean is(int componentNumber, java.lang.String compare)
Compares a specific component with the parameter value- Parameters:
componentNumber
- component number 1-basedcompare
- string to compare- Returns:
- true if the indicated component value is equal to the parameter
-
is
public boolean is(java.lang.String compare1, java.lang.String compare2)
Compares this field components 1 and 2 with the parameter values.- Parameters:
compare1
- string to compare with component 1compare2
- string to compare with component 2- Returns:
- true if components 1 and 2 are equal the parameter values respectively
-
is
public boolean is(java.lang.String... values)
Compares this field component 1 with the parameter values.
If the field has only one component this is the same as comparing against the field value- Parameters:
values
- the values to compare- Returns:
- true if the first component is equal to any of the given values
- Since:
- 7.9.7
-
asTag
public Tag asTag()
Get the generic tag object of this field.
-
componentsSize
public abstract int componentsSize()
Returns the defined amount of components.
This is not the amount of components present in the field instance, but the total amount of components that this field accepts as defined.
-
getLine
protected java.lang.String getLine(Field cp, java.lang.Integer start, java.lang.Integer end, int offset)
Base implementation for subclasses getLine API.Notice that line instance numbers are static and relevant to the field components definition, and not relative to the particular instance value. For example field 35B Line[1] will be the line with the ISIN number, regardless of the ISIN number present or not in the particular field instance. If that ISIN line is not present in the parameter field, the method will return null.
Also notice that a line may be composed by several components, there is no linear relation between component numbers and lines numbers.
- Parameters:
cp
- a copy of the subclass (this object is altered during method execution)start
- a reference to a specific line in the field, first line being 1; if null returns all found lines.end
- a reference to a specific line in the field, first line being 1; if null returns all found lines.offset
- an optional component number used as offset when counting lines- Returns:
- found line content or null
-
getComponentLabels
public abstract java.util.List<java.lang.String> getComponentLabels()
Returns english label for components.
The index in the list is in sync with specific field component structure.- Since:
- 7.8.4
- See Also:
getComponentLabel(int)
-
getComponentLabel
public java.lang.String getComponentLabel(java.lang.String componentName)
Returns english label for the component.- Parameters:
componentName
- name of the component to get- Returns:
- found label or null if it is not defined
- Since:
- 9.3.12
-
getComponentLabel
public java.lang.String getComponentLabel(int number)
Returns english label for the component.- Parameters:
number
- one-based index of component, first component of a field should be number one- Returns:
- found label or null if it is not defined
- Since:
- 7.8.4
-
getComponentMap
protected abstract java.util.Map<java.lang.Integer,java.lang.String> getComponentMap()
Returns a mapping between component numbers and their label in camel case format.- Since:
- 7.10.3
-
getLabelMap
protected abstract java.util.Map<java.lang.String,java.lang.Integer> getLabelMap()
Returns a mapping between component labels and the internal component number. Component labels are in lowercase and without spaces and separators. If a for a given component there is more than one label option, both are mapped to the same component number.- Since:
- 9.3.12
-
notNull
protected final java.util.Locale notNull(java.util.Locale locale)
Ensures a not-null locale parameter.- Parameters:
locale
- a locale or null- Returns:
- the parameter locale if it is not null or the default locale
- Since:
- 7.8.8
-
append
protected void append(java.lang.StringBuilder result, int component)
Appends a not null field component to the builder.
This helper method is used by subclasses implementation ofgetValue()
- Parameters:
result
- string where component content is appendedcomponent
- component number- Since:
- 7.9.3
-
toJson
public java.lang.String toJson()
Get a json representation of this message with expanded fields content.The JSON representation for fields contains the field name and the components with camel case labels, for example:
{"name":"32A","date":"010203","currency":"USD","amount":"123"}
- Specified by:
toJson
in interfaceJsonSerializable
- Returns:
- the message content as JSON
- Since:
- 7.10.3
-
-