|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnars.storage.Bag<Type>
public abstract class Bag<Type extends Item>
A Bag is a storage with a constant capacity and maintains an internal priority distribution for retrieval.
Each entity in a bag must extend Item, which has a BudgetValue and a key.
A name table is used to merge duplicate items that have the same key.
The bag space is divided by a threshold, above which is mainly time management, and below, space mamagement. Differences: (1) level selection vs. item selection, (2) decay rate
| Field Summary | |
|---|---|
protected int |
capacity
defined in different bags |
protected int |
currentCounter
maximum number of items to be taken out at current level |
protected int |
currentLevel
current take out level |
(package private) static Distributor |
DISTRIBUTOR
shared distributor that produce the probability distribution |
protected java.util.ArrayList<Type>[] |
itemTable
array of lists of items, for items on different level |
protected int |
levelIndex
index to get next level, kept in individual objects |
protected static float |
LOAD_FACTOR
hashtable load factor |
protected int |
mass
current sum of occupied level |
protected java.util.HashMap<java.lang.String,Type> |
nameTable
mapping from key to item |
protected static float |
RELATIVE_THRESHOLD
relative threshold, only calculate once |
protected boolean |
showing
whether this bag has an active window |
protected static int |
THRESHOLD
firing threshold |
protected static int |
TOTAL_LEVEL
priority levels |
protected BagWindow |
window
display window |
| Constructor Summary | |
|---|---|
protected |
Bag()
constructor, called from subclasses |
| Method Summary | |
|---|---|
float |
averagePriority()
Get the average priority of Items |
protected abstract int |
capacity()
To get the capacity of the concrete subclass |
boolean |
contains(Type it)
Check if an item is in the bag |
private boolean |
emptyLevel(int n)
Check whether a level is empty |
protected abstract int |
forgetRate()
Get the item decay rate, which differs in difference subclass, and can be changed in run time by the user, so not a constant. |
Type |
get(java.lang.String key)
Get an Item by key |
private int |
getLevel(Type item)
Decide the put-in level according to priority |
private Type |
intoBase(Type newItem)
Insert an item into the itemTable, and return the overflow |
protected void |
outOfBase(Type oldItem)
Remove an item from itemTable, then adjust mass |
Type |
pickOut(java.lang.String key)
Pick an item by key, then remove it from the bag |
void |
play()
Resume display |
void |
putBack(Type oldItem)
Put an item back into the itemTable |
void |
putIn(Type newItem)
Add a new Item into the Bag |
void |
refresh()
Refresh display |
void |
startPlay(java.lang.String title)
To start displaying the Bag in a BagWindow |
void |
stop()
Stop display |
Type |
takeOut()
Choose an Item according to priority distribution and take it out of the Bag |
private Type |
takeOutFirst(int level)
Take out the first or last Type in a level from the itemTable |
java.lang.String |
toString()
Collect Bag content into a String for display |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final int TOTAL_LEVEL
protected static final int THRESHOLD
protected static final float RELATIVE_THRESHOLD
protected static final float LOAD_FACTOR
static final Distributor DISTRIBUTOR
protected java.util.HashMap<java.lang.String,Type extends Item> nameTable
protected java.util.ArrayList<Type extends Item>[] itemTable
protected int capacity
protected int mass
protected int levelIndex
protected int currentLevel
protected int currentCounter
protected boolean showing
protected BagWindow window
| Constructor Detail |
|---|
protected Bag()
| Method Detail |
|---|
protected abstract int capacity()
protected abstract int forgetRate()
public float averagePriority()
public boolean contains(Type it)
it - An item
public Type get(java.lang.String key)
key - The key of the Item
public void putIn(Type newItem)
newItem - The new Itempublic void putBack(Type oldItem)
The only place where the forgetting rate is applied
oldItem - The Item to put backpublic Type takeOut()
public Type pickOut(java.lang.String key)
key - The given key
private boolean emptyLevel(int n)
n - The level index
private int getLevel(Type item)
item - The Item to put in
private Type intoBase(Type newItem)
newItem - The Item to put in
private Type takeOutFirst(int level)
level - The current level
protected void outOfBase(Type oldItem)
oldItem - The Item to be removedpublic void startPlay(java.lang.String title)
title - The title of the windowpublic void play()
public void refresh()
public void stop()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||