Skip to content

Commit

Permalink
Merge pull request #24 from ongweekeong/master
Browse files Browse the repository at this point in the history
Message Class
  • Loading branch information
iamputradanish committed Sep 27, 2018
2 parents f2682d7 + 37e96eb commit a9194dd
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 1 deletion.
2 changes: 2 additions & 0 deletions notifications.txt
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Inbox/>
35 changes: 35 additions & 0 deletions src/seedu/addressbook/inbox/Inbox.java
@@ -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
}*/
}
83 changes: 83 additions & 0 deletions src/seedu/addressbook/inbox/Msg.java
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/inbox/NotificationManager.java
@@ -0,0 +1,4 @@
package seedu.addressbook.inbox;

public class NotificationManager {
}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/inbox/ReadNotification.java
@@ -0,0 +1,4 @@
package seedu.addressbook.inbox;

public class ReadNotification {
}
47 changes: 47 additions & 0 deletions src/seedu/addressbook/inbox/WriteNotification.java
@@ -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();
}

}
1 change: 0 additions & 1 deletion src/seedu/addressbook/storage/StorageFile.java
Expand Up @@ -19,7 +19,6 @@ public class StorageFile {

/** Default file path used if the user doesn't provide the file name. */
public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt";

/* Note: Note the use of nested classes below.
* More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
*/
Expand Down

0 comments on commit a9194dd

Please sign in to comment.