Move RPEntity.nameMatches to static Item.nameMatches
This commit is contained in:
parent
3845fc69da
commit
3e5d472bc3
2 changed files with 18 additions and 17 deletions
|
|
@ -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<Item> 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<Item> 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<Item> getAllEquipped(final String name) {
|
||||
return getAllEquipped(nameMatches(name));
|
||||
return getAllEquipped(Item.nameMatches(name));
|
||||
}
|
||||
|
||||
private List<Item> getAllEquipped(Predicate<Item> 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<Item> nameMatches(String name) {
|
||||
return it -> name.equalsIgnoreCase(it.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute to define the shadow that the client should use.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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<Item> nameMatches(String name) {
|
||||
return item -> name.equalsIgnoreCase(item.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue