State newState = (State) newType;
State oldState = (State) oldType;
for(Rule rule : rules) {
for(EventTrigger t : rule.getEventtrigger()) {
if (t instanceof ChangedEventTrigger) {
ChangedEventTrigger ct = (ChangedEventTrigger) t;
if(ct.getItem().equals(item.getName())) {
if(ct.getOldState()!=null) {
State triggerOldState = TypeParser.parseState(item.getAcceptedDataTypes(), ct.getOldState());
if(!oldState.equals(triggerOldState)) {
continue;
}
}
if(ct.getNewState()!=null) {
State triggerNewState = TypeParser.parseState(item.getAcceptedDataTypes(), ct.getNewState());
if(!newState.equals(triggerNewState)) {
continue;
}
}
result.add(rule);
}
}
}
}
}
break;
case COMMAND:
if(newType instanceof Command) {
Command command = (Command) newType;
for(Rule rule : rules) {
for(EventTrigger t : rule.getEventtrigger()) {
if (t instanceof CommandEventTrigger) {
CommandEventTrigger ct = (CommandEventTrigger) t;
Command triggerCommand = TypeParser.parseCommand(item.getAcceptedCommandTypes(), ct.getCommand());
if(ct.getItem().equals(item.getName()) &&
(triggerCommand==null || command.equals(triggerCommand))) {
result.add(rule);
}
}
}