if (projections.size() != 2) return null;
Projection first = projections.get(0);
Projection second = projections.get(1);
if (first.getRules().size() != 1) return null;
if (second.getRules().size() != 1) return null;
Rule firstRule = first.getRules().get(0);
Rule secondRule = second.getRules().get(0);
assert firstRule != null;
assert secondRule != null;
PathFactory pathFactory = context.getValueFactories().getPathFactory();
List<Path> firstTopLevelPaths = first.getRules().get(0).getTopLevelPathsInRepository(pathFactory);
if (firstTopLevelPaths.size() != 1) return null;
List<Path> secondTopLevelPaths = second.getRules().get(0).getTopLevelPathsInRepository(pathFactory);
if (secondTopLevelPaths.size() != 1) return null;
Path firstTopLevelPath = firstTopLevelPaths.get(0);
Path secondTopLevelPath = secondTopLevelPaths.get(0);
if (firstTopLevelPath.isRoot()) {
// We're good, so create the instance ...
return new BranchedMirrorProjector(context, projections, first, second, secondTopLevelPath,
secondRule.getPathInSource(secondTopLevelPath, pathFactory));
}
// the second top-level path must be a root ...
if (!secondTopLevelPath.isRoot()) return null;
// We're good, so create the instance ...
return new BranchedMirrorProjector(context, projections, second, first, firstTopLevelPath,