@Retention(value=SOURCE) @Target(value=METHOD) public @interface ComputedProperty
Model
annotation to
define a derived property. Value of derived property is based on values
of Property
as enumerated by Model.properties()
.
The name of the derived property is the name of the method. The arguments
of the method must match names and types of some of the properties
from Model.properties()
list. As soon as one of these properties
changes, the method is called to recompute its new value.
This applies to inner changes in derived properties as well - e.g.
if the dependant property is another type generated by @Model
annotation -
changes in its own properties trigger recomputation of this derived
property as well (since version 0.9).
Method's return type defines the type of the derived property. It may be
any primitive type, String
, enum type
or a
type generated by @Model
annotation. One may
also return an array by returning a list of such (boxed) type
(for example List
<String
> or List
<Integer
>).
An example testing
whether a number is a prime using a ComputedProperty
is available
on-line.
public abstract String write
Object
)ComputedProperty
could look like this (assuming the model class
named
DataModel has int property value):
@ComputedProperty
(write="setPowerValue") static int powerValue(int value) { return value * value; } static void setPowerValue(DataModel m, int value) { m.setValue((int)Math
.sqrt(value)); }
Copyright © 2018 NetBeans. All rights reserved.