Use ImmutableList rather than AbstractList for CraftMetaBook

Although the AbstracList implementation does return a list, it is a
of a form that does not play well with libraries using reflection,
such as Gson. Leveraging a stream and the ImmutableList collector,
this process is greatly simplified (and cleaner).
This commit is contained in:
Javacraft 2018-12-05 19:44:07 -05:00 committed by md_5
parent 5f5a6767e8
commit ad7b00b762

View file

@ -256,19 +256,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
}
public List<String> getPages() {
final List<IChatBaseComponent> copy = ImmutableList.copyOf(pages);
return new AbstractList<String>() {
@Override
public String get(int index) {
return CraftChatMessage.fromComponent(copy.get(index));
}
@Override
public int size() {
return copy.size();
}
};
return pages.stream().map(CraftChatMessage::fromComponent).collect(ImmutableList.toImmutableList());
}
public void setPages(List<String> pages) {