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
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAccesses element e, thereby increasing its access count.protected intcount(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.booleanisEmpty()Returns true if the favorites list is empty.static voidprotected voidMoves item at Position p earlier in the list based on access count.voidRemoves element equal to e from the list of favorites (if found).intsize()Returns the number of items in the favorites list.protected static voidtest(FavoritesList<Character> fav) toString()protected Evalue(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
-