JBStrap parameters

Parameters

The JBStrap framework provides a class that is used to store and pass general parameters. This class is the Parameters class. This class is used to store the DataDescriptor column parameters and is also used for passing the page parameters. Developers can also use this class for any other purpose, as the class is simple, general solution pass and handle a large number of parameters.

Along with storing the parameters, it also provides type-correct querying, parameter removal, merging two or more parameter classes. It can also create a copy of the class. Changes in the copied Parameters class do not apply to the original Parameter class.

Creating a Parameter object and uploading it:

In the example above, a Parameter class was created, and three values were added. This class will be used in the rest of the examples below.

Getting a value from the Parameter class:

You can get the value of the param1 parameter. The type of the return value is not determined, it will always return with the same type as it was set. In this case, it will be a String type value.

Getting a value from the Parameter class and specifying the type of the return value:

In this example, the types of the return values were specified. Note that the value of param2 was queried with 2 different types. The value will be returned in both cases, in the specified type. So, the first query will return the value of param2 in String, and the value will be „25”. In the second query, the value will be in Long, and the value will be 25. (This would also apply if the value of param2 was originally specified in Integer).

As you can see, if the data type can be converted to the specified type during the query, it will be done automatically by the Parameters class. If it cannot be converted (e.g. a non-numeric value is queried as a number, or date value is queried as a non-date value), the query will return with an error, informing the developer that the requested value cannot be converted.

Merging the values of two Parameter classes:

In the above example, two separate Parameter classes were created, with their values. Some parameters share names across the two classes. These two classes were merged, by using the appropriate method. With the merge, a third (merged) class was created, which was named ’ mergedParam ’.

This new merged class had its values modified as well. As the param1 class was merged with the param2 class, the values of the param2 class overwrote the values of the param1 class. The value of ’ param1 ’ was changed to „Another value”. The value of param3 was changed to 123, along with its type changing to Integer. The param2 was left unchanged, and param4 was added.

You can merge multiple Parameter classes with the merge method. The order of the merge will follow the order of how the classes were specified, which also applies to how the values are overwritten if they have the same name. (The first class that was specified is going to be overwritten by the second class, the second class will be overwritten by the third class, etc.) Parameter values that do not need to be overwritten will be simply added to the merged class.

Removing a value from the Parameters class:

In this example, the value of ’param1’ will be removed. If you try to get the value of this, it will return with null.

Determining if parameters are equals:

You can check if two Parameter classes are equal, by using the equals method. Two Parameter classes are considered equal, if both have the same number of values, and the names and values of them are identical.

Getting the names of the values in the Parameter class:

Related pages: