use of org.ambraproject.wombat.model.AmendmentGroup in project wombat by PLOS.
the class ArticleMetadata method buildAmendmentGroups.
/**
* Combine adjacent amendments that have the same type into one AmendmentGroup object, for display purposes. If
* multiple amendments share a type but are separated in order by a different type, they go in separate groups.
*
* @param amendments a list of amendment objects in their desired display order
* @return the amendments grouped by type in the same order
*/
private static List<AmendmentGroup> buildAmendmentGroups(List<Amendment> amendments) {
if (amendments.isEmpty())
return ImmutableList.of();
List<AmendmentGroup> retval = new ArrayList<>(amendments.size());
AmendmentGroup.Builder builder = null;
RelatedArticleType type = null;
for (Amendment amendment : amendments) {
RelatedArticleType nextType = amendment.getType();
if (builder == null || !Objects.equals(type, nextType)) {
if (builder != null) {
retval.add(builder.build());
}
builder = AmendmentGroup.builder().setType(nextType);
type = nextType;
}
builder.addAmendment(amendment);
}
retval.add(builder.build());
return retval;
}
Aggregations