Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SalonetheGreat authored Nov 7, 2019
2 parents 3e72ba5 + 357f808 commit e91571b
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 218 deletions.
3 changes: 3 additions & 0 deletions songlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
twinkle aminor 123 [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[RTs],[RT],[LAs],[LA],[LBs],[LB],[LFs],[LF]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[RTs],[RT],[LAs],[LA],[LBs],[LB],[LFs],[LF]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[RTs],[RT],[LAs],[LA],[LBs],[LB],[LFs],[LF]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[RTs],[RT],[LAs],[LA],[LBs],[LB],[LFs],[LF]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]]
44 aminor 123 [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[UBs],[UB],[UB],[UB],[UB],[UB],[UB],[UB]] [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[UBs],[UB],[UB],[UB],[UB],[UB],[UB],[UB]] [[UCs],[UC],[UC],[UC],[UC],[UC],[UC],[UC]]
444 aminor 123 [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[LEs],[LE],[LE],[LE],[LE],[LE],[LE],[LE]] [[LCs],[LC],[LC],[LC],[LCs],[LC],[LC],[LC]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[LEs],[LE],[LE],[LE],[LE],[LE],[LE],[LE]] [[UAs],[UA],[UAs],[UA],[UAs],[UA],[UAs],[UA]] [[UCs],[UC],[UBs],[UB],[LAs],[LA],[MCs],[MC]] [[UAs],[UA],[UA],[UA],[UA],[UA],[UA],[UA]] [[LEs],[LE],[LE],[LE],[LE],[LE],[LE],[LE]]
5 changes: 3 additions & 2 deletions src/main/java/ducats/Ducats.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import ducats.commands.SwapBarCommand;
import ducats.commands.UndoCommand;
import ducats.commands.ViewCommand;
import ducats.commands.ListGroupCommand;
import ducats.components.SongList;
import ducats.components.UndoRedoStack;

import java.nio.file.Paths;

public class Ducats {
/**
Expand Down Expand Up @@ -93,7 +93,8 @@ private void run() {
|| c instanceof OverlayBarSong
|| c instanceof OpenCommand
|| c instanceof AsciiCommand
|| c instanceof OverlayGroupGroup) {
|| c instanceof OverlayGroupGroup
|| c instanceof ListGroupCommand) {
output = c.execute(songs, ui, storage);
if (!(c instanceof HelpCommand
|| c instanceof ViewCommand
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/ducats/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ducats.commands.AddBarCommand;
import ducats.commands.AddOverlayCommand;
import ducats.commands.AsciiCommand;
import ducats.commands.ByeCommand;
import ducats.commands.Command;
import ducats.commands.CopyCommand;
import ducats.commands.DeleteBarCommand;
Expand All @@ -13,7 +12,6 @@
import ducats.commands.HelpCommand;
import ducats.commands.InsertBarCommand;
import ducats.commands.ListCommand;
import ducats.commands.MetronomeCommand;
import ducats.commands.NewCommand;
import ducats.commands.OpenCommand;
import ducats.commands.OverlayBarGroup;
Expand All @@ -23,9 +21,12 @@
import ducats.commands.SwapBarCommand;
import ducats.commands.UndoCommand;
import ducats.commands.ViewCommand;
import ducats.commands.ListGroupCommand;
import ducats.commands.ByeCommand;
import ducats.commands.MetronomeCommand;
import ducats.components.Jaccard;
import ducats.components.WordGetter;
import ducats.Ui;



/**
Expand Down Expand Up @@ -168,6 +169,11 @@ public static Command parse(Ui ui,String message) throws DucatsException {
return new MetronomeCommand(message);
}
break;
case "list_group":
if (message.length() == 10) {
return new ListGroupCommand();
}
break;
default:
return new AddBarCommand(message);
}
Expand Down
213 changes: 23 additions & 190 deletions src/main/java/ducats/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Scanner;

//@@author rohan-av
/**
* A class to implement persistent storage of the task list using a .txt file.
*/
Expand Down Expand Up @@ -61,7 +62,6 @@ boolean initialize() throws DucatsException {
//
// TODO: implement convertFromString

// @@author rohan-av
private ArrayList<String> formatListToString(ArrayList<Song> list) {
ArrayList<String> result = new ArrayList<>();
for (Song song: list) {
Expand All @@ -70,6 +70,12 @@ private ArrayList<String> formatListToString(ArrayList<Song> list) {
return result;
}

/**
* Takes in an ArrayList of Strings, each representing a song, and stores it in the .txt file.
*
* @param songs the ArrayList of songs as Strings
* @throws DucatsException in the case of IO exceptions
*/
private void writeStringsToFile(ArrayList<String> songs) throws DucatsException {
FileWriter fileWriter;
try {
Expand All @@ -86,6 +92,12 @@ private void writeStringsToFile(ArrayList<String> songs) throws DucatsException
}
}

/**
* Returns an ArrayList of Strings, with each String corresponding to a line in the file.
*
* @return the lines as an ArrayList of Strings
* @throws DucatsException in the case of IO exceptions
*/
private ArrayList<String> readStringsFromFile() throws DucatsException {
// reads file and returns an ArrayList of lines
ArrayList<String> result = new ArrayList<>();
Expand Down Expand Up @@ -119,13 +131,13 @@ public void loadToList(SongList songList) throws DucatsException {
}

}

// twinkle [[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA]]
/**
* A function that converts a string into a Song element.
* A function that converts a string into a Song object.
*
* @param s - this is the string to be converted to a song.
* @param s this is the string to be converted to a song.
*/

// twinkle [[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA],[UAs;UAs],[UA;UA]]
public Song convertSongFromString(String s) throws DucatsException {
String[] sections = s.split(" ");
if (sections.length == 1) {
Expand Down Expand Up @@ -225,193 +237,14 @@ private Note convertNoteFromString(String s) throws DucatsException {
return new Note(duration, pitch, isStart);
}


/**
* Updates the .txt file with the current data found within the SongList.
*
* @param songList the SongList object containing the list of Song objects
* @throws DucatsException in the case of IO exceptions
*/
public void updateFile(SongList songList) throws DucatsException {
// System.out.println(songList.getSongList().get(0).toString());
writeStringsToFile(formatListToString(songList.getSongList()));
}

// Ducats implementation ends here. (TODO: delete below when appropriate)

// /**
// * Returns an ArrayList of the String representations of all the duke.tasks.Task objects in the task list.
// *
// * @param list the task list containing all the duke.tasks.Task objects
// * @return an ArrayList of the String representations of the tasks in the task list
// */
// private ArrayList<String> formatFile(ArrayList<Task> list) {
// ArrayList<String> result = new ArrayList<>();
// for (Task task : list) {
// result.add(task.toString());
// }
// return result;
// }
//
// /**
// * Writes the task list to the .txt file.
// *
// * @param tasks an ArrayList of the String representations of the tasks in the task list
// * @throws DukeException in the case of input or output exceptions
// */
// private void writeFile(ArrayList<String> tasks) throws DukeException {
// try {
// Files.write(file, tasks, StandardCharsets.UTF_8);
// } catch (IOException e) {
// throw new DukeException("","io");
// }
// }
//
// /**
// * Reads the .txt fil and returns an ArrayList of Strings that represent the tasks in the task
// * list
// *
// * @return an ArrayList of Strings that represent the tasks in the task list
// * @throws DukeException in the case of input or output exceptions
// */
// private ArrayList<String> readFile() throws DukeException {
// // reads file and returns an ArrayList of lines
// ArrayList<String> result = new ArrayList<>();
// try (BufferedReader br = Files.newBufferedReader(file)) {
// String line;
// while ((line = br.readLine()) != null) {
// result.add(line);
// }
// } catch (Exception e) {
// throw new DukeException("", "io");
// }
// return result;
// }
//
// /**
// * After reading the file, converts each String representation back into its corresponding
// * duke.tasks.Task object and pushes it into the duke.TaskList.
// *
// * @param taskList the duke.TaskList object used to store the task list
// * @throws DukeException in the case of input or output exceptions
// */
// void loadList(TaskList taskList) throws DukeException {
// // loads data into list
// ArrayList<String> data = readFile();
// for (String line: data) {
// //System.out.println(line);
// convertString(taskList, line);
// }
// }
//
// /**
// * Interprets the String, translates it to the appropriate duke.tasks.Task object, and adds it
// * to the duke.TaskList.
// *
// * @param taskList the duke.TaskList object used to store the task list
// * @param s the String representation to be converted
// * @throws DukeException in the case of input or output exceptions
// */
// private void convertString(TaskList taskList, String s) throws DukeException {
// try {
// String type = s.substring(1,2); // T, D, E or A
// boolean isDone = s.substring(4,5).equals("v");
// String description;
// String addendum;
//
// switch (type) {
// case "T":
// description = s.substring(7);
// ToDo todo = new ToDo(description);
// if (isDone) {
// todo.setDone();
// }
// taskList.add(todo);
// break;
// case "E": {
// String[] sections = s.substring(7).split("\\(from:");
//
// sections[1] = sections[1].replace("to","-");
// sections[1] = sections[1].replace(")","");
// //System.out.println(sections[1]);
// //description = sections[0].substring(0, sections[0].length() - 2);
// //addendum = sections[1].substring(1, sections[1].length() - 1);
// //String[] to_from = addendum.split("to");
//
// Event event = (Event)taskList.get_first_e(sections,1);
// if (isDone) {
// event.setDone();
// }
// taskList.add(event);
// break;
// }
// case "D": {
// String[] sections = s.substring(7).split("by:");
// description = sections[0].substring(0, sections[0].length() - 2);
// addendum = sections[1].substring(1, sections[1].length() - 1);
// Deadline deadline = new Deadline(description, addendum);
// if (isDone) {
// deadline.setDone();
// }
// taskList.add(deadline);
// break;
// }
// case "A": {
// String[] sections = s.substring(7).split("after:");
// description = sections[0].substring(0, sections[0].length() - 2);
// addendum = sections[1].substring(6, sections[1].length() - 1);
// int previousTaskNumber = Integer.parseInt(addendum);
// DoAfter doAfter = new DoAfter(description, previousTaskNumber, taskList.getSize() + 1);
// DoAfterList.add(previousTaskNumber);
// if (isDone) {
// doAfter.setDone();
// }
// taskList.add(doAfter);
// break;
// }
// case "B": {
// String[] sections = s.substring(7).split("between");
// description = sections[0].substring(0, sections[0].length() - 2);
// String[] sections2 = sections[1].split("and");
// String start = sections2[0].substring(1, sections2[0].length() - 1).trim();
// String end = sections2[1].substring(0, sections2[1].length() - 1).trim();
// BetweenTask betweenTask = new BetweenTask(description, start, end);
// if (isDone) {
// betweenTask.setDone();
// }
// taskList.add(betweenTask);
// break;
// }
// case "R": {
// String[] sections = s.substring(7).split("\\(");
// description = sections[0];
// String frequency = sections[1].split(" ")[0];
//
// String[] dateInfo = sections[1].split("on: ");
// String[] dateNewInfo = dateInfo[1].split(" ");
// String date = dateNewInfo[0];
// String time;
// if (dateNewInfo.length == 3) {
// time = dateNewInfo[2].substring(0, dateNewInfo[2].length() - 1);
// } else {
// time = "";
// }
// //String date = "";
// // String time = "";
// RecurringTask recurringTask = new RecurringTask(description, date, time, frequency);
// taskList.add(recurringTask);
// break;
// }
// default:
// throw new DukeException("","io");
// }
//
// } catch (Exception e) {
// throw new DukeException("","io");
// }
// }
//
// /**
// * Updates the .txt file with the latest task list found within the duke.Duke program.
// *
// * @param taskList the duke.TaskList object used to store the task list
// * @throws DukeException in the case of input or output exceptions
// */
// public void updateFile(TaskList taskList) throws DukeException {
// writeFile(formatFile(taskList.getTaskList()));
// }
}
22 changes: 22 additions & 0 deletions src/main/java/ducats/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ducats.commands.CommandSyntaxMessage;
import ducats.components.Bar;
import ducats.components.Group;
import ducats.components.Song;
import ducats.components.SongList;

Expand Down Expand Up @@ -184,6 +185,27 @@ public String formatDeleteBar(Song song, int barIndex) {
return wrap(result);
}

//@@author Samuel787
/**
* Returns a String formatted for display that shows all the groups available
* in the current song.
*
* @param songList list of songs from storage
* @return the formatted String to be displayed
*/
public String formatListGroups(SongList songList) {
int songIndex = songList.getActiveIndex();
ArrayList<Group> groups = songList.getSongIndex(songIndex).getGroups();
String result = "Here are the groups available: \n";
int groupCount = 1;
for (Group group : groups) {
result += groupCount + ". " + group.getName() + "\n";
groupCount++;
}
return result;
}

//@@author
/**
* Returns a String formatted for display that the wrong command was type and telling them
* the command was autocorrected.
Expand Down
Loading

0 comments on commit e91571b

Please sign in to comment.