powered by ASAP

Java command annotations are used for the developing Java commands in PAK. This chapter describes the functionality of the @Range annotation. It also gives two examples how you can use this annotation in your implementation.

1. Basics

The @Range annotation restricts the values that can be set to a command variable. It only works together with the @Persistent annotation and is only applicable to variables of a primitive number type. This annotation is evaluated at runtime and raises an exception at the latest.

This annotation does only work in combination with the @Persistent annotation.

2. Properties

There are two properties defined for the @Range annotation: lowerLimit and upperLimit. Both properties are of type Number and represent the lower and the upper limit of a range. Allowed values for each limit are real numbers as well integers as decimals. It is possible to set both or just one of the values to use the @Range annotation. So the @Range annotation can be used to define a minimum or maximum too.

Setting no value for @Range is possible but not recommended as the range will be the maximum representable number by the datatype.

3. Usage

In the following examples are given on how to use the @Range annotation.

The first example shows how both properties are defined to set a lower and upper limit. The annotated field can be equal to 0 or 100 and between the two limits but not greater than 100 or lesser than 0.

Listing 1. Use case for the @Range annotation as range
/**
 * @workflowDocu This command does something with numbers.
 */
@JavaCommand
@CommandGroup("Numbers")
public class somethingWithNumbers {

	[...]

	/**
	 * @workflowDocu Example with a range between 0.0 and 100.0
	 */
	@Range(lowerLimit = 0.0, upperLimit = 100.0)
	@Persistent
	private double percentageShare;

	[...]
}

In the second example only the lower range is defined with 0. In this case the annotated variable can be equal to or greater but not lesser than 0.

Listing 2. Use case for the @Range annotation as a minimum
/**
 * @workflowDocu This command does something with numbers.
 */
@JavaCommand
@CommandGroup("Numbers")
public class somethingWithNumbers {

	[...]

	/**
	 * @workflowDocu Example with 0 as minimum
	 */
	@Range(lowerLimit = 0)
	@Persistent
	private double positiveNumber;

	[...]
}