openpojo icon indicating copy to clipboard operation
openpojo copied to clipboard

How can I declare derived/calculated fields - ones which only have getters and not setters ?

Open GoogleCodeExporter opened this issue 10 years ago • 3 comments

I have some pojos which set/get 4 datetime fields - and we also have related 
fields *and* getters (not setters) which covert those date times into local 
time zone date times. Can this be supported ?

e.g.

private Date startSate; // with getter and setter - setter also coverts and 
sets startLocalDate
private LocalDateTime startLocalDate; // with just setter

Original issue reported on code.google.com by [email protected] on 7 Oct 2014 at 4:18

GoogleCodeExporter avatar Mar 15 '15 19:03 GoogleCodeExporter

I realise if I dont have a field for the derived value - and calculate it in 
the getter everytime, then this will work... but it would be more efficient if 
I could store the derived values in fields to use in multiple calls to a 
getter. It depends on how often I anticipate the getters to be called.

Original comment by [email protected] on 7 Oct 2014 at 4:25

GoogleCodeExporter avatar Mar 15 '15 19:03 GoogleCodeExporter

It appears you want to write your own rule that implements the "setter must 
exist unless derived field"...
you can do it through an annotation that flags those fields as derived and then 
skip them in your rule.

Hope this helps...

Original comment by [email protected] on 8 Oct 2014 at 4:30

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

GoogleCodeExporter avatar Mar 15 '15 19:03 GoogleCodeExporter

#90 SetterTester and GetterTester improvement

rcriosbr avatar Sep 07 '16 23:09 rcriosbr