Package com.zybooks.dsaj.list
Class FavoritesList<E>
java.lang.Object
com.zybooks.dsaj.list.FavoritesList<E>
- Type Parameters:
E
- The element type
- Direct Known Subclasses:
FavoritesListMTF
A list of elements, ordered from most frequently to least frequently accessed.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Accesses element e, thereby increasing its access count.protected int
count
(Position<FavoritesList.Item<E>> p) Provides shorthand notation to retrieve count of item stored at Position p.protected Position<FavoritesList.Item<E>>
findPosition
(E e) Returns Position having element equal to e (or null if not found).getFavorites
(int k) Returns an iterable collection of the k most frequently accessed elements.boolean
isEmpty()
Returns true if the favorites list is empty.static void
protected void
Moves item at Position p earlier in the list based on access count.void
Removes element equal to e from the list of favorites (if found).int
size()
Returns the number of items in the favorites list.protected static void
test
(FavoritesList<Character> fav) toString()
protected E
value
(Position<FavoritesList.Item<E>> p) Provides shorthand notation to retrieve user's element stored at Position p.
-
Constructor Details
-
FavoritesList
public FavoritesList()Constructs initially empty favorites list.
-
-
Method Details
-
value
Provides shorthand notation to retrieve user's element stored at Position p. -
count
Provides shorthand notation to retrieve count of item stored at Position p. -
findPosition
Returns Position having element equal to e (or null if not found). -
moveUp
Moves item at Position p earlier in the list based on access count. -
size
public int size()Returns the number of items in the favorites list. -
isEmpty
public boolean isEmpty()Returns true if the favorites list is empty. -
access
Accesses element e, thereby increasing its access count. If e is new, its count will be 1 after this operation. -
remove
Removes element equal to e from the list of favorites (if found). -
getFavorites
Returns an iterable collection of the k most frequently accessed elements.- Throws:
IllegalArgumentException
-
toString
-
test
-
main
-