Debian Codegraph @

tests/inputs/drools.drl

raw
1 // https://github.com/AlDanial/cloc/issues/172
2
3 /*
4 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.drools.examples.fibonacci
20
21 import org.drools.examples.fibonacci.FibonacciExample.Fibonacci;
22
23 dialect "mvel"
24
25 rule Recurse
26 salience 10
27 when
28 f : Fibonacci ( value == -1 )
29 not ( Fibonacci ( sequence == 1 ) )
30 then
31 insert( new Fibonacci( f.sequence - 1 ) );
32 System.out.println( "recurse for " + f.sequence );
33 end
34
35 rule Bootstrap
36 when
37 f : Fibonacci( sequence == 1 || == 2, value == -1 ) // this is a multi-restriction || on a single field
38 then
39 modify ( f ){ value = 1 };
40 System.out.println( f.sequence + " == " + f.value );
41 end
42
43 rule Calculate
44 when
45 f1 : Fibonacci( s1 : sequence, value != -1 ) // here we bind sequence
46 f2 : Fibonacci( sequence == (s1 + 1 ), value != -1 ) // here we don't, just to demonstrate the different way bindings can be used
47 f3 : Fibonacci( s3 : sequence == (f2.sequence + 1 ), value == -1 )
48 then
49 modify ( f3 ) { value = f1.value + f2.value };
50 System.out.println( s3 + " == " + f3.value ); // see how you can access pattern and field bindings
51 end