@Test public void testEquals() { Payload event = new Payload(); event.addStatement(Statement.AND, "number", Statement.EQUALS, "1"); event.addStatement(Statement.AND, "text", Statement.EQUALS, "abc"); event.addStatement(Statement.AND, "testRegex", Statement.EQUALS, "EnvObject.ElectricDevice.Light"); Payload trigger = new Payload(); trigger.addStatement(Statement.AND, "number", Statement.EQUALS, "1"); trigger.addStatement(Statement.AND, "number", Statement.EQUALS, Statement.ANY); trigger.addStatement(Statement.AND, "event.number", Statement.EQUALS, "123"); trigger.addStatement("SET", "defineANewProperty", Statement.EQUALS, "123"); trigger.addStatement(Statement.AND, "testRegex", Statement.REGEX, "^EnvObject.ElectricDevice\\.(.*)"); boolean expResult = true; boolean result = trigger.equals(event); assertEquals(expResult, result); }
@Override public boolean equals(Object obj) { boolean payloadConsistence = true; if (obj instanceof Payload) { Payload eventPayload = (Payload) obj; Iterator<Statement> it = payloadLst.iterator(); while (it.hasNext()) { Statement triggerStatement = it.next(); if (triggerStatement.getAttribute().startsWith("event.")) { continue; } List<Statement> filteredEventStatements = eventPayload.getStatements(triggerStatement.getAttribute()); if (filteredEventStatements.isEmpty()) { if (!triggerStatement.getLogical().equalsIgnoreCase(Statement.SET)) { return false; } if (triggerStatement.getValue().equalsIgnoreCase(Statement.ANY)) { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = false; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || false; } } } } else { for (Statement eventStatement : filteredEventStatements) { if (eventStatement != null) { if ("SET".equalsIgnoreCase(triggerStatement.getLogical())) { return true; } else { boolean isStatementConsistent = isStatementConsistent(triggerStatement.getOperand(), triggerStatement.getValue(), eventStatement.getValue()); if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = payloadConsistence && isStatementConsistent; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || isStatementConsistent; } } } } } } } } else { payloadConsistence = false; } return payloadConsistence; }
Payload implements Serializable { @Override public boolean equals(Object obj) { boolean payloadConsistence = true; if (obj instanceof Payload) { Payload eventPayload = (Payload) obj; Iterator<Statement> it = payloadLst.iterator(); while (it.hasNext()) { Statement triggerStatement = it.next(); if (triggerStatement.getAttribute().startsWith("event.")) { continue; } List<Statement> filteredEventStatements = eventPayload.getStatements(triggerStatement.getAttribute()); if (filteredEventStatements.isEmpty()) { if (!triggerStatement.getLogical().equalsIgnoreCase(Statement.SET)) { return false; } if (triggerStatement.getValue().equalsIgnoreCase(Statement.ANY)) { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = false; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || false; } } } } else { for (Statement eventStatement : filteredEventStatements) { if (eventStatement != null) { if ("SET".equalsIgnoreCase(triggerStatement.getLogical())) { return true; } else { boolean isStatementConsistent = isStatementConsistent(triggerStatement.getOperand(), triggerStatement.getValue(), eventStatement.getValue()); if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = payloadConsistence && isStatementConsistent; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || isStatementConsistent; } } } } } } } } else { payloadConsistence = false; } return payloadConsistence; } }
Payload implements Serializable { @Override public boolean equals(Object obj) { boolean payloadConsistence = true; if (obj instanceof Payload) { Payload eventPayload = (Payload) obj; Iterator<Statement> it = payloadLst.iterator(); while (it.hasNext()) { Statement triggerStatement = it.next(); if (triggerStatement.getAttribute().startsWith("event.")) { continue; } List<Statement> filteredEventStatements = eventPayload.getStatements(triggerStatement.getAttribute()); if (filteredEventStatements.isEmpty()) { if (!triggerStatement.getLogical().equalsIgnoreCase(Statement.SET)) { return false; } if (triggerStatement.getValue().equalsIgnoreCase(Statement.ANY)) { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = false; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || false; } } } } else { for (Statement eventStatement : filteredEventStatements) { if (eventStatement != null) { if ("SET".equalsIgnoreCase(triggerStatement.getLogical())) { return true; } else { boolean isStatementConsistent = isStatementConsistent(triggerStatement.getOperand(), triggerStatement.getValue(), eventStatement.getValue()); if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = payloadConsistence && isStatementConsistent; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || isStatementConsistent; } } } } } } } } else { payloadConsistence = false; } return payloadConsistence; }  }
Payload implements Serializable { @Override public boolean equals(Object obj) { boolean payloadConsistence = true; if (obj instanceof Payload) { Payload eventPayload = (Payload) obj; Iterator<Statement> it = payloadLst.iterator(); while (it.hasNext()) { Statement triggerStatement = it.next(); if (triggerStatement.getAttribute().startsWith("event.")) { continue; } List<Statement> filteredEventStatements = eventPayload.getStatements(triggerStatement.getAttribute()); if (filteredEventStatements.isEmpty()) { if (!triggerStatement.getLogical().equalsIgnoreCase(Statement.SET)) { return false; } if (triggerStatement.getValue().equalsIgnoreCase(Statement.ANY)) { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = false; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || false; } } } } else { for (Statement eventStatement : filteredEventStatements) { if (eventStatement != null) { if ("SET".equalsIgnoreCase(triggerStatement.getLogical())) { return true; } else { boolean isStatementConsistent = isStatementConsistent(triggerStatement.getOperand(), triggerStatement.getValue(), eventStatement.getValue()); if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = payloadConsistence && isStatementConsistent; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || isStatementConsistent; } } } } } } } } else { payloadConsistence = false; } return payloadConsistence; }  void addStatement(String logical, String attribute, String operand, String value); void addStatement(String attribute, String value); void addStatement(String attribute, int value); void enqueueStatement(Statement s); int size(); @Override boolean equals(Object obj); @Override int hashCode(); List<Statement> getStatements(String attribute); List<Statement> getStatements(); String getStatementsAsJson(); String getStatementValue(String attribute); Iterator<Statement> iterator(); void merge(Payload anotherPayload); @Override String toString(); void clear(); }
Payload implements Serializable { @Override public boolean equals(Object obj) { boolean payloadConsistence = true; if (obj instanceof Payload) { Payload eventPayload = (Payload) obj; Iterator<Statement> it = payloadLst.iterator(); while (it.hasNext()) { Statement triggerStatement = it.next(); if (triggerStatement.getAttribute().startsWith("event.")) { continue; } List<Statement> filteredEventStatements = eventPayload.getStatements(triggerStatement.getAttribute()); if (filteredEventStatements.isEmpty()) { if (!triggerStatement.getLogical().equalsIgnoreCase(Statement.SET)) { return false; } if (triggerStatement.getValue().equalsIgnoreCase(Statement.ANY)) { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = false; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || false; } } } } else { for (Statement eventStatement : filteredEventStatements) { if (eventStatement != null) { if ("SET".equalsIgnoreCase(triggerStatement.getLogical())) { return true; } else { boolean isStatementConsistent = isStatementConsistent(triggerStatement.getOperand(), triggerStatement.getValue(), eventStatement.getValue()); if (triggerStatement.getLogical().equalsIgnoreCase(Statement.AND)) { payloadConsistence = payloadConsistence && isStatementConsistent; } else { if (triggerStatement.getLogical().equalsIgnoreCase(Statement.OR)) { payloadConsistence = payloadConsistence || isStatementConsistent; } } } } } } } } else { payloadConsistence = false; } return payloadConsistence; }  void addStatement(String logical, String attribute, String operand, String value); void addStatement(String attribute, String value); void addStatement(String attribute, int value); void enqueueStatement(Statement s); int size(); @Override boolean equals(Object obj); @Override int hashCode(); List<Statement> getStatements(String attribute); List<Statement> getStatements(); String getStatementsAsJson(); String getStatementValue(String attribute); Iterator<Statement> iterator(); void merge(Payload anotherPayload); @Override String toString(); void clear();  }