com.kenshoo.pl.entity.Hierarchy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toSet;
import static org.jooq.lambda.Seq.seq;
class Hierarchy {
private final EntityType> root;
private final Set, EntityType>>> parentChildRelations;
private Hierarchy(EntityType> root, Set, EntityType>>> parentChildRelations) {
this.root = root;
this.parentChildRelations = parentChildRelations;
}
static Hierarchy build(ChangeFlowConfig rootFlow) {
Set, EntityType>>> relations = getRelationsRecursively(rootFlow).collect(toSet());
return new Hierarchy(rootFlow.getEntityType(), relations);
}
Collection extends EntityType>> childrenTypes(EntityType> parent) {
return seq(parentChildRelations)
.filter(pair -> pair.getLeft().equals(parent))
.map(Pair::getRight)
.toList();
}
EntityType> root() {
return root;
}
boolean contains(EntityField, ?> field) {
return seq(parentChildRelations).anyMatch(
pair -> field.getEntityType().equals(pair.getLeft()) ||
field.getEntityType().equals(pair.getRight())
);
}
private static Stream, EntityType>>> getRelationsRecursively(ChangeFlowConfig> flow) {
Stream, EntityType>>> myRelations = flow.childFlows().stream().map(childFlow -> Pair.of(flow.getEntityType(), childFlow.getEntityType()));
return Stream.concat(myRelations, flow.childFlows().stream().flatMap(f -> getRelationsRecursively(f)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy