+ if (fragmentExtracts != null) {
+ for (final FragmentExtract fragmentExtract : fragmentExtracts) {
+ final FragmentEntity fragmentEntity = toFragmentEntity(anchorEntity, fragmentExtract);
+ fragmentEntityPerId.put(fragmentEntity.getId(), fragmentEntity);
+ }
+ }
+ return reuniteChildrenWithTheirParents(fragmentEntityPerId);
+ }
+
+ /**
+ * Convert a collection of (related) FragmentExtracts into FragmentEntities (trees) with descendants.
+ *
+ * @param anchorEntityPerId the anchor(entities) the fragments belong to
+ * @param fragmentExtracts FragmentExtracts to convert
+ * @return a collection of FragmentEntities (trees) with descendants.
+ */
+ public static Collection<FragmentEntity> toFragmentEntityTreesAcrossAnchors(
+ final Map<Integer, AnchorEntity> anchorEntityPerId, final Collection<FragmentExtract> fragmentExtracts) {
+ final Map<Long, FragmentEntity> fragmentEntityPerId = new HashMap<>();