Files
JustEnoughCalculation/src/main/java/me/towdium/jecalculation/data/structure/Recents.java
T
2021-04-30 23:53:58 +08:00

46 lines
1.4 KiB
Java

package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
public class Recents {
public static final String IDENTIFIER = "recent";
Utilities.Recent<ILabel> record = new Utilities.Recent<>((a, b) -> a == ILabel.EMPTY || a.equals(b), 9);
public Recents(NBTTagList nbt) {
List<ILabel> ls = StreamSupport.stream(NBTHelper.spliterator(nbt), false)
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.DESERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
new Utilities.ReversedIterator<>(ls).forEachRemaining(l -> record.push(l));
}
public Recents() {
}
public void push(ILabel label) {
record.push(label);
}
public ILabel getLatest() {
return record.toList().get(0);
}
public List<ILabel> getRecords() {
return record.toList();
}
public NBTTagList serialize() {
NBTTagList ret = new NBTTagList();
record.toList().forEach(l -> ret.appendTag(ILabel.DESERIALIZER.serialize(l)));
return ret;
}
}