us.asciiroth.client.core
Class Bag<T extends Piece>

java.lang.Object
  extended by us.asciiroth.client.core.Bag<T>
Type Parameters:
T -
Direct Known Subclasses:
EffectBag, ItemBag, PlayerBag

public class Bag<T extends Piece>
extends java.lang.Object

A collection of items or effects. A bag keeps track of the count of like items within the bag, and has logic for correctly adding and removing counts, rather than item instances.


Nested Class Summary
static class Bag.Entry<T extends Piece>
          An entry in the bag.
 
Constructor Summary
Bag()
          Constructor.
 
Method Summary
 void add(int index, T piece)
          Add an item to the bag at the indicated index.
 void add(T piece)
          Add one count of an item to the bag.
 java.util.List<Bag.Entry<T>> asEntryList()
           
 boolean contains(T piece)
          Does this bag contain one or more of the indicated piece?
 Bag.Entry<T> findEntry(T piece)
           
 T get(int index)
          Get the item at the given index
 int getCount(T piece)
          Get the current count for this item type.
 int getIndex(T piece)
          Get the index of the entry for this item.
 boolean isEmpty()
          Is the bag empty?
 T last()
          Get the last item in this bag (and thus, the item that is visible when on the ground).
 void remove(T piece)
          Remove one count of an item from the bag.
 int size()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bag

public Bag()
Constructor.

Method Detail

add

public void add(int index,
                T piece)
Add an item to the bag at the indicated index. Used in an attempt to manipulate what you can see in the effects layer.

Parameters:
index -
piece -

add

public void add(T piece)
Add one count of an item to the bag.

Parameters:
piece -

asEntryList

public java.util.List<Bag.Entry<T>> asEntryList()
Returns:
the set of entries as a list

contains

public boolean contains(T piece)
Does this bag contain one or more of the indicated piece?

Parameters:
piece -
Returns:
true if it does, false otherwise

findEntry

public Bag.Entry<T> findEntry(T piece)

get

public T get(int index)
Get the item at the given index

Parameters:
index -
Returns:
the item at the given index, or null if the index is out of bounds

getCount

public int getCount(T piece)
Get the current count for this item type.

Parameters:
piece -
Returns:
the number in the bag, or 0 if none

getIndex

public int getIndex(T piece)
Get the index of the entry for this item.

Parameters:
piece -
Returns:
the index of the entry for this item

isEmpty

public boolean isEmpty()
Is the bag empty?

Returns:
true if empty, false otherwise

last

public T last()
Get the last item in this bag (and thus, the item that is visible when on the ground).

Returns:
the last item in the bag.

remove

public void remove(T piece)
Remove one count of an item from the bag.

Parameters:
piece -

size

public int size()
Returns:
the number of entries in the bag

0.7

© 2009 Alx Dark