001    /**
002     * Property of Hammurapi Group
003     */
004    package com.hammurapi.reasoning.spi;
005    
006    import java.lang.annotation.ElementType;
007    import java.lang.annotation.Retention;
008    import java.lang.annotation.RetentionPolicy;
009    import java.lang.annotation.Target;
010    
011    /**
012     * Condition annotation can be used instead of accept methods for parameters and
013     * if () blocks inside infer methods.
014     * 
015     * @author Pavel
016     *
017     */
018    @Target({ElementType.METHOD, ElementType.PARAMETER})
019    @Retention(RetentionPolicy.RUNTIME)
020    public @interface Condition {
021            
022            /**
023             * Condition definition has the following format <code>[parameter list:] condition expression</code>. Parameter list is a comma separated list of parameter names, 
024             * parameters not used in the condition expression can be omitted. E.g. <code>parent, child, sibling</code> or, if <code>child</code> is not 
025             * used in the condition expression <code>parent,,sibling</code>. If parameter list is omitted, then arguments are named <code>arg0</code>, <code>arg1</code>, etc. for
026             * method level conditions and <code>arg</code> for parameter level conditions.
027             * Condition expression is a fragment of Java code returning boolean. 
028             * Rule instance is available through <code>rule</code> parameter. 
029             * @return True if condition is fulfilled and further rule evaluation shall be attempted. If several conditions are specified, 
030             * then they are connected by AND and it is assumed that they can be reordered by the rule compilation/execution engine to
031             * build conditions chain.
032             */
033            String[] value();
034            
035            /**
036             * Cost of condition evaluation. This cost can be used by rule compilation/execution engine to optimize condition order. 
037             * @return
038             */
039            double cost() default 1.0;      
040                    
041    }