Class Layout
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends a new field to the collection of fields of this layout.static LayoutCompiles the givenspecificationinto a layout.voidCompletes the definition of the collection of fields of this layout.booleanReturnstrueif the layout field indexed by the suppliednameexists in this layout.fields()Returns an unmodifiable collection with the fields contained in this layout.Returns the layout field indexed by the suppliedname.intReturns 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.booleanReturnstrueif this layout is complete.static StringnormalizeName(String name) Converts supplied name to upper case and replaces "-" by "_".voidChanges the locale of this layout.voidChanges the name of this layout.toString()Creates and returns a string serialization of this layout.
-
Constructor Details
-
Layout
public Layout()Constructs a newLayoutinstance.
-
-
Method Details
-
getName
-
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- ifnameisnull.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 returns0if this layout is notcomplete.- Returns:
- the total field size of this layout.
-
getSignature
-
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- iflocaleisnull.IllegalStateException- if the layout is not complete.
-
getField
Returns the layout field indexed by the suppliedname. Returnsnullif 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
nameornull. - Throws:
NullPointerException- ifnameisnull.
-
exists
Returnstrueif the layout field indexed by the suppliednameexists in this layout. It returnsfalseif this layout is notcomplete.- Parameters:
name- the name of the layout field.- Returns:
trueif the field is defined in this layout.- Throws:
NullPointerException- ifnameisnull.
-
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 theaddFieldmethod. 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 typeLISTis 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
nulliftypeisLISTEND. - Throws:
NullPointerException- if an argument isnull.IllegalArgumentException- if the name is invalid.IllegalStateException- if the layout definition is complete.
-
isComplete
public boolean isComplete()Returnstrueif 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:
trueif this layout is complete.
-
complete
Completes the definition of the collection of fields of this layout. The suppliedsignatureis stored so it can later be retrieved using thegetSignature()method. Once this method is called, no other calls to theaddFieldmethod 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:
toStringin classObject- Returns:
- the serialization of this layout.
- Throws:
IllegalStateException- if the layout is not complete.
-
normalizeName
-
compile
Compiles the givenspecificationinto a layout. The first line of thespecificationprovides 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- iftrueverify the specified signature.- Returns:
- the Layout compiled from the supplied
specification. - Throws:
NullPointerException- ifspecificationisnull.IllegalArgumentException- ifspecificationis invalid.
-