Last active
December 30, 2015 16:19
-
-
Save mdproctor/7853901 to your computer and use it in GitHub Desktop.
simple DRL DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.drools.java8; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.function.Predicate; | |
public class Java8Example { | |
Rule rule1 = new Rule() | |
.setWhen((CTuple1<Person>) (Person person) -> person.getAge() >= 18, | |
(CTuple2<Person, Pet>) (Person person, Pet pet) -> pet.getOwner() == person) | |
.setThen(((ATuple2<Person, Pet>) (Person person, Pet pet) -> System.out.println("Person" + person + "is the owner of" + pet))); | |
public static interface Tuple { | |
} | |
public static interface CTuple1<E1> extends Tuple { | |
boolean invoke(E1 t); | |
} | |
public static interface CTuple2<E1, E2> extends Tuple{ | |
boolean invoke(E1 e1, E2 e2); | |
} | |
public static interface CTuple3<E1, E2, E3> extends Tuple { | |
boolean invoke(E1 e1, E2 e2, E3 e3); | |
} | |
public static interface ATuple1<E1> extends Tuple { | |
void invoke(E1 t); | |
} | |
public static interface ATuple2<E1, E2> extends Tuple{ | |
void invoke(E1 e1, E2 e2); | |
} | |
public static interface ATuple3<E1, E2, E3> extends Tuple { | |
void invoke(E1 e1, E2 e2, E3 e3); | |
} | |
public static class Rule { | |
private Tuple[] when; | |
private Tuple then; | |
public Rule() {} | |
public Rule setWhen(Tuple... when) { | |
this.when = when; | |
return this; | |
} | |
public Rule setThen(Tuple then) { | |
this.then = then; | |
return this; | |
} | |
} | |
public static class Person { | |
private String name; | |
private int age; | |
public Person(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
public int getAge() { | |
return age; | |
} | |
} | |
public static class Pet { | |
private String name; | |
private Person owner; | |
private String type; | |
public Pet(String name, Person owner, String type) { | |
this.name = name; | |
this.owner = owner; | |
this.type = type; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public Person getOwner() { | |
return owner; | |
} | |
public void setOwner(Person owner) { | |
this.owner = owner; | |
} | |
public String getType() { | |
return type; | |
} | |
public void setType(String type) { | |
this.type = type; | |
} | |
} | |
public static class Location { | |
private String person; | |
private String place; | |
public Location(String person, String place) { | |
this.person = person; | |
this.place = place; | |
} | |
public String getPerson() { | |
return person; | |
} | |
public void setPerson(String person) { | |
this.person = person; | |
} | |
public String getPlace() { | |
return place; | |
} | |
public void setPlace(String place) { | |
this.place = place; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment