public abstract class Field extends Object implements PatternContainer
Modifier and Type | Field and Description |
---|---|
protected List<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()
Deprecated.
usar
Field(int) |
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(String value)
Creates a new field and initializes its components with content from the parameter value.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendInLines(StringBuilder sb,
int componentStart,
int componentEnd)
Append each component between componentStart and componentEnd in a new lines, empty components are ignored
|
protected void |
appendInLines(StringBuilder sb,
String... lines)
Append each lines in a new lines, empty lines are ignored
|
Tag |
asTag()
Get the generic tag object of this field.
|
abstract 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(Object obj)
Implementation of equals using EqualsBuilder from commons-lang
|
String |
findComponentStartingWith(String prefix)
Returns the first component starting with the given prefix value or
null if not found. |
protected static String |
format(Calendar d) |
protected static String |
formatAccount(String a)
A formatted amount with a fixed format nnnn-nnnnn-nnn-n
|
protected static String |
formatNumber(Object aValue)
Format the given object as a money number without currency information in format
|
static BigDecimal |
getAsBigDecimal(Number number)
Gets a BigDecimal from a generic Number argument
|
String |
getComponent(int number)
Gets a specific component from the components list.
|
Object |
getComponentAs(int component,
Class c)
Get the given component as the given object type.
|
Number |
getComponentAsNumber(int component)
Get the given component as a number object
This method internall y calls
getComponentAs(int, Class) , and casts the result |
String |
getComponentLabel(int number)
Returns english label for the component.
|
protected abstract List<String> |
getComponentLabels()
Returns english label for components.
|
List<String> |
getComponents() |
String |
getConditionalQualifier()
Deprecated.
|
String |
getDSS()
Deprecated.
|
static Field |
getField(String name,
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.
|
String |
getLabel()
Deprecated.
field labels varies depending on the specific MT and sequence, label should be retrieve using
getLabel(String, String, String, Locale) with proper MT and sequence identifiers |
String |
getLabel(Locale locale)
Deprecated.
field labels varies depending on the specific MT and sequence, label should be retrieve using
getLabel(String, String, String, Locale) with proper MT and sequence identifiers |
static String |
getLabel(String fieldName,
Locale locale)
Deprecated.
field labels varies depending on the specific MT and sequence, label should be retrieve using
getLabel(String, String, String, Locale) with proper MT and sequence identifiers |
static String |
getLabel(String fieldName,
String mt,
String sequence)
Same as
getLabel(String, String, String, Locale) using default locale |
static String |
getLabel(String fieldName,
String mt,
String sequence,
Locale locale)
Returns the field business description name, using resource bundle from pw_swift_labels property files.
|
static String |
getLabelComponents(String fieldName,
String mt,
String sequence,
Locale locale)
Similar to
getLabelComponents(String, String, String, Locale) but returning the components property in bundle |
protected String |
getLine(Field cp,
Integer start,
Integer end,
int offset)
Base implementation for subclasses getLine API.
|
abstract String |
getName()
Returns the field's name composed by the field number and the letter option (if any)
|
String |
getValue()
Serializes the fields' components into the single string value (SWIFT format).
|
String |
getValueByCodeword(String codeword)
Finds the first component starting with the given codeword between slashes, and returns the component subvalue.
|
String |
getValueDisplay() |
abstract String |
getValueDisplay(int component,
Locale locale)
Returns a localized suitable for showing to humans string of a field component.
|
String |
getValueDisplay(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,
String compare)
Compare the value of the component
componentNumber of this field with compare |
boolean |
is(String compare)
Compare the value of the component1 of this field with
compare
Same as is(1, compare) |
boolean |
is(String compare1,
String compare2)
Compare the value of the component1 of this field with
compare1 and the value of component2 with compare2 |
boolean |
isAnyOf(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(String... names) |
abstract boolean |
isOptional(int component) |
String |
joinComponents()
Returns a string with all field's components joined.
|
String |
joinComponents(boolean skipLast)
Returns a string with all field's components joined.
|
String |
joinComponents(int start)
Returns a string with all field's components joined
|
String |
joinComponents(int start,
boolean skipLast)
Returns a string with joined components values.
|
Character |
letterOption()
Return the letter option of this field as given by it classname or
null if this field has no letter option |
void |
parse(String value)
Parses the parameter value into the internal components structure.
|
void |
setComponent(int number,
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(List<String> components) |
String |
toString()
Implementation of toString using ToStringBuilder from commons-lang
|
abstract String |
validatorPattern()
Returns the field's validator pattern
|
static boolean |
validName(String name)
Returns true if the field name is valid.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parserPattern
@Deprecated protected Field()
Field(int)
protected Field(int components)
components
- the number of components to initializeinit(int)
protected Field(String value)
parse(String)
value
- complete field value including separators and CRLFprotected Field(Field source)
source
- a field instance to copyprotected void init(int components)
null
components
- the number of components to initializepublic void parse(String value)
value
- complete field value including separators and CRLFpublic String toString()
public boolean equals(Object obj)
public int hashCode()
protected static String formatNumber(Object aValue)
aValue
- protected static String format(Calendar d)
d
- Date object to formatprotected static String formatAccount(String a)
a
- string with an account number or null
null
protected void appendInLines(StringBuilder sb, String... lines)
sb
- must not be null, target bufferlines
- may be null or empty, nothing is done in this caseprotected void appendInLines(StringBuilder sb, int componentStart, int componentEnd)
sb
- must not be null, target buffercomponentStart
- starting component number to addcomponentEnd
- ending component number to addpublic void setComponents(List<String> components)
components
- list to setpublic void setComponent(int number, String value)
number
- component number, first component of a field should be number onevalue
- String value of the parsed component (without component separators ':', '/', '//')public String getComponent(int number)
number
- one-based index of component, first component of a field should be number onenull
public String getValueDisplay()
getValueDisplay(Locale)
public String getValueDisplay(Locale locale)
locale
- optional locale to format date and amounts, if null, the default locale is usedgetValueDisplay(int, Locale)
public abstract String getValueDisplay(int component, Locale locale)
component
- number of the component to displaylocale
- optional locale to format date and amounts, if null, the default locale is usedIllegalArgumentException
- if component number is invalid for the fieldpublic Object getComponentAs(int component, Class c)
component
- one-based index of the component to retrieveIllegalArgumentException
- if c is not any of: String, BIC, Currency, Number, BigDecimal Character or IntegergetComponent(int)
public Number getComponentAsNumber(int component)
getComponentAs(int, Class)
, and casts the resultpublic 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 String joinComponents(boolean skipLast)
skipLast
- joinComponents(int, boolean)
public String joinComponents(int start)
start
- joinComponents(int, boolean)
public String joinComponents()
joinComponents(int, boolean)
public static BigDecimal getAsBigDecimal(Number number)
number
- public String findComponentStartingWith(String prefix)
null
if not found.prefix
- public String getValueByCodeword(String codeword)
codeword
- null
if not foundfindComponentStartingWith(String)
public String getValue()
public boolean isEmpty()
public static Field getField(Tag t)
t
- a tag with proper name and value contentnull
if exceptions occur during object creation.public static Field getField(String name, String value)
name
- a proper field name, ex: 32A, 22F, 20value
- an optional field value or null
to create the field with no initial contentnull
if exceptions occur during object creation.@Deprecated public String getLabel()
getLabel(String, String, String, Locale)
with proper MT and sequence identifiers@Deprecated public String getLabel(Locale locale)
getLabel(String, String, String, Locale)
with proper MT and sequence identifiers@Deprecated public static String getLabel(String fieldName, Locale locale)
getLabel(String, String, String, Locale)
with proper MT and sequence identifierspublic static String getLabel(String fieldName, String mt, String sequence)
getLabel(String, String, String, Locale)
using default localepublic static String getLabel(String fieldName, String mt, String sequence, 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 String getLabelComponents(String fieldName, String mt, String sequence, Locale locale)
getLabelComponents(String, String, String, Locale)
but returning the components property in bundlepublic abstract String getName()
public abstract String componentsPattern()
componentsPattern
in interface PatternContainer
public abstract String validatorPattern()
public abstract boolean isOptional(int component)
public abstract boolean isGeneric()
@Deprecated public String getDSS()
@Deprecated public boolean isDSSPresent()
@Deprecated public String getConditionalQualifier()
public Character letterOption()
null
if this field has no letter optionpublic boolean isLetterOption(char c)
@Deprecated public boolean isAnyOf(String... names)
isNameAnyOf(String...)
insteadnames
- must not be null nor emptytrue
if this field names equals one in the list of names and false
in other caseIllegalArgumentException
- if names is null or emptyisNameAnyOf(String...)
public boolean isNameAnyOf(String... names)
names
- must not be null nor emptytrue
if this field names equals one in the list of names and false
in other caseIllegalArgumentException
- if names is null or emptypublic boolean is(String compare)
compare
Same as is(1, compare)
public boolean is(int componentNumber, String compare)
componentNumber
of this field with compare
public boolean is(String compare1, String compare2)
compare1
and the value of component2 with compare2
public Tag asTag()
public abstract int componentsSize()
protected String getLine(Field cp, Integer start, Integer end, int offset)
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 static boolean validName(String name)
name
- a field name to validateprotected abstract List<String> getComponentLabels()
getComponentLabel(int)
public String getComponentLabel(int number)
number
- one-based index of component, first component of a field should be number onenull
if it is not defined