diff --git a/src/games/stendhal/server/entity/RPEntity.java b/src/games/stendhal/server/entity/RPEntity.java index 767a1f5c06..109111de2a 100644 --- a/src/games/stendhal/server/entity/RPEntity.java +++ b/src/games/stendhal/server/entity/RPEntity.java @@ -2138,7 +2138,7 @@ public abstract class RPEntity extends CombatEntity { * @return true iff dropping the desired amount was successful. */ public boolean drop(final String name, final int amount) { - return drop(nameMatches(name), amount); + return drop(Item.nameMatches(name), amount); } private boolean isEquipped(Predicate condition, int amount) { @@ -2277,7 +2277,7 @@ public abstract class RPEntity extends CombatEntity { * number. */ public boolean isEquipped(final String name, final int amount) { - return isEquipped(nameMatches(name), amount); + return isEquipped(Item.nameMatches(name), amount); } /** @@ -2331,7 +2331,7 @@ public abstract class RPEntity extends CombatEntity { * @return The number of carried items */ public int getNumberOfEquipped(final String name) { - return equippedStream().filter(nameMatches(name)) + return equippedStream().filter(Item.nameMatches(name)) .mapToInt(Item::getQuantity).sum(); } @@ -2345,7 +2345,7 @@ public abstract class RPEntity extends CombatEntity { */ public int getTotalNumberOf(final String name) { Stream allItems = slots().stream().flatMap(this::slotStream); - return allItems.filter(nameMatches(name)).mapToInt(Item::getQuantity).sum(); + return allItems.filter(Item.nameMatches(name)).mapToInt(Item::getQuantity).sum(); } /** @@ -2358,7 +2358,7 @@ public abstract class RPEntity extends CombatEntity { * found */ public Item getFirstEquipped(final String name) { - return equippedStream().filter(nameMatches(name)).findFirst().orElse(null); + return equippedStream().filter(Item.nameMatches(name)).findFirst().orElse(null); } /** @@ -2371,7 +2371,7 @@ public abstract class RPEntity extends CombatEntity { * found */ public List getAllEquipped(final String name) { - return getAllEquipped(nameMatches(name)); + return getAllEquipped(Item.nameMatches(name)); } private List getAllEquipped(Predicate condition) { @@ -3459,16 +3459,6 @@ public abstract class RPEntity extends CombatEntity { return slots.flatMap(this::slotStream); } - /** - * A convenience method for getting a method for matching item names. - * - * @param name name to match - * @return a predicate for matching the name - */ - private Predicate nameMatches(String name) { - return it -> name.equalsIgnoreCase(it.getName()); - } - /** * Sets the attribute to define the shadow that the client should use. * diff --git a/src/games/stendhal/server/entity/item/Item.java b/src/games/stendhal/server/entity/item/Item.java index f262176b37..4ddfe6908a 100644 --- a/src/games/stendhal/server/entity/item/Item.java +++ b/src/games/stendhal/server/entity/item/Item.java @@ -17,6 +17,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; import org.apache.log4j.Logger; @@ -1036,5 +1037,15 @@ public class Item extends PassiveEntity implements TurnListener, EquipListener, return false; } - + /** + * A convenience method for getting a method for matching item names. + * + * @param name + * Item name to match. + * @return + * A predicate for matching the name. + */ + public static Predicate nameMatches(String name) { + return item -> name.equalsIgnoreCase(item.getName()); + } }