|
12 | 12 | import org.jetbrains.annotations.NotNull;
|
13 | 13 | import org.jetbrains.annotations.Nullable;
|
14 | 14 |
|
15 |
| -import java.lang.reflect.Field; |
16 | 15 | import java.lang.reflect.Modifier;
|
17 | 16 | import java.util.*;
|
18 | 17 |
|
@@ -100,18 +99,16 @@ public Item setCustomModelData(int customModelData) {
|
100 | 99 |
|
101 | 100 | @Override
|
102 | 101 | 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 | + }); |
115 | 112 | }
|
116 | 113 |
|
117 | 114 | @Override
|
|
0 commit comments