com.planet_ink.coffee_mud.Common
Class WeakItemCollection

java.lang.Object
  extended by com.planet_ink.coffee_mud.Common.WeakItemCollection
All Implemented Interfaces:
CMCommon, CMObject, ItemCollection, java.lang.Cloneable, java.lang.Comparable<CMObject>

public class WeakItemCollection
extends java.lang.Object
implements ItemCollection, CMCommon

Abstract collection of item objects, complete with some finders and various accessors. Also, the copyOf method does a deep copy. Also, this is a weak item collection, so as items get destroyed, they disappear from here.


Constructor Summary
WeakItemCollection()
           
 
Method Summary
 void addItem(Item item)
          Adds a new item to its possessor.
 int compareTo(CMObject o)
           
 CMObject copyOf()
          Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.
 void delAllItems(boolean destroy)
          Removes all items from this collection
 void delItem(Item item)
          Removes the item from this possessor.
 void eachItem(EachApplicable<Item> applier)
          Applies the given code to each item in this collection
 Item findItem(Item goodLocation, java.lang.String itemID)
          Returns the item in the given container that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller name is found).
 Item findItem(java.lang.String itemID)
          Returns the item in this possessor that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller name is found).
 java.util.List<Item> findItems(Item goodLocation, java.lang.String itemID)
          Returns all items in the given container that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller names are found).
 java.util.List<Item> findItems(java.lang.String itemID)
          Returns all items in this possessor that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller names are found).
 Item getItem(int i)
          Returns the item at the given index, regardless of container status, visibility, or other modifiers.
 Item getRandomItem()
          Returns a random item in this collection, or null
 java.lang.String ID()
          The CoffeeMud Java Class ID shared by all instances of this object.
 void initializeClass()
          Called ONCE after all objects are loaded, but before the map is read in during initialization.
 boolean isContent(Item item)
          Returns whether the given item is in this possessors list.
 java.util.Enumeration<Item> items()
          An enumeration of all the items at this possessor.
 java.lang.String name()
          The displayable name of this object.
 CMObject newInstance()
          Returns a new instance of this class.
 int numItems()
          Returns the total number of items at this possessor, regardless of container status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakItemCollection

public WeakItemCollection()
Method Detail

ID

public java.lang.String ID()
Description copied from interface: CMObject
The CoffeeMud Java Class ID shared by all instances of this object. Unlike the Java Class name, this method does not include package information. However, it must return a String value unique to its class category in the ClassLoader. Class categories include Libraries, Common, Areas, Abilities, Behaviors, CharClasses, Commands, Exits Locales, MOBS, Races, WebMacros, Basic Items, Armor, Weapons, ClanItems, Tech. The name is typically identical to the class name.

Specified by:
ID in interface CMObject
Returns:
the name of this class

name

public java.lang.String name()
Description copied from interface: CMObject
The displayable name of this object. May be modified by phyStats() object. Is derived from the Name().

Specified by:
name in interface CMObject
Returns:
the modified final name of this object on the map.
See Also:
Environmental.Name()

copyOf

public CMObject copyOf()
Description copied from interface: CMObject
Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.

Specified by:
copyOf in interface CMObject
Returns:
a clone of this object

initializeClass

public void initializeClass()
Description copied from interface: CMObject
Called ONCE after all objects are loaded, but before the map is read in during initialization.

Specified by:
initializeClass in interface CMObject

newInstance

public CMObject newInstance()
Description copied from interface: CMObject
Returns a new instance of this class.

Specified by:
newInstance in interface CMObject
Returns:
a new instance of this class

compareTo

public int compareTo(CMObject o)
Specified by:
compareTo in interface java.lang.Comparable<CMObject>

findItem

public Item findItem(java.lang.String itemID)
Description copied from interface: ItemCollection
Returns the item in this possessor that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller name is found). Handles indexing for duplicate-named items.

Specified by:
findItem in interface ItemCollection
Parameters:
itemID - the name or partial name of the item to fetch
Returns:
the item found, or null

items

public java.util.Enumeration<Item> items()
Description copied from interface: ItemCollection
An enumeration of all the items at this possessor.

Specified by:
items in interface ItemCollection
Returns:
enumeration of all the items at this possessor.

findItem

public Item findItem(Item goodLocation,
                     java.lang.String itemID)
Description copied from interface: ItemCollection
Returns the item in the given container that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller name is found). Handles indexing for duplicate-named items.

Specified by:
findItem in interface ItemCollection
Parameters:
goodLocation - the container to look in, or null for none
itemID - the name or partial name of the item to fetch
Returns:
the item found, or null

findItems

public java.util.List<Item> findItems(Item goodLocation,
                                      java.lang.String itemID)
Description copied from interface: ItemCollection
Returns all items in the given container that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller names are found).

Specified by:
findItems in interface ItemCollection
Parameters:
goodLocation - the container to look in, or null for none
itemID - the name or partial name of the item to fetch
Returns:
the item found, or null

findItems

public java.util.List<Item> findItems(java.lang.String itemID)
Description copied from interface: ItemCollection
Returns all items in this possessor that matches the given itemID, whether by full name, description, class ID, or partial name (if no fuller names are found).

Specified by:
findItems in interface ItemCollection
Parameters:
itemID - the name or partial name of the item to fetch
Returns:
the item found, or null

addItem

public void addItem(Item item)
Description copied from interface: ItemCollection
Adds a new item to its possessor. By default, the item is added in a default resting state -- no containers, timeouts, or other modifiers are set. Duplicates will not be permitted.

Specified by:
addItem in interface ItemCollection
Parameters:
item - the item to add
See Also:
ItemCollection.delItem(Item)

delItem

public void delItem(Item item)
Description copied from interface: ItemCollection
Removes the item from this possessor.

Specified by:
delItem in interface ItemCollection
Parameters:
item - the item to remove

delAllItems

public void delAllItems(boolean destroy)
Description copied from interface: ItemCollection
Removes all items from this collection

Specified by:
delAllItems in interface ItemCollection
Parameters:
destroy - true to also destroy the items

numItems

public int numItems()
Description copied from interface: ItemCollection
Returns the total number of items at this possessor, regardless of container status.

Specified by:
numItems in interface ItemCollection
Returns:
the total number of items

isContent

public boolean isContent(Item item)
Description copied from interface: ItemCollection
Returns whether the given item is in this possessors list.

Specified by:
isContent in interface ItemCollection
Parameters:
item - the item to check
Returns:
true if the item was found, and false otherwise

getItem

public Item getItem(int i)
Description copied from interface: ItemCollection
Returns the item at the given index, regardless of container status, visibility, or other modifiers.

Specified by:
getItem in interface ItemCollection
Parameters:
i - the index of the item
Returns:
the item at that index, or null if its not found

eachItem

public void eachItem(EachApplicable<Item> applier)
Description copied from interface: ItemCollection
Applies the given code to each item in this collection

Specified by:
eachItem in interface ItemCollection
Parameters:
applier - code to execute against each object

getRandomItem

public Item getRandomItem()
Description copied from interface: ItemCollection
Returns a random item in this collection, or null

Specified by:
getRandomItem in interface ItemCollection
Returns:
a random item in this collection, or null