wyvern.lib.commands
Class ItemDesc

java.lang.Object
  extended bywyvern.lib.commands.ItemDesc

public class ItemDesc
extends java.lang.Object

This class encapsulates an item description, including the string description and the item number. When a user types "get key 3", "key" is the string description and the item number is 3. Used by commands that have to know about such things.

Version:
1.0, Sep 15, 1999
Author:
Steve Yegge

Field Summary
protected  java.lang.String desc_
           
protected  int number_
           
 
Constructor Summary
ItemDesc(java.lang.String desc, int num)
          Constructs a new ItemDesc
 
Method Summary
 java.lang.String getDescription()
          Returns the description parsed from getItemNumber().
 int getItemNumber()
          Returns the item number parsed from getItemNumber().
static ItemDesc getItemNumber(java.lang.String desc)
          Returns an ItemDesc for this item, if needed.
static Predicate getNameMatchPredicate(java.lang.String desc)
          Takes an object description and returns a predicate suitable for finding it.
static void main(java.lang.String[] args)
          Used for testing only.
 void setDescription(java.lang.String desc)
          Sets a new description for this ItemDesc.
 void setItemNumber(int num)
          Sets the item number for this ItemDesc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

number_

protected int number_

desc_

protected java.lang.String desc_
Constructor Detail

ItemDesc

public ItemDesc(java.lang.String desc,
                int num)
Constructs a new ItemDesc

Parameters:
desc - the description, without the item number
num - the item number, a positive integer.
Method Detail

setItemNumber

public void setItemNumber(int num)
Sets the item number for this ItemDesc.

Parameters:
num - a positive integer

getItemNumber

public int getItemNumber()
Returns the item number parsed from getItemNumber().

Returns:
a positive integer

getDescription

public java.lang.String getDescription()
Returns the description parsed from getItemNumber().

Returns:
the item description with the item number taken off

setDescription

public void setDescription(java.lang.String desc)
Sets a new description for this ItemDesc.

Parameters:
desc - the new description

getItemNumber

public static ItemDesc getItemNumber(java.lang.String desc)
Returns an ItemDesc for this item, if needed. (I.e. if there was an item number specified in the description).

Parameters:
desc - the item description
Returns:
an ItemDesc with the item number and description set properly, if appropriate. Returns null if there was no item number at the end of the description. Valid item numbers are positive integers, so "key 0" would not return an ItemDesc.

getNameMatchPredicate

public static Predicate getNameMatchPredicate(java.lang.String desc)
Takes an object description and returns a predicate suitable for finding it. If the description is "ordinary", in that it doesn't have a number at the end, then this method just returns a NameMatchPredicate for the description. If the description is in the format "desc NN", where NN is some positive integer >= 1, then the method returns a CounterPredicate with count set to N and the predicate set to a NameMatchPredicate on the "desc" part of the description.

Parameters:
desc - an object description, which may or may not have an item number at the end.
Returns:
a predicate suitable for finding the object.

main

public static void main(java.lang.String[] args)
Used for testing only.