org.haphazard.item
Class Container

java.lang.Object
  extended byorg.haphazard.item.Container
All Implemented Interfaces:
Containing

public class Container
extends java.lang.Object
implements Containing

Class for holding items and keeping track of free space for more items


Constructor Summary
Container()
          Creates a new container
 
Method Summary
 boolean add(Item item)
          Adds an item to this container
 void addSpecialization(java.lang.String specialization)
          Adds an item specialization to this container.
 boolean canHold(Item item)
          Checks if this container can hold the item in question
 boolean contains(Item item)
          Checks if this container contains a specific item
 Dimension3D getContainerDimension()
          Returns the containers volume
 int getContainerWeight()
          Gets the total weight of the container
 int getFreeSpecializationSlots()
          Gets the number of free slots
 int getFreeVolume()
          Gets the total free volume of the inventory
 javax.swing.tree.DefaultMutableTreeNode getTreeNode()
          Gets the treenode of the containing item
 boolean isSpecialization(Item item)
          Checks if an item is a specialization of this container
 boolean remove(Item item)
          Removes an item from this container
 void setContainerDimension(Dimension3D dimension)
          Sets the dimension of the container
 void setSpecializations(java.util.Vector specializations)
          Convenience function for setting all specializations at once
 void setSpecializationSlots(int count)
          Sets the number of specialized items the container can hold
 java.lang.String toXML(int indent)
          Transforms this object into an XML notation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Container

public Container()
Creates a new container

Method Detail

getContainerDimension

public Dimension3D getContainerDimension()
Returns the containers volume

Specified by:
getContainerDimension in interface Containing
Returns:
The containers volume

setContainerDimension

public void setContainerDimension(Dimension3D dimension)
Sets the dimension of the container

Parameters:
dimension - The dimension of the container

addSpecialization

public void addSpecialization(java.lang.String specialization)
Adds an item specialization to this container. By specifying a certain type of item (i.e. "Long Sword") the container can hold Long Swords regardless of it's dimension. The containers specialized slots and the inner dimensions is not dependant on each other

Parameters:
specialization - The type of item to specialize in

setSpecializations

public void setSpecializations(java.util.Vector specializations)
Convenience function for setting all specializations at once

Parameters:
specializations - All specializations for this container

setSpecializationSlots

public void setSpecializationSlots(int count)
Sets the number of specialized items the container can hold

Parameters:
count - The number of specialized items the container can hold

getFreeSpecializationSlots

public int getFreeSpecializationSlots()
Gets the number of free slots

Specified by:
getFreeSpecializationSlots in interface Containing
Returns:
Gets the number of free specialization slots on this container

contains

public boolean contains(Item item)
Checks if this container contains a specific item

Specified by:
contains in interface Containing
Parameters:
item - The item to look for
Returns:
True if the item is in this container

add

public boolean add(Item item)
Adds an item to this container

Specified by:
add in interface Containing
Parameters:
item - The item to add
Returns:
True if the item was successfully added

remove

public boolean remove(Item item)
Removes an item from this container

Specified by:
remove in interface Containing
Parameters:
item - The item to remove
Returns:
True if the item was successfully removed

canHold

public boolean canHold(Item item)
Checks if this container can hold the item in question

Specified by:
canHold in interface Containing
Parameters:
item - The item to check
Returns:
True if the item fits in the container and the remaining volume permits it

getFreeVolume

public int getFreeVolume()
Gets the total free volume of the inventory

Specified by:
getFreeVolume in interface Containing
Returns:
The total free volume of the inventory

getContainerWeight

public int getContainerWeight()
Gets the total weight of the container

Specified by:
getContainerWeight in interface Containing
Returns:
The total weight of the container

toXML

public java.lang.String toXML(int indent)
Transforms this object into an XML notation

Parameters:
indent - The indent level
Returns:
A string in XML notation

isSpecialization

public boolean isSpecialization(Item item)
Checks if an item is a specialization of this container

Specified by:
isSpecialization in interface Containing
Parameters:
item - The item to check

getTreeNode

public javax.swing.tree.DefaultMutableTreeNode getTreeNode()
Gets the treenode of the containing item

Specified by:
getTreeNode in interface Containing
Returns:
The node of the container to be used in a JTree