Search in sources :

Example 1 with Amendment

use of org.ambraproject.wombat.model.Amendment 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;
}
Also used : Amendment(org.ambraproject.wombat.model.Amendment) RelatedArticleType(org.ambraproject.wombat.model.RelatedArticleType) ArrayList(java.util.ArrayList) AmendmentGroup(org.ambraproject.wombat.model.AmendmentGroup)

Aggregations

ArrayList (java.util.ArrayList)1 Amendment (org.ambraproject.wombat.model.Amendment)1 AmendmentGroup (org.ambraproject.wombat.model.AmendmentGroup)1 RelatedArticleType (org.ambraproject.wombat.model.RelatedArticleType)1