in query/src/main/kotlin/jetbrains/exodus/query/QueryEngine.kt [54:102]
open fun intersect(left: Iterable<Entity>, right: Iterable<Entity>): Iterable<Entity> {
if (left === right) {
return left
}
if (left.isEmpty || right.isEmpty) {
return EMPTY
}
if (left is TreeKeepingEntityIterable) {
val leftType = left.getEntityType()
if (right is TreeKeepingEntityIterable) {
if (left.instance === right.instance) {
val rightType = right.getEntityType()
if (isTypeOf(leftType, rightType, modelMetaData.notNull)) {
return TreeKeepingEntityIterable(
right.instance, leftType,
And.and(left.tree, right.tree), left.annotatedTree, right.annotatedTree, this
)
} else if (isTypeOf(rightType, leftType, modelMetaData.notNull)) {
return TreeKeepingEntityIterable(
right.instance, rightType,
And.and(left.tree, right.tree), left.annotatedTree, right.annotatedTree, this
)
}
}
}
}
var staticType: String? = null
if (left is StaticTypedEntityIterable) {
val leftType = left.getEntityType()
if (right is StaticTypedEntityIterable) {
val rightType = right.getEntityType()
if (isTypeOf(rightType, leftType, modelMetaData.notNull)) {
staticType = rightType
} else if (isTypeOf(leftType, rightType, modelMetaData.notNull)) {
staticType = leftType
}
if (leftType == rightType) {
if (left.isGetAllTree) {
return ExcludeNullStaticTypedEntityIterable(rightType, right, this)
}
if (right.isGetAllTree) {
return ExcludeNullStaticTypedEntityIterable(leftType, left, this)
}
}
}
}
val result = intersectNonTrees(instantiateAndAdjust(left), instantiateAndAdjust(right))
return staticType?.let { StaticTypedIterableDecorator(staticType, result, this) } ?: result
}