in polaris-synchronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/planning/ModificationAwarePlanner.java [189:222]
private <T> FilteredNotModifiedEntityResult<T> filterOutEntitiesNotModified(
Collection<T> entitiesOnSource,
Collection<T> entitiesOnTarget,
Function<T, Object> entityIdentifierSupplier,
BiFunction<T, T, Boolean> entitiesAreSame
) {
Map<Object, T> sourceEntitiesById = new HashMap<>();
Map<Object, T> targetEntitiesById = new HashMap<>();
List<T> notModifiedEntities = new ArrayList<>();
entitiesOnSource.forEach(entity -> sourceEntitiesById.put(entityIdentifierSupplier.apply(entity), entity));
entitiesOnTarget.forEach(entity -> targetEntitiesById.put(entityIdentifierSupplier.apply(entity), entity));
for (T sourceEntity : entitiesOnSource) {
Object sourceEntityId = entityIdentifierSupplier.apply(sourceEntity);
if (targetEntitiesById.containsKey(sourceEntityId)) {
T targetEntity = targetEntitiesById.get(sourceEntityId);
Object targetEntityId = entityIdentifierSupplier.apply(targetEntity);
if (entitiesAreSame.apply(sourceEntity, targetEntity)) {
notModifiedEntities.add(sourceEntity);
sourceEntitiesById.remove(sourceEntityId);
targetEntitiesById.remove(targetEntityId);
}
}
}
return new FilteredNotModifiedEntityResult<>(
sourceEntitiesById.values().stream().toList(),
targetEntitiesById.values().stream().toList(),
notModifiedEntities
);
}