package model; import java.util.LinkedList; import java.util.List; public class NewsCollection extends Item { private final List items = new LinkedList<>(); public NewsCollection(String title) { this.title = title; } /** * Gets overview information about all directly or transitively * referenced items in the given collection. */ public String getOverview(){ StringBuilder builder = new StringBuilder(); builder .append("###").append(getTitle()).append("###") .append("\n"); for(Item item : getItems()){ builder .append(item.getOverview()) .append("\n"); } return builder.toString(); } /** * Gets the contents of all directly or transitively referenced items in * the given collection. */ public String getDetails(){ StringBuilder builder = new StringBuilder(); builder .append("###").append(getTitle()).append("###") .append("\n"); for (Item item : getItems()) { builder.append(item.getDetails()); } return builder.toString(); } //================================= /** * Get the list of items stored directly in this collection. * @return items stored in this collection */ public List getItems() { return items; } /** * Store an item directly in this collection. * @param item to add * @return this collection (enables method chaining) */ public NewsCollection addItem(Item item) { items.add(item); return this; } }