From f0ba372adee4969c772ce94ba1c7aa9da25b86fa Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Mon, 8 Apr 2024 03:11:15 +0200 Subject: [PATCH] Reworked isSimilar method --- .../it/angrybear/yagl/items/ItemImpl.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java b/item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java index ec6cd2e3..9a256eb5 100644 --- a/item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java +++ b/item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java @@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; @@ -100,18 +99,16 @@ public Item setCustomModelData(int customModelData) { @Override public boolean isSimilar(final @Nullable Item item, final ItemField @NotNull ... ignore) { - if (item == null) return false; - main_loop: - for (final Field field : ItemImpl.class.getDeclaredFields()) { - if (Modifier.isStatic(field.getModifiers())) continue; - for (final ItemField f : ignore) - if (field.getName().equalsIgnoreCase(f.name().replace("_", ""))) - continue main_loop; - Object obj1 = ReflectionUtils.get(field, this); - Object obj2 = ReflectionUtils.get(field, item); - if (!Objects.equals(obj1, obj2)) return false; - } - return true; + return item != null && Arrays.stream(ItemImpl.class.getDeclaredFields()) + .filter(f ->! Modifier.isStatic(f.getModifiers())) + .filter(f -> Arrays.stream(ignore) + .noneMatch(f2 -> f.getName().equalsIgnoreCase(f2.name() + .replace("_", "")))) + .allMatch(f -> { + Object obj1 = ReflectionUtils.get(f, this); + Object obj2 = ReflectionUtils.get(f, item); + return Objects.equals(obj1, obj2); + }); } @Override