|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jminor.common.model.ItemRandomizerModel<T>
public class ItemRandomizerModel<T>
A default ItemRandomizer implementation.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.jminor.common.model.ItemRandomizer |
---|
ItemRandomizer.RandomItem<T> |
Constructor Summary | |
---|---|
ItemRandomizerModel()
Instantiates a new empty RandomItemModel. |
|
ItemRandomizerModel(int defaultWeight,
T... items)
Instantiates a new RandomItemModel with the given items. |
Method Summary | |
---|---|
void |
addItem(T item)
Adds the given item to this model with default weight of 0. |
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 |
protected void |
fireWeightsChangedEvent()
Notifies this model that the item weights have changed. |
EventObserver |
getEnabledObserver()
|
int |
getItemCount()
|
List<ItemRandomizer.RandomItem<T>> |
getItems()
|
protected Random |
getRandom()
|
T |
getRandomItem()
Fetches a random item from this model based on the item weights. |
protected ItemRandomizer.RandomItem<T> |
getRandomItem(T item)
Returns the RandomItem associated with item . |
int |
getWeight(T item)
Returns the weight of the given item. |
double |
getWeightRatio(T item)
Returns this items share in the total weights as a floating point number between 0 and 1 |
EventObserver |
getWeightsObserver()
|
void |
incrementWeight(T item)
Increments the weight of the given item by one |
boolean |
isItemEnabled(T item)
|
void |
setItemEnabled(T item,
boolean value)
|
void |
setWeight(T item,
int weight)
Sets the weight of the given item |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ItemRandomizerModel()
public ItemRandomizerModel(int defaultWeight, T... items)
defaultWeight
- the default weight to assign to each intial itemitems
- the items to add to this modelMethod Detail |
---|
public void addItem(T item, int weight)
addItem
in interface ItemRandomizer<T>
item
- the item to addweight
- the initial weight to assign to the itempublic void incrementWeight(T item)
incrementWeight
in interface ItemRandomizer<T>
item
- the itempublic void decrementWeight(T item)
decrementWeight
in interface ItemRandomizer<T>
item
- the itempublic void setWeight(T item, int weight)
setWeight
in interface ItemRandomizer<T>
item
- the itemweight
- the valuepublic boolean isItemEnabled(T item)
isItemEnabled
in interface ItemRandomizer<T>
item
- the item
public void setItemEnabled(T item, boolean value)
setItemEnabled
in interface ItemRandomizer<T>
item
- the itemvalue
- true if the item should be enabledpublic final void addItem(T item)
addItem
in interface ItemRandomizer<T>
item
- the item to addpublic final List<ItemRandomizer.RandomItem<T>> getItems()
getItems
in interface ItemRandomizer<T>
public final int getItemCount()
getItemCount
in interface ItemRandomizer<T>
public final EventObserver getWeightsObserver()
getWeightsObserver
in interface ItemRandomizer<T>
public final EventObserver getEnabledObserver()
getEnabledObserver
in interface ItemRandomizer<T>
public final T getRandomItem()
getRandomItem
in interface ItemRandomizer<T>
public final double getWeightRatio(T item)
getWeightRatio
in interface ItemRandomizer<T>
item
- the item
public final int getWeight(T item)
getWeight
in interface ItemRandomizer<T>
item
- the item
protected final ItemRandomizer.RandomItem<T> getRandomItem(T item)
item
.
item
- the item
RuntimeException
- in case the item is not foundprotected final void fireWeightsChangedEvent()
protected final Random getRandom()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |