Skip to content

Commit

Permalink
Reworked isSimilar method
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 8, 2024
1 parent f872f67 commit f0ba372
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0ba372

Please sign in to comment.