forked from nusCS2113-AY1819S1/addressbook-level3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ongweekeong/master
Message Class
- Loading branch information
Showing
7 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<Inbox/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.addressbook.inbox; | ||
|
||
public class Inbox { | ||
// all messages will be stored here, notifications will appear based on severity and timestamp. | ||
public static final String MESSAGE_STORAGE_FILEPATH = "notifications.txt"; | ||
public static final String COMMAND_WORD = "inbox"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Opens up list of unread notifications. \n\t" | ||
+ "Example: " + COMMAND_WORD; | ||
public static final String MESSAGE_PROMPT = "Press 'Enter' to take action for Message 1"; | ||
public static int unreadMsgs = 0; | ||
private Msg message; | ||
WriteNotification myMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH); | ||
|
||
public enum Priority{ | ||
HIGH, // For messages that require HPQ intervention | ||
MED, // For messages that only require PO back-up | ||
LOW // Messages that are FYI (e.g. Notifications to admin that details of subjects have changed | ||
} | ||
|
||
public Inbox(){ // A data structure must be created to store the messages from the message storage file. | ||
|
||
} | ||
|
||
|
||
|
||
/** Prints out all unread notifications ordered by priority, then timestamp (earlier first). | ||
* | ||
* @return messages to be printed out on the main window. | ||
*/ | ||
|
||
/*public String printMsg(){ | ||
//for (String s : messages) | ||
return | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package seedu.addressbook.inbox; | ||
|
||
import java.security.Timestamp; | ||
|
||
/** Msg has the following attributes: | ||
* @params Priority, timestamp, message, location (x,y coordinates) and ETA. | ||
* Priority, timestamp and message are compulsory fields. Location and ETA are optional. | ||
*/ | ||
|
||
|
||
public class Msg { | ||
private String newMsg; | ||
private Priority priority; | ||
private double x, y; | ||
private int eta = -1; | ||
private String comment; | ||
public boolean isRead = false; | ||
public boolean isLocationAvailable = false; | ||
private Timestamp time; | ||
private enum Priority { | ||
HIGH, // For messages that require HPQ intervention | ||
MED, // For messages that only require PO back-up | ||
LOW // Messages that are FYI (e.g. Notifications to admin that details of subjects have changed | ||
} | ||
|
||
public Msg(){ | ||
Msg message = new Msg(); | ||
} | ||
|
||
public void addMsg(String msg){ | ||
this.newMsg = msg; | ||
} | ||
|
||
public void setPriority(Priority urgency){ | ||
this.priority = urgency; | ||
} | ||
|
||
public Priority getPriority(){ | ||
return this.priority; | ||
} | ||
public String getMsg(){ | ||
return this.newMsg; | ||
} | ||
|
||
public void setLocation(double x, double y, double min){ | ||
this.x = x; | ||
this.y = y; | ||
isLocationAvailable = true; | ||
} | ||
|
||
public double getLongitude(){ | ||
return this.x; | ||
} | ||
|
||
public double getLatitude(){ | ||
return this.y; | ||
} | ||
public void setEta(int eta){ | ||
this.eta = eta; | ||
} | ||
public int getEta(){ | ||
return this.eta; | ||
} | ||
|
||
public boolean hasEta(){ | ||
if(eta == -1) | ||
return false; | ||
else | ||
return true; | ||
} | ||
|
||
public void setTime(Timestamp time){ | ||
this.time = time; | ||
} | ||
|
||
public Timestamp getTime(){ | ||
return this.time; | ||
} | ||
|
||
public void setComments(String comment){ | ||
this.comment = comment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package seedu.addressbook.inbox; | ||
|
||
public class NotificationManager { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package seedu.addressbook.inbox; | ||
|
||
public class ReadNotification { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.addressbook.inbox; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
public class WriteNotification { | ||
private String path; | ||
private boolean isAppend = false; | ||
|
||
public WriteNotification(String filePath){ | ||
path = filePath; | ||
} | ||
|
||
public WriteNotification(String filePath, boolean appendValue){ | ||
path = filePath; | ||
isAppend = appendValue; | ||
} | ||
|
||
|
||
/** Message format should look like this | ||
* Read/Unread (1 or 0) --> for writeToFile function, messages are entered as unread. | ||
* Priority of Message | ||
* Timestamp of message | ||
* Message | ||
* ETA, if applicable | ||
* Location, if available | ||
*/ | ||
|
||
public void writeToFile(Msg message) throws IOException{ | ||
FileWriter write = new FileWriter (path, isAppend); | ||
PrintWriter myPrinter = new PrintWriter(write); | ||
myPrinter.println(message.isRead); | ||
myPrinter.println(message.getPriority()); | ||
myPrinter.println(message.getTime()); | ||
myPrinter.println(message.getMsg()); | ||
if(message.hasEta()) | ||
myPrinter.println(message.getEta()); | ||
if(message.isLocationAvailable) { | ||
myPrinter.println(message.getLatitude()); | ||
myPrinter.println(message.getLongitude()); | ||
} | ||
myPrinter.println("---"); // Notate the end of 1 message entry with "---" | ||
myPrinter.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters