Refactor LocatedItems to use the function addItem() instead of

initItemsIfNull().
This commit is contained in:
Assaf 2018-07-17 15:47:21 +03:00 committed by Ben Gruver
parent af8bc1d9cd
commit 1bf8f2544b

View File

@ -13,12 +13,6 @@ public abstract class LocatedItems<T extends ItemWithLocation> {
@Nullable
private List<T> items = null;
private void initItemsIfNull() {
if (items == null) {
items = new ArrayList<>(1);
}
}
@Nonnull
private List<T> getItems() {
if (items == null) {
@ -70,13 +64,19 @@ public abstract class LocatedItems<T extends ItemWithLocation> {
throw new IllegalArgumentException(getAddLocatedItemError());
}
item.setLocation(newItemsLocation);
initItemsIfNull();
items.add(item);
addItem(item);
return true;
}
};
}
private void addItem(@Nonnull T item) {
if (items == null) {
items = new ArrayList<>(1);
}
items.add(item);
}
protected abstract String getAddLocatedItemError();
public void mergeItemsIntoNext(@Nonnull MethodLocation nextLocation, LocatedItems<T> otherLocatedItems) {