org.jminor.common.model
Class BoundedItemRandomizerModel<T>

java.lang.Object
  extended by org.jminor.common.model.ItemRandomizerModel<T>
      extended by org.jminor.common.model.BoundedItemRandomizerModel<T>
Type Parameters:
T - the type of item this random item model returns
All Implemented Interfaces:
ItemRandomizer<T>

public final class BoundedItemRandomizerModel<T>
extends ItemRandomizerModel<T>

A ItemRandomizer with the added constraint that the total item weights can not exceed a defined maximum. When the weight of one item is incremented the weight of another is decremented in a round robin kind of fashion and when a item weight is decremented the weight of another is incremented.
User: Björn Darri
Date: 6.4.2010
Time: 21:26:00


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jminor.common.model.ItemRandomizer
ItemRandomizer.RandomItem<T>
 
Constructor Summary
BoundedItemRandomizerModel(int boundedWeight, T... items)
          Instantiates a new BoundedRandomItemModel with the given bounded weight.
BoundedItemRandomizerModel(T... items)
          Instantiates a new BoundedRandomItemModel with a default bounded weight of 100.
 
Method Summary
 void addItem(T item, int weight)
          Adds the given item to this model with the given weight value.
 void decrementWeight(T item)
          Decrements the weight of the given item by one
 int getWeightBounds()
           
 void incrementWeight(T item)
          Increments the weight of the given item by one
 void setWeight(T item, int weight)
          Sets the weight of the given item
 
Methods inherited from class org.jminor.common.model.ItemRandomizerModel
addItem, fireWeightsChangedEvent, getEnabledObserver, getItemCount, getItems, getRandom, getRandomItem, getRandomItem, getWeight, getWeightRatio, getWeightsObserver, isItemEnabled, setItemEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedItemRandomizerModel

public BoundedItemRandomizerModel(T... items)
Instantiates a new BoundedRandomItemModel with a default bounded weight of 100.

Parameters:
items - the items

BoundedItemRandomizerModel

public BoundedItemRandomizerModel(int boundedWeight,
                                  T... items)
Instantiates a new BoundedRandomItemModel with the given bounded weight.

Parameters:
boundedWeight - the maximum total weight
items - the items
Method Detail

getWeightBounds

public int getWeightBounds()

incrementWeight

public void incrementWeight(T item)
Increments the weight of the given item by one

Specified by:
incrementWeight in interface ItemRandomizer<T>
Overrides:
incrementWeight in class ItemRandomizerModel<T>
Parameters:
item - the item

decrementWeight

public void decrementWeight(T item)
Decrements the weight of the given item by one

Specified by:
decrementWeight in interface ItemRandomizer<T>
Overrides:
decrementWeight in class ItemRandomizerModel<T>
Parameters:
item - the item

setWeight

public void setWeight(T item,
                      int weight)
Sets the weight of the given item

Specified by:
setWeight in interface ItemRandomizer<T>
Overrides:
setWeight in class ItemRandomizerModel<T>
Parameters:
item - the item
weight - the value

addItem

public void addItem(T item,
                    int weight)
Adds the given item to this model with the given weight value.

Specified by:
addItem in interface ItemRandomizer<T>
Overrides:
addItem in class ItemRandomizerModel<T>
Parameters:
item - the item to add
weight - the initial weight to assign to the item