Skip to content

Commit f0ba372

Browse files
committed
Reworked isSimilar method
1 parent f872f67 commit f0ba372

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

item/base/src/main/java/it/angrybear/yagl/items/ItemImpl.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.jetbrains.annotations.NotNull;
1313
import org.jetbrains.annotations.Nullable;
1414

15-
import java.lang.reflect.Field;
1615
import java.lang.reflect.Modifier;
1716
import java.util.*;
1817

@@ -100,18 +99,16 @@ public Item setCustomModelData(int customModelData) {
10099

101100
@Override
102101
public boolean isSimilar(final @Nullable Item item, final ItemField @NotNull ... ignore) {
103-
if (item == null) return false;
104-
main_loop:
105-
for (final Field field : ItemImpl.class.getDeclaredFields()) {
106-
if (Modifier.isStatic(field.getModifiers())) continue;
107-
for (final ItemField f : ignore)
108-
if (field.getName().equalsIgnoreCase(f.name().replace("_", "")))
109-
continue main_loop;
110-
Object obj1 = ReflectionUtils.get(field, this);
111-
Object obj2 = ReflectionUtils.get(field, item);
112-
if (!Objects.equals(obj1, obj2)) return false;
113-
}
114-
return true;
102+
return item != null && Arrays.stream(ItemImpl.class.getDeclaredFields())
103+
.filter(f ->! Modifier.isStatic(f.getModifiers()))
104+
.filter(f -> Arrays.stream(ignore)
105+
.noneMatch(f2 -> f.getName().equalsIgnoreCase(f2.name()
106+
.replace("_", ""))))
107+
.allMatch(f -> {
108+
Object obj1 = ReflectionUtils.get(f, this);
109+
Object obj2 = ReflectionUtils.get(f, item);
110+
return Objects.equals(obj1, obj2);
111+
});
115112
}
116113

117114
@Override

0 commit comments

Comments
 (0)