public abstract class Field extends java.lang.Object implements PatternContainer, JsonSerializable
Modifier and Type | Method and Description |
---|---|
Tag |
asTag()
Get the generic tag object of this field.
|
abstract java.lang.String |
componentsPattern()
Returns the field's components pattern
|
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. |
boolean |
equals(java.lang.Object obj)
Implementation of equals using EqualsBuilder from commons-lang
|
java.lang.String |
findComponentStartingWith(java.lang.String prefix)
Returns the first component starting with the given prefix value or null if not found.
|
static 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 argument
|
java.lang.String |
getComponent(int number)
Gets a specific component from the components list.
|
java.lang.Object |
getComponentAs(int component,
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 calls
getComponentAs(int, Class) , and casts the result |
java.lang.String |
getComponentLabel(int number)
Returns english label for the component.
|
java.util.List<java.lang.String> |
getComponents() |
java.lang.String |
getConditionalQualifier()
Deprecated.
|
java.lang.String |
getDSS()
Deprecated.
|
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 Field |
getField(Tag t)
Creates a Field instance for the given Tag object, using reflection.
|
static java.lang.String |
getLabel(java.lang.String fieldName,
java.lang.String mt,
java.lang.String sequence)
Same as
getLabel(String, String, String, Locale) using default locale |
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.
|
static java.lang.String |
getLabelComponents(java.lang.String fieldName,
java.lang.String mt,
java.lang.String sequence,
java.util.Locale locale)
Similar to
getLabelComponents(String, String, String, Locale) but returning the components property in bundle |
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.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-lang
|
boolean |
is(int componentNumber,
java.lang.String compare)
Compares a specific component with the parameter value
|
boolean |
is(java.lang.String... values)
Compares this field component 1 with the parameter values.
|
boolean |
is(java.lang.String compare)
Compares this field component 1 with the parameter value
Same as is(1, compare)
If the field has only one component this is the same as comparing against field value |
boolean |
is(java.lang.String compare1,
java.lang.String compare2)
Compares this field components 1 and 2 with the parameter values.
|
boolean |
isAnyOf(java.lang.String... names)
Deprecated.
confusing name, use
isNameAnyOf(String...) instead |
boolean |
isDSSPresent()
Deprecated.
|
boolean |
isEmpty()
Returns true if all field's components are blank or null
|
abstract 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 check
|
abstract 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 joined
|
java.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 option
|
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 |
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-lang
|
abstract java.lang.String |
validatorPattern()
Returns the field's validator pattern
|
static boolean |
validName(java.lang.String name)
Returns true if the field name is valid.
|
parserPattern
public abstract void parse(java.lang.String value)
value
- complete field value including separators and CRLFpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.util.List<java.lang.String> getComponents()
public void setComponents(java.util.List<java.lang.String> components)
components
- list to setpublic void setComponent(int number, java.lang.String value)
number
- component number, first component of a field should be number onevalue
- String value of the parsed component (without component separators ':', '/', '//')public java.lang.String getComponent(int number)
number
- one-based index of component, first component of a field should be number onepublic java.lang.String getValueDisplay()
getValueDisplay(Locale)
public java.lang.String getValueDisplay(java.util.Locale locale)
locale
- optional locale to format date and amounts, if null, the default locale is usedgetValueDisplay(int, Locale)
public abstract java.lang.String getValueDisplay(int component, java.util.Locale locale)
component
- number of the component to displaylocale
- optional locale to format date and amounts, if null, the default locale is usedjava.lang.IllegalArgumentException
- if component number is invalid for the fieldpublic java.lang.Object getComponentAs(int component, java.lang.Class c)
component
- one-based index of the component to retrievejava.lang.IllegalArgumentException
- if c is not any of: String, BIC, Currency, Number, BigDecimal Character or IntegergetComponent(int)
public java.lang.Number getComponentAsNumber(int component)
getComponentAs(int, Class)
, and casts the resultpublic java.lang.String joinComponents(int start, boolean skipLast)
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.public java.lang.String joinComponents(boolean skipLast)
skipLast
- joinComponents(int, boolean)
public java.lang.String joinComponents(int start)
start
- joinComponents(int, boolean)
public java.lang.String joinComponents()
joinComponents(int, boolean)
public static java.math.BigDecimal getAsBigDecimal(java.lang.Number number)
number
- public java.lang.String findComponentStartingWith(java.lang.String prefix)
prefix
- public java.lang.String getValueByCodeword(java.lang.String codeword)
codeword
- findComponentStartingWith(String)
public abstract java.lang.String getValue()
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.
public boolean isEmpty()
public static Field getField(Tag t)
t
- a tag with proper name and value contentpublic static Field getField(java.lang.String name, java.lang.String value)
name
- a proper field name, ex: 32A, 22F, 20value
- an optional field value or null to create the field with no initial contentpublic static java.lang.String getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence)
getLabel(String, String, String, Locale)
using default localepublic static java.lang.String getLabel(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
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 desiredpublic static java.lang.String getLabelComponents(java.lang.String fieldName, java.lang.String mt, java.lang.String sequence, java.util.Locale locale)
getLabelComponents(String, String, String, Locale)
but returning the components property in bundlepublic abstract java.lang.String getName()
public abstract java.lang.String componentsPattern()
componentsPattern
in interface PatternContainer
public abstract java.lang.String validatorPattern()
public abstract boolean isOptional(int component)
public abstract boolean isGeneric()
@Deprecated @ProwideDeprecated(phase3=SRU2020) public java.lang.String getDSS()
@Deprecated @ProwideDeprecated(phase3=SRU2020) public boolean isDSSPresent()
@Deprecated @ProwideDeprecated(phase3=SRU2020) public java.lang.String getConditionalQualifier()
public java.lang.Character letterOption()
public boolean isLetterOption(char c)
@Deprecated @ProwideDeprecated(phase4=SRU2020) public boolean isAnyOf(java.lang.String... names)
isNameAnyOf(String...)
insteadpublic boolean isNameAnyOf(java.lang.String... names)
names
- must not be null nor emptyjava.lang.IllegalArgumentException
- if names is null or emptypublic boolean is(java.lang.String compare)
is(1, compare)
compare
- string to comparepublic boolean is(int componentNumber, java.lang.String compare)
componentNumber
- component number 1-basedcompare
- string to comparepublic boolean is(java.lang.String compare1, java.lang.String compare2)
compare1
- string to compare with component 1compare2
- string to compare with component 2public boolean is(java.lang.String... values)
values
- the values to comparepublic Tag asTag()
public abstract int componentsSize()
public static boolean validName(java.lang.String name)
name
- a field name to validatepublic java.lang.String getComponentLabel(int number)
number
- one-based index of component, first component of a field should be number onepublic java.lang.String toJson()
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"}
toJson
in interface JsonSerializable
public static Field fromJson(java.lang.String json)
The implementation reads the "name" property in the JSON data, then calls the fromJson method in the specific Field subclass
toJson()