Skip to content

Commit

Permalink
changed eol
Browse files Browse the repository at this point in the history
  • Loading branch information
ant committed Aug 16, 2015
1 parent f8b9625 commit 02fb02b
Show file tree
Hide file tree
Showing 46 changed files with 6,598 additions and 6,598 deletions.
42 changes: 21 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

target/
.settings/
.project
.classpath

rules-js/test/coverage
**/node_modules/

*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

target/
.settings/
.project
.classpath

rules-js/test/coverage
**/node_modules/

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## rules

Simple Rule Engine from Ant's blog

See [http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html](http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html) and
[http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html](http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html) and also
[http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html](http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html) for Node.js.

Also see the test classes, e.g. [https://github.com/maxant/rules/tree/master/rules/src/test/java/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules/src/test/java/ch/maxant/rules/blackbox), [https://github.com/maxant/rules/tree/master/rules-java8/src/test/java/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules-java8/src/test/java/ch/maxant/rules/blackbox) and [https://github.com/maxant/rules/tree/master/rules-scala/src/test/scala/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules-scala/src/test/scala/ch/maxant/rules/blackbox), or [https://github.com/maxant/rules/tree/master/rules-js/test/rules-test.js](https://github.com/maxant/rules/tree/master/rules-js/test/rules-test.js).

Release Notes and Licence (LGPL) can be found here: [https://github.com/maxant/rules/tree/master/rules/src/main/resources](https://github.com/maxant/rules/tree/master/rules/src/main/resources).
## rules

Simple Rule Engine from Ant's blog

See [http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html](http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html) and
[http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html](http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html) and also
[http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html](http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html) for Node.js.

Also see the test classes, e.g. [https://github.com/maxant/rules/tree/master/rules/src/test/java/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules/src/test/java/ch/maxant/rules/blackbox), [https://github.com/maxant/rules/tree/master/rules-java8/src/test/java/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules-java8/src/test/java/ch/maxant/rules/blackbox) and [https://github.com/maxant/rules/tree/master/rules-scala/src/test/scala/ch/maxant/rules/blackbox](https://github.com/maxant/rules/tree/master/rules-scala/src/test/scala/ch/maxant/rules/blackbox), or [https://github.com/maxant/rules/tree/master/rules-js/test/rules-test.js](https://github.com/maxant/rules/tree/master/rules-js/test/rules-test.js).

Release Notes and Licence (LGPL) can be found here: [https://github.com/maxant/rules/tree/master/rules/src/main/resources](https://github.com/maxant/rules/tree/master/rules/src/main/resources).
88 changes: 44 additions & 44 deletions rules-java8/pom.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../rules-parent</relativePath>
</parent>
<artifactId>rules-java8</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<!-- depend on the rules library -->
<groupId>ch.maxant</groupId>
<artifactId>rules</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<!-- depend on test classes from the rules library -->
<groupId>ch.maxant</groupId>
<artifactId>rules</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../rules-parent</relativePath>
</parent>
<artifactId>rules-java8</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<!-- depend on the rules library -->
<groupId>ch.maxant</groupId>
<artifactId>rules</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<!-- depend on test classes from the rules library -->
<groupId>ch.maxant</groupId>
<artifactId>rules</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
138 changes: 69 additions & 69 deletions rules-java8/src/main/java/ch/maxant/rules/Java8Engine.java
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
/*
* Copyright (c) 2011-2014 Ant Kutschera
*
* This file is part of Ant Kutschera's blog.
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
* You should have received a copy of the Lesser GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.maxant.rules;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class supports Java 8 {@link Stream}s being used with the engine.
*
* <code>
//to use a lambda, construct a SamAction and pass it a lambda.
IAction<MyInput, BigDecimal> action1 = new SamAction<MyInput, BigDecimal>("outcome1", i -> new BigDecimal("100.0"));
IAction<MyInput, BigDecimal> action2 = new SamAction<MyInput, BigDecimal>("outcome2", i -> new BigDecimal("101.0"));
List<IAction<MyInput, BigDecimal>> actions = Arrays.asList(action1, action2);
Engine e = new Engine(rules, true);
* </code>
*
* See <code>Engine</code> for more details.
*/
public class Java8Engine extends Engine {

/** See <code>#Engine(java.util.Collection, boolean)</code>. Convenience constructor for use with Java 8 {@link Stream}s.
* Simply collects all elements from the given {@link Stream}.
*/
public Java8Engine(final Stream<Rule> rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException {
super(rules.collect(Collectors.toList()), throwExceptionIfCompilationFails);
}

/** See <code>#executeBestAction(Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> Output executeBestAction(Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
return executeBestAction(null, input, actions);
}

/** See <code>#executeBestAction(String nameSpacePattern, Object, java.util.Collection)</code>, supports {@link Stream}s.
*/
public <Input, Output> Output executeBestAction(String nameSpacePattern, Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
return executeBestAction(nameSpacePattern, input, actions.collect(Collectors.toList()));
}

/** See <code>#executeAllActions(Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> void executeAllActions(Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
executeAllActions(null, input, actions);
}

/** See <code>#executeAllActions(String nameSpacePattern, Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> void executeAllActions(String nameSpacePattern, Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
executeAllActions(nameSpacePattern, input, actions.collect(Collectors.toList()));
}

}

/*
* Copyright (c) 2011-2014 Ant Kutschera
*
* This file is part of Ant Kutschera's blog.
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
* You should have received a copy of the Lesser GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.maxant.rules;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class supports Java 8 {@link Stream}s being used with the engine.
*
* <code>
//to use a lambda, construct a SamAction and pass it a lambda.
IAction<MyInput, BigDecimal> action1 = new SamAction<MyInput, BigDecimal>("outcome1", i -> new BigDecimal("100.0"));
IAction<MyInput, BigDecimal> action2 = new SamAction<MyInput, BigDecimal>("outcome2", i -> new BigDecimal("101.0"));
List<IAction<MyInput, BigDecimal>> actions = Arrays.asList(action1, action2);
Engine e = new Engine(rules, true);
* </code>
*
* See <code>Engine</code> for more details.
*/
public class Java8Engine extends Engine {

/** See <code>#Engine(java.util.Collection, boolean)</code>. Convenience constructor for use with Java 8 {@link Stream}s.
* Simply collects all elements from the given {@link Stream}.
*/
public Java8Engine(final Stream<Rule> rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException {
super(rules.collect(Collectors.toList()), throwExceptionIfCompilationFails);
}

/** See <code>#executeBestAction(Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> Output executeBestAction(Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
return executeBestAction(null, input, actions);
}

/** See <code>#executeBestAction(String nameSpacePattern, Object, java.util.Collection)</code>, supports {@link Stream}s.
*/
public <Input, Output> Output executeBestAction(String nameSpacePattern, Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
return executeBestAction(nameSpacePattern, input, actions.collect(Collectors.toList()));
}

/** See <code>#executeAllActions(Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> void executeAllActions(Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
executeAllActions(null, input, actions);
}

/** See <code>#executeAllActions(String nameSpacePattern, Object, java.util.Collection)</code>, supports {@link Stream}s. */
public <Input, Output> void executeAllActions(String nameSpacePattern, Input input, Stream<IAction<Input, Output>> actions) throws NoMatchingRuleFoundException, NoActionFoundException, DuplicateNameException {
executeAllActions(nameSpacePattern, input, actions.collect(Collectors.toList()));
}

}


88 changes: 44 additions & 44 deletions rules-java8/src/main/java/ch/maxant/rules/SamAction.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
/*
* Copyright (c) 2011-2014 Ant Kutschera
*
* This file is part of Ant Kutschera's blog.
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
* You should have received a copy of the Lesser GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.maxant.rules;

/**
* allows you to construct an action using a lambda.
* @param <I> the input type of this action
* @param <O> the output type of this action
*/
public class SamAction<I, O> extends AbstractAction<I, O> {

private final ExecutableAction<I, O> action;

/**
* @param name the name of this action
* @param action a lambda containing the function which should be
* executed when <code>execute(Object)</code> is called by the <code>Engine</code>.
*/
public SamAction(String name, ExecutableAction<I, O> action) {
super(name);
this.action = action;
}

@Override
public O execute(I input) {
return action.execute(input);
}

}
/*
* Copyright (c) 2011-2014 Ant Kutschera
*
* This file is part of Ant Kutschera's blog.
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
* You should have received a copy of the Lesser GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.maxant.rules;

/**
* allows you to construct an action using a lambda.
* @param <I> the input type of this action
* @param <O> the output type of this action
*/
public class SamAction<I, O> extends AbstractAction<I, O> {

private final ExecutableAction<I, O> action;

/**
* @param name the name of this action
* @param action a lambda containing the function which should be
* executed when <code>execute(Object)</code> is called by the <code>Engine</code>.
*/
public SamAction(String name, ExecutableAction<I, O> action) {
super(name);
this.action = action;
}

@Override
public O execute(I input) {
return action.execute(input);
}

}
Loading

0 comments on commit 02fb02b

Please sign in to comment.