Debian Codegraph @

demo/kitchen-sink/docs/drools.drl

raw
1 /*
2 * Copyright 2010 JBoss Inc
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18 Original source
19 https://github.com/droolsjbpm/drools/blob/master/drools-examples/
20 http://docs.jboss.org/drools/
21 */
22 package com.example.ace
23
24 import java.math.BigDecimal
25 import function my.package.Foo.hello
26
27 declare FactType
28 @author( Bob )
29 id : String
30 name : String @maxLength(100) @notnull
31
32 value : BigDecimal
33 end
34
35 declare FactType2 extends AnotherType
36 end
37
38 declare trait TraitType extends com.package.AnotherType
39 end
40
41
42 declare trait GoldenCustomer
43 balance : long @Alias( "org.acme.foo.accountBalance" )
44 end
45
46 global org.slf4j.Logger logger
47
48 /**
49 * @param name who we'll salute?
50 */
51 function String hello(String name) {
52 return "Hello "+name+"!";
53 }
54
55 rule "Trim all strings"
56 dialect "java"
57 no-loop
58 when // fdsfds
59 $s : String(a == null || == "empty", $g : size)
60 Cheese( name matches "(Buffalo)?\\S*Mozarella" )
61 CheeseCounter( cheeses contains $var ) // contains with a variable
62 CheeseCounter( cheese memberof $matureCheeses )
63 Cheese( name soundslike 'foobar' )
64 Message( routingValue str[startsWith] "R1" )
65 Cheese( name in ( "stilton", "cheddar", $cheese ) )
66 Person( eval( age == girlAge + 2 ), sex = 'M' )
67 then
68 /**
69 * TODO There mus be better way
70 */
71 retract($s);
72 String a = "fd";
73 a.toString();
74
75 insert($s.trim());
76 end
77
78 query isContainedIn( String x, String y )
79 Location( x, y; )
80 or
81 ( Location( z, y; ) and isContainedIn( x, z; ) )
82 end
83
84 rule "go" salience 10
85 when
86 $s : String( )
87 then
88 System.out.println( $s );
89 end
90
91 rule "When all English buses are not red"
92 when
93 not(forall( $bus : Bus( nationality == 'english')
94 Bus( this == $bus, color = 'red' ) ))
95 then
96 // What if all english buses are not red?
97 end
98
99 rule "go1"
100 when
101 String( this == "go1" )
102 isContainedIn("Office", "House"; )
103 then
104 System.out.println( "office is in the house" );
105 end
106
107 rule "go2"
108 when
109 String( this == "go2" )
110 isContainedIn("Draw", "House"; )
111 then
112 System.out.println( "Draw in the House" );
113 end
114
115 /**
116 * Go Right
117 */
118 rule GoRight dialect "mvel" salience (Math.abs( $df.colDiff )) when
119 $df : DirectionDiff(colDiff > 0 )
120 $target : Cell( row == $df.row, col == ($df.col + 1) )
121 CellContents( cell == $target, cellType != CellType.WALL )
122 not Direction(character == $df.fromChar, horizontal == Direction.RIGHT )
123 then
124 System.out.println( "monster right" );
125 retract( $df );
126 insert( new Direction($df.fromChar, Direction.RIGHT, Direction.NONE ) );
127 end