13
0
geforkt von Mirrors/Paper

[Bleeding] Removing the last metadata item for a key now sets hasMetadata(key) to false. Addresses BUKKIT-1380

By: rmichela <deltahat@gmail.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-03-28 01:41:33 -04:00
Ursprung 853f14f0dc
Commit cc95e9f5ef
2 geänderte Dateien mit 12 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -86,6 +86,9 @@ public abstract class MetadataStoreBase<T> {
for (int i = 0; i < metadataList.size(); i++) { for (int i = 0; i < metadataList.size(); i++) {
if (metadataList.get(i).getOwningPlugin().equals(owningPlugin)) { if (metadataList.get(i).getOwningPlugin().equals(owningPlugin)) {
metadataList.remove(i); metadataList.remove(i);
if (metadataList.isEmpty()) {
metadataMap.remove(key);
}
} }
} }
} }

Datei anzeigen

@ -96,6 +96,15 @@ public class MetadataStoreTest {
assertEquals(20, subject.getMetadata("subject", "key").get(0).value()); assertEquals(20, subject.getMetadata("subject", "key").get(0).value());
} }
@Test
public void testMetadataRemoveLast() {
subject.setMetadata("subject", "key", new FixedMetadataValue(pluginX, 10));
subject.removeMetadata("subject", "key", pluginX);
assertFalse(subject.hasMetadata("subject", "key"));
assertEquals(0, subject.getMetadata("subject", "key").size());
}
@Test @Test
public void testMetadataRemoveForNonExistingPlugin() { public void testMetadataRemoveForNonExistingPlugin() {
subject.setMetadata("subject", "key", new FixedMetadataValue(pluginX, 10)); subject.setMetadata("subject", "key", new FixedMetadataValue(pluginX, 10));