public abstract class Field extends java.lang.Object implements PatternContainer, JsonSerializable
Modifier and Type | Field and 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]=1234 |
Modifier | Constructor and Description |
---|---|
protected |
Field(Field source)
Copy constructor.
Initializes the components list with a deep copy of the source components list. |
protected |
Field(int components)
Creates a field with the list of components initialized to the given number of components.
|
protected |
Field(java.lang.String value)
Creates a new field and initializes its components with content from the parameter value.
|
Modifier and Type | Method and 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 ignored
|
protected void |
appendInLines(java.lang.StringBuilder sb,
java.lang.String... lines)
Append each lines in a new lines, empty lines are ignored
|
Tag |
asTag()
Get the generic tag object of this field.
|
abstract java.lang.String |
componentsPattern()
Deprecated.
Use
typesPattern() instead |
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.
|
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-n
|
protected static java.lang.String |
formatNumber(java.lang.Object aValue)
Format the given object as a money number without currency information in format
|
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.
|
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(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 |
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.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
|
protected void |
init(int components)
Initialize the list of components to the indicated size and sets all values to null
|
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 |
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
|
protected 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 |
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 |
typesPattern()
Returns the field component types pattern
This method returns a letter representing the type for each component in the Field.
|
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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parserPattern
protected java.util.List<java.lang.String> components
protected Field(int components)
components
- the number of components to initializeinit(int)
protected Field(java.lang.String value)
parse(String)
value
- complete field value including separators and CRLFprotected Field(Field source)
source
- a field instance to copyprotected static java.lang.String formatNumber(java.lang.Object aValue)
protected static java.lang.String format(java.util.Calendar d)
d
- Date object to formatprotected static java.lang.String formatAccount(java.lang.String a)
a
- string with an account number or nullpublic static java.math.BigDecimal getAsBigDecimal(java.lang.Number number)
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 static boolean validName(java.lang.String name)
name
- a field name to validatepublic 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()
protected void init(int components)
components
- the number of components to initializepublic 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
protected void appendInLines(java.lang.StringBuilder sb, java.lang.String... lines)
sb
- must not be null, target bufferlines
- may be null or empty, nothing is done in this caseprotected void appendInLines(java.lang.StringBuilder sb, int componentStart, int componentEnd)
sb
- must not be null, target buffercomponentStart
- starting component number to addcomponentEnd
- ending component number to addpublic 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)
joinComponents(int, boolean)
public java.lang.String joinComponents(int start)
joinComponents(int, boolean)
public java.lang.String joinComponents()
joinComponents(int, boolean)
public java.lang.String findComponentStartingWith(java.lang.String prefix)
public java.lang.String getValueByCodeword(java.lang.String 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 abstract java.lang.String getName()
@Deprecated @ProwideDeprecated(phase3=SRU2023) public abstract java.lang.String componentsPattern()
typesPattern()
insteadpublic abstract java.lang.String typesPattern()
typesPattern
in interface PatternContainer
public abstract java.lang.String validatorPattern()
public abstract boolean isOptional(int component)
public abstract boolean isGeneric()
public java.lang.Character letterOption()
public boolean isLetterOption(char c)
public 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()
protected java.lang.String getLine(Field cp, java.lang.Integer start, java.lang.Integer end, int offset)
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.
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 linespublic abstract java.util.List<java.lang.String> getComponentLabels()
getComponentLabel(int)
public java.lang.String getComponentLabel(int number)
number
- one-based index of component, first component of a field should be number oneprotected abstract java.util.Map<java.lang.Integer,java.lang.String> getComponentMap()
protected final java.util.Locale notNull(java.util.Locale locale)
locale
- a locale or nullprotected void append(java.lang.StringBuilder result, int component)
getValue()
result
- string where component content is appendedcomponent
- component numberpublic 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