/** * Merge two lists. All child element will be in the merged list. All parent elements not in the child list will be * added. Mergeable elements in both lists will be merged according to that element merge rules. * @param child the child list to merge * @param parent the parent list to merge * @param addAtEnd if true new items will be added at the end of the list, otherwise the beginning * @return the merged list */ protected <T extends Model> LinkedList<T> merge(LinkedList<T> child, LinkedList<T> parent, boolean addAtEnd) { if (child == null) { return copyList(parent); } if (parent == null) { return child; } if (!addAtEnd) { parent = new LinkedList<>(parent); Collections.reverse(parent); } for (T parentModel : parent) { addOrMerge(child, parentModel, addAtEnd); } return child; }
/** * Merge two lists. All child element will be in the merged list. All parent elements not in the child list will be * added. Mergeable elements in both lists will be merged according to that element merge rules. * @param child the child list to merge * @param parent the parent list to merge * @param addAtEnd if true new items will be added at the end of the list, otherwise the beginning * @return the merged list */ protected <T extends Model> LinkedList<T> merge(LinkedList<T> child, LinkedList<T> parent, boolean addAtEnd) { if (child == null) { return copyList(parent); } if (parent == null) { return child; } if (!addAtEnd) { parent = new LinkedList<>(parent); Collections.reverse(parent); } for (T parentModel : parent) { addOrMerge(child, parentModel, addAtEnd); } return child; }