001    /*
002     * hammurapi-rules-tutorial @mesopotamia.version@
003     * Hammurapi rules tutorial. 
004     * Copyright (C) 2006  Hammurapi Group
005     *
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 2 of the License, or (at your option) any later version.
010     *
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with this library; if not, write to the Free Software
018     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019     *
020     * URL: http://http://www.hammurapi.biz
021     * e-Mail: support@hammurapi.biz
022     */
023    package biz.hammurapi.rules.tutorial.rules;
024    
025    import biz.hammurapi.rules.Rule;
026    import biz.hammurapi.rules.tutorial.conclusions.Child;
027    import biz.hammurapi.rules.tutorial.conclusions.Daughter;
028    import biz.hammurapi.rules.tutorial.conclusions.Father;
029    import biz.hammurapi.rules.tutorial.conclusions.GrandDaughter;
030    import biz.hammurapi.rules.tutorial.conclusions.GrandFather;
031    import biz.hammurapi.rules.tutorial.conclusions.GrandMother;
032    import biz.hammurapi.rules.tutorial.conclusions.GrandSon;
033    import biz.hammurapi.rules.tutorial.conclusions.Mother;
034    import biz.hammurapi.rules.tutorial.conclusions.Parent;
035    import biz.hammurapi.rules.tutorial.conclusions.Son;
036    
037    public class GrandRules extends Rule {
038            
039            /**
040             * Son of child is a grandson.
041             * @param son
042             * @param parent
043             * @return
044             */
045            public GrandSon infer(Son son, Parent parent) {
046                    return son.getObject().equals(parent.getObject()) ? new GrandSon(son.getSubject(), parent.getSubject()) : null;
047            }
048            
049            /**
050             * Daughter of child is a granddaughter.
051             * @param daughter
052             * @param parent
053             * @return
054             */
055            public GrandDaughter infer(Daughter daughter, Parent parent) {
056                    return daughter.getObject().equals(parent.getObject()) 
057                                    ? new GrandDaughter(daughter.getSubject(), parent.getSubject()) 
058                                    : null;
059            }
060            
061            /**
062             * Father of parent is grandparent.
063             * @param child
064             * @param father
065             * @return
066             */
067            public GrandFather infer(Child child, Father father) {
068                    return child.getObject().equals(father.getObject()) ? new GrandFather(father.getSubject(), child.getSubject()) : null;
069            }
070            
071            /**
072             * Mother of parent is grandmother.
073             * @param child
074             * @param mother
075             * @return
076             */
077            public GrandMother infer(Child child, Mother mother) {
078                    GrandMother grandMother = child.getObject().equals(mother.getObject()) ? new GrandMother(mother.getSubject(), child.getSubject()) : null;
079                    return grandMother;
080            }
081            
082    }