Skip to content

Commit c8c283e

Browse files
chore: update MusicPlaylist comments to be more indepth
1 parent e53267f commit c8c283e

1 file changed

Lines changed: 70 additions & 25 deletions

File tree

p1-music-playlist/src/main/java/MusicPlaylist.java

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
import java.util.*;
22

33
/**
4-
* Contains CRUD and view methods for the music playlist utilizing the Queue and
5-
* Stack data structures.
4+
* CLI music playlist application.
5+
*
6+
* <p>
7+
* The playlist is modeled as a {@code Queue} of song names in FIFO order.
8+
* Played songs are recorded in a {@code Stack} as a LIFO history.
9+
*
10+
* <p>
11+
* This program supports:
12+
* <ul>
13+
* <li>Adding songs to the end of the playlist with
14+
* {@link MusicPlaylist#addSong(Scanner, Queue)}</li>
15+
* <li>Playing the next song (implicitly moves it from playlist to history) with
16+
* {@link MusicPlaylist#playSong(Queue, Stack)}</li>
17+
* <li>Viewing the current playlist order
18+
* {@link MusicPlaylist#viewPlaylist(Queue)}</li>
19+
* <li>Printing the play history in most recent order with
20+
* {@link MusicPlaylist#printHistory(Stack)}</li>
21+
* <li>Clearing history with {@link MusicPlaylist#clearHistory(Stack)}</li>
22+
* <li>Deleting a specified number of songs from history (ordered from most
23+
* recent to oldest) with
24+
* {@link MusicPlaylist#deleteHistory(Scanner, Stack)}</li>
25+
* </ul>
26+
*
27+
* <p>
28+
* All songs are represented as {@code String} values and are compared and
29+
* printed as entered.
630
*/
731
public class MusicPlaylist {
832
public static void main(String[] args) {
@@ -48,12 +72,16 @@ public static void main(String[] args) {
4872
}
4973

5074
/**
51-
* Adds a song to the playlist `Queue`.
75+
* Prompts the user for a song name and appends it to the end of the
76+
* {@code playlist}.
77+
*
78+
* <p>
79+
* The playlist is a FIFO structure.
5280
*
5381
* @param input
54-
* user input scanner
82+
* input scanner used to read user input.
5583
* @param playlist
56-
* the `Queue` of songs to add a song too
84+
* playlist {@code Queue} that stores the upcoming songs.
5785
*/
5886
private static void addSong(Scanner input, Queue<String> playlist) {
5987
System.out.print("Enter song name: ");
@@ -63,14 +91,17 @@ private static void addSong(Scanner input, Queue<String> playlist) {
6391
}
6492

6593
/**
66-
* Removes the head of the playlist `Queue` and pushes it to the history stack.
94+
* Plays the next song in the {@code playlist}.
95+
*
96+
* <p>
97+
* Removes the song at the head of the {@code playlist} onto {@code history}.
6798
*
6899
* @param playlist
69-
* the `Queue` of songs to play a song from
100+
* playlist {@code Queue} that stores the upcoming songs.
70101
* @param history
71-
* the `Stack` of songs which have been played
102+
* {@code Stack} storing previously played songs.
72103
* @throws IllegalStateException
73-
* if {@code playlist} is empty
104+
* if {@code playlist} is empty.
74105
*/
75106
private static void playSong(Queue<String> playlist, Stack<String> history) {
76107
if (playlist.isEmpty()) {
@@ -83,12 +114,15 @@ private static void playSong(Queue<String> playlist, Stack<String> history) {
83114
}
84115

85116
/**
86-
* Prints the history `Stack` in reverse chronological order.
117+
* Prints the play {@code history} in reverse chronological order.
118+
*
119+
* <p>
120+
* This methods reserves {@code history}.
87121
*
88122
* @param history
89-
* the `Stack` of songs which have been played
123+
* {@code Stack} storing previously played songs.
90124
* @throws IllegalStateException
91-
* if {@code history} is empty
125+
* if {@code history} is empty.
92126
*/
93127
private static void printHistory(Stack<String> history) {
94128
if (history.isEmpty()) {
@@ -108,10 +142,13 @@ private static void printHistory(Stack<String> history) {
108142
}
109143

110144
/**
111-
* Clears the history `Stack` by popping all its elements.
145+
* Removes all songs from the play {@code history}.
146+
*
147+
* <p>
148+
* After this methods returns, {@code history} is empty.
112149
*
113150
* @param history
114-
* the `Stack` of songs which have been played
151+
* {@code Stack} storing previously played songs.
115152
*/
116153
private static void clearHistory(Stack<String> history) {
117154
while (!history.isEmpty()) {
@@ -120,20 +157,25 @@ private static void clearHistory(Stack<String> history) {
120157
}
121158

122159
/**
123-
* Deletes the history `Stack` in either chronological or reverse chronological
124-
* order.
160+
* Deletes a user specified number of songs from the play {@code history}.
125161
*
126-
* The user inputted number is the amount to delete. If the number is signed the
127-
* deletion happens in chronological order, otherwise elements are deleted in
128-
* reverse chronological order
162+
* <p>
163+
* The user enters an integer:
164+
* <ul>
165+
* <li>If the number is positive, the method deletes from the most recent
166+
* history.</li>
167+
* <li>If the number if negative, the method deletes from the oldest
168+
* history.</li>
169+
* <li>If the number is zero, no changes are made.</li>
170+
* </ul>
129171
*
130172
* @param input
131-
* user input scanner
173+
* input scanner used to read the delete count.
132174
* @param history
133-
* the `Stack` of songs which have been played
175+
* {@code Stack} storing previously played songs.
134176
* @throws IllegalArgumentException
135177
* if {@code normalizedDelete} is greater than the size of
136-
* {@code history}
178+
* {@code history.size()}.
137179
*/
138180
private static void deleteHistory(Scanner input, Stack<String> history) {
139181
System.out.println("A positive number will delete from recent history.");
@@ -175,12 +217,15 @@ private static void deleteHistory(Scanner input, Stack<String> history) {
175217
}
176218

177219
/**
178-
* Prints the playlist `Queue` order.
220+
* Prints the current {@code playlist} in play order.
221+
*
222+
* <p>
223+
* This method preserves {@code playlist}.
179224
*
180225
* @param playlist
181-
* the `Queue` of songs to play a song from
226+
* playlist {@code Queue} that stores the upcoming songs.
182227
* @throws IllegalStateException
183-
* if {@code playlist} is empty
228+
* if {@code playlist} is empty.
184229
*/
185230
private static void viewPlaylist(Queue<String> playlist) {
186231
if (playlist.isEmpty()) {

0 commit comments

Comments
 (0)