diff --git a/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/raid/RAID.java b/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/raid/RAID.java index 74a871d..e84b101 100644 --- a/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/raid/RAID.java +++ b/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/raid/RAID.java @@ -1,10 +1,8 @@ package cz.tefek.pluto.io.asl.resource.raid; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.*; /** * Runtime Assigned ID (or Resource Address ID) @@ -13,9 +11,9 @@ public class RAID implements Iterable { private static final int INITIAL_SIZE = 512; - private List raid; + private final List raid; - private Map reverseRaid; + private final Map reverseRaid; public RAID() { @@ -38,6 +36,7 @@ public class RAID implements Iterable item.onRegister(pos); } + @Nullable public E getByIntID(int id) { if (id < 0 || id >= this.raid.size()) @@ -48,11 +47,16 @@ public class RAID implements Iterable return this.raid.get(id); } - public int getIDOf(E item) + @Nonnull + public OptionalInt getIDOf(E item) { - return this.reverseRaid.get(item.getStringID()); + return reverseRaid.containsKey(item.getStringID()) ? + OptionalInt.of(reverseRaid.get(item.getStringID())) + : + OptionalInt.empty(); } + @Nonnull @Override public Iterator iterator() {