|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.AbstractListModel
javax.swing.DefaultComboBoxModel
org.ceryle.util.FrequencyModel
public class FrequencyModel
Extends the default model for ComboBoxes, DefaultComboBoxModel,
using a Vector treated as a Set (ie., checking uniqueness of entries upon
adding) as the data store to insure that items in the list are unique.
This class is similar to SetModel, except that
it wraps each stored Object in a SortableObject
container, in order to maintain the rank order of each Object in the
list in terms of the frequency of access, i.e., the most accessed objects
move towards the top of the list.
An item's rank (an int value) can also be moved to the top or bottom of
the list, or to an explicit position (though only using the ranking scheme).
This can be done automatically on access to the list (when autoRank
is true), or the default, by explicitly calling action(Object).
Because this implements Set, attempts to add Objects
to the list that already are members does not add a duplicate Object,
but does decrement (i.e., move towards the top of the list) that Object's
rank within the list accordingly.
Note that the beginning (or top) of the list has the lowest int value, whereas the end (or bottom) of the list has the highest. There is no particular significance to the relative values of the list rankings, as they will tend to change during usage. This means that any change to the list may change an Object's ranking, and the exact value should not be relied upon; it is an implementation side-effect and is only used for sorting.
setMaximumSize(int). If set false
trimModel() will have to be called manually. Note that if
autotrim has been set true manual calls to trimModel() are ignored.
SetModel,
SortableObject,
DefaultComboBoxModel,
DefaultListModel,
Serialized Form| Field Summary | |
|---|---|
static boolean |
autoRank
When true, automatically alters the ranking on access to the model. |
| Fields inherited from class javax.swing.AbstractListModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
FrequencyModel()
Constructs an empty FrequencyModel and no maximum size. |
|
FrequencyModel(int maxsize)
Constructs an empty FrequencyModel and a maximum size of maxsize. |
|
FrequencyModel(Object[] items,
int maxsize)
Constructs a FrequencyModel object initialized with an array of objects and a maximum size of maxsize. |
|
FrequencyModel(Vector vector,
int maxsize)
Constructs a FrequencyModel object initialized with a Vector and a maximum size of maxsize. |
|
| Method Summary | |
|---|---|
void |
action(Object o)
Decrements the rank of Object o and then resorts the list, indicating activity on the Object. |
boolean |
add(Object o)
Adds the Object o to the end (bottom) of this FrequencyModel, returning true if the addition was successful. |
boolean |
addAll(Collection collection)
Adds all unique elements of the Collection collection to this FrequencyModel, returning true if all were successfully added. |
void |
addElement(Object o)
Implements javax.swing.MutableComboBoxModel. |
void |
addElements(Collection collection)
Adds all unique elements of the Collection collection to this FrequencyModel. |
void |
changedElementAt(int index)
Notifies any listeners that the element at index has changed. |
void |
clear()
Removes all the elements of this FrequencyModel. |
boolean |
contains(Object o)
Returns true if the specified Object exists within the list. |
boolean |
containsAll(Collection c)
Returns true if this FrequencyModel contains all of the elements of the provided Collection. |
Object |
get(int index)
Implements javax.swing.AbstractList. |
Object |
getElementAt(int index)
Implements javax.swing.ListModel. |
Object |
getFirstElement()
Returns the first Element of the model, null if empty. |
int |
getIndexOf(Object o)
Returns the index position of the specified object in the list. |
Object |
getLastElement()
Returns the last Element of the model, null if empty. |
int |
getMaximumRank()
Returns the current maximum ranking. |
int |
getMaximumSize()
Return the current maximum size setting. |
int |
getMinimumRank()
Returns the current minimum ranking. |
Object |
getSelectedItem()
Implements javax.swing.ComboBoxModel. |
int |
getSize()
Implements javax.swing.ListModel. |
int |
indexOf(Object o)
Returns the index position of the specified object in the list. |
int |
indexOf(Object o,
int index)
Returns the index position of the specified object in the list, beginning the search at index. |
void |
insertElementAt(Object o,
int index)
This inserts the Object o at position index, by ranking the object and adding it to the list. |
boolean |
isEmpty()
Returns true if the contents of this FrequencyModel are empty. |
Iterator |
iterator()
Returns an iterator over the contents of this FrequencyModel, null if empty. |
boolean |
moveToBeginning(Object o)
Moves the Object o to the first element (top) position in the model. |
int |
rankOf(Object o)
Returns the current ranking of Object o as an int. |
Object |
remove(int index)
Implementation method of java.util.List. |
boolean |
remove(Object o)
Implements java.util.List. |
boolean |
removeAll(Collection c)
Removes all the elements of this FrequencyModel that are contained within the provided Collection. |
void |
removeAllElements()
Empties the list. |
void |
removeElement(Object o)
Implements javax.swing.MutableComboBoxModel. |
void |
removeElementAt(int index)
Removes the element at position index. |
void |
removeWeight()
Does not change the sequence of the Objects within the model, but eliminates the weighting acrued (the number of "hits") by each. |
boolean |
retainAll(Collection c)
Retains only the elements in this FrequencyModel that are contained within the provided Collection. |
void |
setMaximumSize(int max)
If the maximum size is set (by default it is -1), the list will be auto-trimmed to limit, from the bottom (least popular). |
void |
setSelectedItem(Object o)
Implements javax.swing.ComboBoxModel. |
int |
size()
Implements java.util.Collection. |
void |
sort()
Sorts the values of the list, and reassigns rank numbers. |
Object[] |
toArray()
Returns an array containing all the elements in their current sequence. |
Object[] |
toArray(Object[] array)
Returns an array containing all the elements in their current sequence, with the runtime type of the returned array that of the provided array. |
String |
toString()
|
List |
trimModel()
Trims the size of the model to fit within its maximum size limit, if this has been set. |
| Methods inherited from class javax.swing.AbstractListModel |
|---|
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
equals, hashCode |
| Field Detail |
|---|
public static boolean autoRank
action(Object).
Default is false.
| Constructor Detail |
|---|
public FrequencyModel()
public FrequencyModel(int maxsize)
public FrequencyModel(Object[] items,
int maxsize)
items - an array of Object objectsmaxsize - the maximum size of the cache before trimming; if less than one no autotrim occurs.
public FrequencyModel(Vector vector,
int maxsize)
vector - the Vector objectmaxsize - the maximum size of the cache before trimming; if less than one no autotrim occurs.| Method Detail |
|---|
public void action(Object o)
public boolean add(Object o)
add in interface Collectionadd in interface Setpublic boolean addAll(Collection collection)
addAll in interface CollectionaddAll in interface Setpublic void addElement(Object o)
addElement in interface MutableComboBoxModeladdElement in class DefaultComboBoxModelpublic void addElements(Collection collection)
public void changedElementAt(int index)
public void clear()
removeAllElements().
clear in interface Collectionclear in interface Setpublic boolean contains(Object o)
contains in interface Collectioncontains in interface Seto - the specified Object
public boolean containsAll(Collection c)
containsAll in interface CollectioncontainsAll in interface Setpublic Object get(int index)
public Object getElementAt(int index)
getElementAt in interface ListModelgetElementAt in class DefaultComboBoxModelpublic Object getFirstElement()
public int getIndexOf(Object o)
getIndexOf in class DefaultComboBoxModelo - the specified Object.
public Object getLastElement()
public int getMaximumRank()
public int getMaximumSize()
public int getMinimumRank()
public Object getSelectedItem()
getSelectedItem in interface ComboBoxModelgetSelectedItem in class DefaultComboBoxModelpublic int getSize()
getSize in interface ListModelgetSize in class DefaultComboBoxModelpublic int indexOf(Object o)
o - the specified Object.
public int indexOf(Object o,
int index)
o - the specified Object.index - the non-negative index to start searching from.
IndexOutOfBoundsException - if index is negative.
public void insertElementAt(Object o,
int index)
Because this mixes the original usage of this method (i.e., dealing with Objects in the list via their index position) with FrequencyModel's ranking methodology, this should be used with caution.
Implements javax.swing.MutableComboBoxModel.
insertElementAt in interface MutableComboBoxModelinsertElementAt in class DefaultComboBoxModelpublic boolean isEmpty()
isEmpty in interface CollectionisEmpty in interface Setpublic Iterator iterator()
iterator in interface Iterableiterator in interface Collectioniterator in interface Setpublic boolean moveToBeginning(Object o)
Note that in SetModel, this required a delete
and an insert, whereas in this class it involves a change to the Object's
rank and a resort.
public int rankOf(Object o)
public Object remove(int index)
public boolean remove(Object o)
remove in interface Collectionremove in interface Setpublic boolean removeAll(Collection c)
removeAll in interface CollectionremoveAll in interface Setpublic void removeAllElements()
removeAllElements in class DefaultComboBoxModelpublic void removeElement(Object o)
removeElement in interface MutableComboBoxModelremoveElement in class DefaultComboBoxModelpublic void removeElementAt(int index)
Because this mixes the original usage of this method (i.e., dealing with Objects in the list via their index position) with FrequencyModel's ranking methodology, this should be used with caution.
Implements javax.swing.MutableComboBoxModel.
removeElementAt in interface MutableComboBoxModelremoveElementAt in class DefaultComboBoxModelpublic void removeWeight()
Note that if a maximum size is set, this method is called upon each addition to the list in order to allow new items to gain in popularity.
public boolean retainAll(Collection c)
retainAll in interface CollectionretainAll in interface Setpublic void setMaximumSize(int max)
max - the maximum size of the cache before trimming; if less than one no autotrim occurs.public void setSelectedItem(Object o)
setSelectedItem in interface ComboBoxModelsetSelectedItem in class DefaultComboBoxModelpublic int size()
size in interface Collectionsize in interface Setpublic void sort()
public Object[] toArray()
toArray in interface CollectiontoArray in interface Setpublic Object[] toArray(Object[] array)
toArray in interface CollectiontoArray in interface Setpublic String toString()
toString in class Objectpublic List trimModel()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||