I have List of log events that I shoud check, that they are the same as should be. There is structure of Event object:
public class Event {
public String type;
public List<Item> items;
public Event(String type, List<Item> items) {
this.type = type;
this.items = items;
}
}
public class Item {
public String id;
public String value;
public Item(String id, String value) {
this.id = id;
this.value = value;
}
}
Lets fill "should" object, "real" object and check that they have same items
List<Event> should = asList(
new Event("1000", asList(new Item("server_id", "1"), new Item("user_id", "11"))),
new Event("1000", asList(new Item("server_id", "1"), new Item("user_id", "11"))));
List<Event> logged = asList(
new Event("1000", asList(new Item("server_id", "1"), new Item("user_id", "11"))),
new Event("1000", asList(new Item("server_id", "1"), new Item("user_id", "11"))));
boolean logMatch = logged.stream()
.allMatch(e1 ->
should.stream()
.allMatch(e2 -> e2.items
.stream()
.allMatch(a2 -> e1.items
.stream()
.anyMatch(a1 -> a1.value.equals(a2.value)))));
System.out.println(logMatch);
It's true, but I have an issue, if I change any value of "should" to "11", I'll get true. How can I fix this or how to make this comparison simpler?