public boolean applies(Environment e) { | ||||
switch(e.getContext()) { | ||||
case PRIMITIVE: | ||||
switch (matchType) { | ||||
case TRUE: | ||||
return e.osm.isKeyTrue(label) ^ negateResult; | ||||
case FALSE: | ||||
return e.osm.isKeyFalse(label) ^ negateResult; | ||||
case REGEX: | ||||
return e.osm.keySet().stream().anyMatch(containsPattern) ^ negateResult; | ||||
default: | ||||
return e.osm.hasKey(label) ^ negateResult; | ||||
} | ||||
case LINK: | ||||
Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context"); | ||||
return false; | ||||
default: throw new AssertionError(); | ||||
} | ||||
} |
protected void sort() { | ||||
data.sort((c1, c2) -> { | ||||
if (c1.getModificationType().equals(c2.getModificationType())) { | ||||
long id1 = c1.getPrimitive().getId(); | ||||
long id2 = c2.getPrimitive().getId(); | ||||
| ||||
if (id1 == id2) | ||||
return 0; | ||||
else if (id1 < id2) | ||||
return -1; | ||||
return 1; | ||||
} | ||||
switch(c1.getModificationType()) { | ||||
case CREATED: return -1; | ||||
case UPDATED: | ||||
switch(c2.getModificationType()) { | ||||
case CREATED: return 1; | ||||
default: return -1; | ||||
} | ||||
case DELETED: | ||||
return 1; | ||||
} | ||||
// should not happen | ||||
return 0; | ||||
} | ||||
); | ||||
} |