#845: Remove unnecessary calls to Class#getSimpleName in PDC

By: Wesley Smith <me@wesjd.net>
This commit is contained in:
CraftBukkit/Spigot 2021-05-21 08:25:09 +10:00
parent 9111166484
commit d8a90faeb1

View file

@ -19,7 +19,6 @@ import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagLongArray;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import org.apache.commons.lang3.Validate;
import org.bukkit.persistence.PersistentDataContainer;
/**
@ -57,7 +56,9 @@ public final class CraftPersistentDataTypeRegistry {
* extractor function
*/
T extract(NBTBase base) {
Validate.isInstanceOf(nbtBaseType, base, "The provided NBTBase was of the type %s. Expected type %s", base.getClass().getSimpleName(), nbtBaseType.getSimpleName());
if (!nbtBaseType.isInstance(base)) {
throw new IllegalArgumentException(String.format("The provided NBTBase was of the type %s. Expected type %s", base.getClass().getSimpleName(), nbtBaseType.getSimpleName()));
}
return this.extractor.apply(nbtBaseType.cast(base));
}
@ -73,7 +74,9 @@ public final class CraftPersistentDataTypeRegistry {
* function
*/
Z build(Object value) {
Validate.isInstanceOf(primitiveType, value, "The provided value was of the type %s. Expected type %s", value.getClass().getSimpleName(), primitiveType.getSimpleName());
if (!primitiveType.isInstance(value)) {
throw new IllegalArgumentException(String.format("The provided value was of the type %s. Expected type %s", value.getClass().getSimpleName(), primitiveType.getSimpleName()));
}
return this.builder.apply(primitiveType.cast(value));
}
@ -247,10 +250,14 @@ public final class CraftPersistentDataTypeRegistry {
*/
public <T> T extract(Class<T> type, NBTBase tag) throws ClassCastException, IllegalArgumentException {
TagAdapter adapter = this.adapters.computeIfAbsent(type, CREATE_ADAPTER);
Validate.isTrue(adapter.isInstance(tag), "`The found tag instance cannot store %s as it is a %s", type.getSimpleName(), tag.getClass().getSimpleName());
if (!adapter.isInstance(tag)) {
throw new IllegalArgumentException(String.format("`The found tag instance cannot store %s as it is a %s", type.getSimpleName(), tag.getClass().getSimpleName()));
}
Object foundValue = adapter.extract(tag);
Validate.isInstanceOf(type, foundValue, "The found object is of the type %s. Expected type %s", foundValue.getClass().getSimpleName(), type.getSimpleName());
if (!type.isInstance(foundValue)) {
throw new IllegalArgumentException(String.format("The found object is of the type %s. Expected type %s", foundValue.getClass().getSimpleName(), type.getSimpleName()));
}
return type.cast(foundValue);
}
}