Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-av committed Oct 24, 2019
2 parents 9028f5b + d992e23 commit ae1cf6d
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 154 deletions.
11 changes: 10 additions & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package duke;


import duke.commands.AddBarCommand;
import duke.commands.AddOverlayCommand;
import duke.commands.AsciiCommand;
import duke.commands.Command;
import duke.commands.CopyCommand;
import duke.commands.DeleteBarCommand;
import duke.commands.DeleteCommand;
import duke.commands.EditCommand;
import duke.commands.GroupCommand;
import duke.commands.HelpCommand;
import duke.commands.ListCommand;
Expand Down Expand Up @@ -77,11 +82,15 @@ public void run() {
if (c instanceof AddBarCommand
|| c instanceof ViewCommand
|| c instanceof NewCommand
|| c instanceof DeleteCommand
|| c instanceof DeleteBarCommand
|| c instanceof EditCommand
|| c instanceof HelpCommand
|| c instanceof GroupCommand
|| c instanceof CopyCommand
|| c instanceof AddOverlayCommand
|| c instanceof ListCommand) {
|| c instanceof ListCommand
|| c instanceof AsciiCommand) {
output = c.execute(songs, ui, storage);
} else {
output = c.execute(tasks, ui, storage);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ public DukeException(String input, String type) {
public String getMessage() {

String message = "An unknown exception has occurred.";
String word = input.trim().equals("event") || input.trim().equals("overlay") || input.trim().equals("addbar")
String word = input.trim().equals("event")
|| input.trim().equals("overlay")
|| input.trim().equals("addbar")
? "an " : "a ";

if (hasEmptyDescription(input)) {

message = "OOPS!!! The description of "
+ word
+ input.trim()
+ " task cannot be empty.";
+ " command cannot be empty.";
} else if (!type.equals("other")) {
switch (type) {
case "todo": {
Expand Down Expand Up @@ -90,6 +92,10 @@ public String getMessage() {
message = "OOPS!!! New bar cannot be added due to invalid input.";
break;
}
case "edit": {
message = "OOPS!!! Bar cannot be edited due to invalid input.";
break;
}
case "io": {
message = "OOPS!!! An IO exception has occurred.";
break;
Expand Down Expand Up @@ -139,6 +145,10 @@ public String getMessage() {
message = "OOPS!!! The data is corrupted.";
break;
}
case "AsciiCommand": {
message = "OOPS!!! Your Ascii Command is not recognised.";
break;
}
default: {
message = "OOPS!!! I'm sorry, but I don't know what that means :-(";
}
Expand Down
33 changes: 22 additions & 11 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package duke;

import duke.commands.AddBarCommand;
import duke.commands.AddCommand;
import duke.commands.AddOverlayCommand;
import duke.commands.ByeCommand;
import duke.commands.Command;
import duke.commands.ViewCommand;
import duke.commands.GroupCommand;
import duke.commands.NewCommand;
import duke.commands.HelpCommand;
import duke.commands.CopyCommand;
import duke.commands.ByeCommand;
import duke.commands.ListCommand;
import duke.commands.AddOverlayCommand;
import duke.commands.DeleteBarCommand;
import duke.commands.DeleteCommand;
import duke.commands.FindCommand;
import duke.commands.DoneCommand;
import duke.commands.AddBarCommand;
import duke.commands.AddCommand;

import duke.commands.EditCommand;
import duke.commands.FindCommand;
import duke.commands.GroupCommand;
import duke.commands.HelpCommand;
import duke.commands.ListCommand;
import duke.commands.NewCommand;
import duke.commands.ViewCommand;


/**
Expand Down Expand Up @@ -48,6 +49,16 @@ static Command parse(String message) throws DukeException {
return new DeleteCommand(message);
}
break;
case "deletebar":
if (message.length() >= 11) {
return new DeleteBarCommand(message);
}
break;
case "edit":
if (message.length() >= 6) {
return new EditCommand(message);
}
break;
case "find":
if (message.length() >= 6) {
return new FindCommand(message);
Expand Down
75 changes: 56 additions & 19 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package duke;

import duke.commands.Command;
import duke.commands.CommandSyntaxMessage;
import duke.components.Bar;
import duke.components.Song;
import duke.components.SongList;
import duke.tasks.RecurringTask;
import duke.tasks.Task;

Expand Down Expand Up @@ -144,23 +144,44 @@ public String formatDone(ArrayList<Task> list, int index) {
}

/**
* Returns a String formatted for display that indicates that a task has been deleted by
* the done command.
* Returns a String formatted for display that indicates that a song has been deleted by
* the delete command.
*
* @param list the task list prior to deletion
* @param index the index of the item that was deleted
* @param songList the song list after deletion
* @param deletedSong the song that was deleted
* @return the formatted String to be displayed
*/
public String formatDelete(ArrayList<Task> list,ArrayList<Task> newList, int index) {
String word = (list.size() == 2) ? "task" : "tasks";
String result = "Noted! I've removed this task:\n "
+ list.get(index - 1).toString()
public String formatDelete(SongList songList, Song deletedSong) {
String word = (songList.getSize() == 1) ? "song" : "songs";
String result = "Noted! I've removed this song:\n "
+ deletedSong.getName()
+ "\n"
+ "Now you have "
+ (newList.size())
+ (songList.getSize())
+ " "
+ word
+ " in the list.";
+ " in the SongList.";
return wrap(result);
}

/**
* Returns a String formatted for display that indicates that a bar has been deleted by
* the deletebar command.
*
* @param song the song after deletion
* @param deletedBar the bar that was deleted
* @return the formatted String to be displayed
*/
public String formatDeleteBar(Song song, Bar deletedBar) {
String word = (song.getBars().size() == 1) ? "bar" : "bars";
String result = "Noted! I've removed bar: "
+ (deletedBar.getId() + 1)
+ "\n"
+ "Now you have "
+ (song.getBars().size())
+ " "
+ word
+ " in the song.";
return wrap(result);
}

Expand Down Expand Up @@ -235,15 +256,16 @@ public String formatNewSong(ArrayList<Song> list, Song song) {
* @return the formatted String to be displayed
*/
public String formatHelp(String helpMessage) throws DukeException {
return CommandSyntaxMessage.getMessage(helpMessage);
return wrap(CommandSyntaxMessage.getMessage(helpMessage));
}

/**
* Returns a String that contains all the commands with their command name and format.
* @return the formatted command syntax
*/
public String formatHelp() {
return CommandSyntaxMessage.getMessage();
String output = CommandSyntaxMessage.getMessage();
return wrap(CommandSyntaxMessage.getMessage());
}

/**
Expand All @@ -265,8 +287,6 @@ public String formatView(Song song) {
*/
public String formatAddBar(ArrayList<Song> list, Bar bar, Song song) {
String word = (list.size() == 1) ? "bar" : "bars";
return bar.toString();
/*
String result = "Got it. I've added this bar:\n "
+ bar.toString()
+ "\nto "
Expand All @@ -276,12 +296,30 @@ public String formatAddBar(ArrayList<Song> list, Bar bar, Song song) {
+ " "
+ word
+ " in the song.";
System.out.print("adding the bar here");
return wrap(result);
}

*/

/**
* Returns a String formatted for display that indicates that a duke.components.Bar object has been edited
* by the edit command.
*
* @param oldBar the previous bar that was changed
* @param newBar the new bar
* @param song the item that was modified
* @return the formatted String to be displayed
*/
public String formatEdit(Bar oldBar, Bar newBar, Song song) {
String result = "Got it. I've edited this bar:\n "
+ oldBar.toString()
+ "\nNow you have "
+ newBar.toString()
+ " "
+ "in the song "
+ song.getName()
+ ".";
return wrap(result);
}

/**
* Returns a String formatted for display that indicates that
* a duke.components.AddOverlay object has been created
Expand All @@ -291,7 +329,6 @@ public String formatAddBar(ArrayList<Song> list, Bar bar, Song song) {
* @param song the song that is being copied to
* @return the formatted String to be displayed
*/

public String formatAddOverlay(ArrayList<Song> list, int index,Song song) {
String result = "Got it. I've added this overlay:\n "
+ "bar" + new Integer(index).toString() + "\nto "
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/duke/commands/AddBarCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import duke.components.Song;
import duke.components.SongList;

import javax.sound.midi.Soundbank;
import java.util.ArrayList;

//@@author jwyf
/**
* A class representing the command to add a new bar of notes to the current song.
*/
Expand Down Expand Up @@ -45,7 +45,7 @@ public String execute(SongList songList, Ui ui, Storage storage) throws DukeExce
String[] sections = message.substring(7).split(" ");
barNo = Integer.parseInt(sections[0].substring(4));

int notesIndex = message.indexOf(sections[1]); // todo
int notesIndex = message.indexOf(sections[1]);

Bar newBar = new Bar(barNo, message.substring(notesIndex));

Expand All @@ -57,14 +57,17 @@ public String execute(SongList songList, Ui ui, Storage storage) throws DukeExce
try {
ArrayList<Song> temp = songList.getSongList();
System.out.println("i have gotten the song list");
return ui.formatAddBar(temp, newBar, song);
//return ui.formatAddBar(temp, newBar, song);
} catch (Exception e) {
//System.out.println(e.getMessage());
return "hello myfddafadf ";
}
//
storage.updateFile(songList);
ArrayList<Song> temp = songList.getSongList();
return ui.formatAddBar(temp, newBar, song);

} catch (Exception e) {
//System.out.println(e.getMessage());
throw new DukeException(message, "addbar");
}
}
Expand Down
Loading

0 comments on commit ae1cf6d

Please sign in to comment.