| 1 | /* |
| 2 | @license.text@ |
| 3 | */ |
| 4 | package com.hammurapi.eventbus.tests.familyties.rules; |
| 5 | |
| 6 | import com.hammurapi.eventbus.Handler; |
| 7 | import com.hammurapi.eventbus.tests.familyties.model.Father; |
| 8 | import com.hammurapi.eventbus.tests.familyties.model.Mother; |
| 9 | import com.hammurapi.eventbus.tests.familyties.model.Parent; |
| 10 | |
| 11 | public class ParentRules extends FamilyTiesRules { |
| 12 | |
| 13 | /** |
| 14 | * Male parent is father, female parent is mother. |
| 15 | * @param parent |
| 16 | * @return Brother or Sister. |
| 17 | */ |
| 18 | @Handler(posts={Father.class, Mother.class}) |
| 19 | public Parent infer(Parent parent) { |
| 20 | |
| 21 | if (parent.getSubject().isMale()) { |
| 22 | if (!(parent instanceof Father)) { |
| 23 | return new Father(parent.getSubject(), parent.getObject()); |
| 24 | } |
| 25 | } else { |
| 26 | if (!(parent instanceof Mother)) { |
| 27 | return new Mother(parent.getSubject(), parent.getObject()); |
| 28 | } |
| 29 | } |
| 30 | return null; |
| 31 | } |
| 32 | } |