@ -69,12 +69,14 @@ public class Facts implements Iterable<Map.Entry<String, Object>> {
/**
* Get a fact by name.
*
* @param name of fact to get.
* @param name of the fact
* @param <T> type of the fact
* @return the fact having the given name, or null if there is no fact with the given name
*/
public Object get(String name) {
@SuppressWarnings("unchecked")
public <T> T get(String name) {
Objects.requireNonNull(name);
return facts.get(name);
return (T) facts.get(name);
}
@ -17,7 +17,7 @@ public class AirConditioningRule {
@Action
public void coolAir(Facts facts) {
System.out.println("It is hot! cooling air..");
Integer temperature = (Integer) facts.get("temperature");
Integer temperature = facts.get("temperature");
facts.put("temperature", temperature - 1);
@ -36,13 +36,13 @@ public class AgeRule extends BasicRule {
@Override
public boolean evaluate(Facts facts) {
Person person = (Person) facts.get("person");
Person person = facts.get("person");
return person.getAge() > ADULT_AGE;
public void execute(Facts facts) {
person.setAdult(true);
System.out.printf("Person %s has been marked as adult", person.getName());
System.out.println();
@ -34,13 +34,13 @@ public class AlcoholRule extends BasicRule {
return !person.isAdult();
public void execute(Facts facts){
System.out.printf("Shop: Sorry %s, you are not allowed to buy alcohol", person.getName());