java.lang.Object
cl.netswitch.lib.layout.Layout
- All Implemented Interfaces:
Serializable
Collection of fields whose values can be edited with a
LayoutMessage
.
After creating a layout, its name must be defined using the setName
method. Then, the addField
method
must be called for each field. Finally, the complete
method
must be called to complete the definition of the layout.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAppends a new field to the collection of fields of this layout.static Layout
Compiles the givenspecification
into a layout.void
Completes the definition of the collection of fields of this layout.boolean
Returnstrue
if the layout field indexed by the suppliedname
exists in this layout.fields()
Returns an unmodifiable collection with the fields contained in this layout.Returns the layout field indexed by the suppliedname
.int
Returns the sum of the sizes of all the fields of this layout.Returns the locale of this layout.getName()
Returns the name of this layout.Returns the signature (or checksum) of this layout.boolean
Returnstrue
if this layout is complete.static String
normalizeName
(String name) Converts supplied name to upper case and replaces "-" by "_".void
Changes the locale of this layout.void
Changes the name of this layout.toString()
Creates and returns a string serialization of this layout.
-
Constructor Details
-
Layout
public Layout()Constructs a newLayout
instance.
-
-
Method Details
-
getName
Returns the name of this layout. It returnsnull
if this layout is notcomplete
.- Returns:
- the name of this layout or
null
.
-
setName
Changes the name of this layout. This method cannot be used if the layout iscomplete
.- Parameters:
name
- the name of this layout.- Throws:
NullPointerException
- ifname
isnull
.IllegalStateException
- if the layout definition is complete.
-
getLength
public int getLength()Returns the sum of the sizes of all the fields of this layout. It returns0
if this layout is notcomplete
.- Returns:
- the total field size of this layout.
-
getSignature
Returns the signature (or checksum) of this layout. It returnsnull
if this layout is notcomplete
.- Returns:
- the signature (or checksum) of this layout.
-
getLocale
Returns the locale of this layout. This locale is used by fields that are locale-sensitive (such as numeric fields) when they are converted to/from strings. Initially, a layout uses the default JVM locale.- Returns:
- the locale of this layout.
-
setLocale
Changes the locale of this layout. This locale is used by fields that are locale-sensitive (such as numeric fields) when they are converted to/from strings. Initially, a layout uses the default JVM locale.- Parameters:
locale
- the locale of the layout.- Throws:
NullPointerException
- iflocale
isnull
.IllegalStateException
- if the layout is not complete.
-
getField
Returns the layout field indexed by the suppliedname
. Returnsnull
if the field is not defined in the layout, or if the layout is notcomplete
.- Parameters:
name
- the name of the required field.- Returns:
- the field indexed by
name
ornull
. - Throws:
NullPointerException
- ifname
isnull
.
-
exists
Returnstrue
if the layout field indexed by the suppliedname
exists in this layout. It returnsfalse
if this layout is notcomplete
.- Parameters:
name
- the name of the layout field.- Returns:
true
if the field is defined in this layout.- Throws:
NullPointerException
- ifname
isnull
.
-
fields
Returns an unmodifiable collection with the fields contained in this layout. These fields are returned in the order they were added to the layout using theaddField
method. It returns an empty collection if this layout is notcomplete
.- Returns:
- an unmodifiable collection of the fields contained in this layout.
-
addField
Appends a new field to the collection of fields of this layout. The properties of this new field are specified in the supplied arguments. Their legal values and restrictions are all explained inLayoutField
. Certain calls to this method must be made in pairs. In particular, if a field of typeLIST
is added, then this list must be closed (or terminated) adding a field of typeLISTEND
. This last call does not actually add aLayoutField
; it just completes the definition of the list field.- Parameters:
type
- type of the new field.name
- name of the new field.size
- total size of the new field.scale
- numeric scale of the new field.defval
- default value of the new field.- Returns:
- the newly added field or
null
iftype
isLISTEND
. - Throws:
NullPointerException
- if an argument isnull
.IllegalArgumentException
- if the name is invalid.IllegalStateException
- if the layout definition is complete.
-
isComplete
public boolean isComplete()Returnstrue
if this layout is complete. A layout is complete when it's name, fields and signature have all been defined. A complete layout is immutable, so none of its properties can be changed.- Returns:
true
if this layout is complete.
-
complete
Completes the definition of the collection of fields of this layout. The suppliedsignature
is stored so it can later be retrieved using thegetSignature()
method. Once this method is called, no other calls to theaddField
method are allowed. In other words, this layout becomes immutable after this method is used.- Parameters:
signature
- the signature of this layout (can be null).- Throws:
IllegalStateException
- if the layout definition is complete.
-
toString
Creates and returns a string serialization of this layout. The serialization consists of a sequence of three or more text lines. The first line is called the version and starts with the sequence "VR:
". The last line is called the checksum and starts with the sequence "CS:
". The lines between the version and the checksum lines represent layout fields in the following format:type:length[.scale]:name[:default]
- Overrides:
toString
in classObject
- Returns:
- the serialization of this layout.
- Throws:
IllegalStateException
- if the layout is not complete.
-
normalizeName
Converts supplied name to upper case and replaces "-" by "_".- Parameters:
name
- the name to be normalized (can be null).- Returns:
- the normalized version of supplied
name
.
-
compile
Compiles the givenspecification
into a layout. The first line of thespecification
provides the name of the layout, and the last line provides it's signature. The lines between the first and the last define the fields of the layout. The following is a sample layoutspecification
:VR:1.0:FMPRA_ING:2021-08-01:18:22:50 N:5:CODIGO X:1:TIPO:M N:11.2:VALOR X:1:ESTADO:A D:8:FECHAING:* X:30:DESCRIP D:8:FECACT:* CS:64:FMPRA_ING:ONHP2hI8ptNvgfYJSErLqa
- Parameters:
specification
- the specification of the layout.verifySignature
- iftrue
verify the specified signature.- Returns:
- the Layout compiled from the supplied
specification
. - Throws:
NullPointerException
- ifspecification
isnull
.IllegalArgumentException
- ifspecification
is invalid.
-