Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iamputradanish/Main
Browse files Browse the repository at this point in the history
  • Loading branch information
iamputradanish committed Oct 11, 2018
2 parents b8036e7 + 81f0840 commit f1ce81b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 42 deletions.
33 changes: 5 additions & 28 deletions notifications.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 15:06:25.299
Message:Backup requested
-
-
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 15:09:10.673
Message:Backup requested
-
Expand All @@ -16,55 +9,39 @@ Message:Backup requested
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 15:12:45.753
Message:Backup requested
-
-
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 15:37:56.323
Message:Backup requested
-
Location:-6.206968,106.751365
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 15:38:03.65
Timestamp:2018-10-05 10:28:47.248
Message:Backup requested
-
Location:-6.206968,106.751365
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 16:04:13.287
Timestamp:2018-10-05 10:43:02.9
Message:Backup requested
-
Location:-6.206968,106.751365
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 16:04:17.549
Timestamp:2018-10-05 10:44:28.957
Message:Backup requested
-
Location:-6.206968,106.751365
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 16:04:43.17
Timestamp:2018-10-05 10:48:07.034
Message:Backup requested
-
Location:-6.206968,106.751365
> END OF MESSAGE <
> START OF MESSAGE <
Read status:false
Priority:HIGH
Timestamp:2018-10-04 16:05:10.314
Timestamp:2018-10-05 15:12:10.894
Message:Backup requested
-
Location:-6.206968,106.751365
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class Messages {
"java seedu.addressbook.Main [STORAGE_FILE_PATH]";
public static final String MESSAGE_WELCOME = "Welcome to your system.";
public static final String MESSAGE_USING_STORAGE_FILE = "Using storage file : %1$s";
public static final String MESSAGE_ENTER_PASSWORD = "Please enter password: ";
public static final String MESSAGE_ENTER_PASSWORD = "Please enter password. ";
public static final String MESSAGE_BATTERY_PERCENTAGE = "Battery level left: %d";
}
40 changes: 32 additions & 8 deletions src/seedu/addressbook/inbox/Inbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class Inbox {
public static int unreadMsgs = 0;
private Msg message;
private static ReadNotification nw = new ReadNotification(MESSAGE_STORAGE_FILEPATH);
static WriteNotification myMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH, true);
static WriteNotification newMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH, true);
static WriteNotification oldMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH, false);

protected static HashMap<Triplet<Boolean, Msg.Priority, Timestamp>, Triplet<String, Integer, Location>> notificationsToPrint = new HashMap<>();

Expand All @@ -37,26 +38,49 @@ public static void loadMsgs() throws IOException {
*/

public int checkNumUnreadMessages(HashMap notificationsToPrint){

return unreadMsgs;
}

public static void printMsg(){
public static void printNumOfUnreadMsg(){ // Set the read status of the messages to true.
if(unreadMsgs > 0)
System.out.println("You have " + unreadMsgs + " unread message" + ((unreadMsgs == 1) ? "." : "s."));
else System.out.println(unreadMsgs);
System.out.println("You have " + unreadMsgs + " new notification" + ((unreadMsgs == 1) ? "." : "s."));
else
System.out.println("You have no new notifications.");
}

/** Do the thing to print out new messages in the specified format.
* Messages will all be marked as read and rewritten in the new notifications file.
*
*/
public void printNewMsgs(){
// print new messages in order according to TreeMap. After messages are printed, they are considered old.
Msg myPrintMsg = new Msg();
// use pollFirstEntry/pollLastEntry to 'pop' the most urgent message to myPrintMsg

// After

myPrintMsg = markMsgasRead(myPrintMsg);
// use put to associate updated message into TreeMap.
notificationsToPrint.put(Triplet.with(myPrintMsg.isRead, myPrintMsg.getPriority(), myPrintMsg.getTime()),
Triplet.with(myPrintMsg.getMsg(), myPrintMsg.getEta(), myPrintMsg.getLocation()));
// After the whole process is done, rewrite notifications into notifications.txt.

}

public Msg markMsgasRead(Msg myMsg){ // Construct a new message, copy from TreeMap, then change read status, update.
myMsg.isRead = Msg.MESSAGE_IS_READ;
return myMsg;
}

public static void main(String[] args) throws IOException {
/*Msg newMsg = new Msg();
Msg newMsg = new Msg();
Location location = new Location(-6.206968,106.751365);
newMsg.addMsg("Backup requested");
newMsg.setLocation(location);
newMsg.setPriority(Msg.Priority.HIGH);
newMsg.setTime();
myMessages.writeToFile(newMsg);*/
newMessages.writeToFile(newMsg);
loadMsgs();
printMsg();
printNumOfUnreadMsg();
}
}
35 changes: 30 additions & 5 deletions src/seedu/addressbook/inbox/Msg.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Msg {
protected boolean isRead;
protected boolean isLocationAvailable;
private Timestamp time;
public static final boolean MESSAGE_IS_READ = true;
public static final boolean MESSAGE_IS_UNREAD = false;
public enum Priority {
HIGH, // For messages that require HPQ intervention
MED, // For messages that only require PO back-up
Expand All @@ -27,7 +29,34 @@ public enum Priority {

public Msg(){ // Create overloading constructors.
isLocationAvailable = false;
isRead = false;
isRead = MESSAGE_IS_UNREAD;
}

public Msg(Priority urgency, String message){
isLocationAvailable = false;
isRead = MESSAGE_IS_UNREAD;
priority = urgency;
time = new Timestamp(System.currentTimeMillis());
newMsg = message;
}

public Msg(Priority urgency, String message, Location myLocale){ // Constructor for request backup message
isLocationAvailable = true;
isRead = MESSAGE_IS_UNREAD;
priority = urgency;
time = new Timestamp(System.currentTimeMillis());
newMsg = message;
location = myLocale;
}

public Msg(Priority urgency, String message, Location requesterLocale, int myEta){ // Constructor for request backup message
isLocationAvailable = true; // An ack message should be sent to PO requesting
isRead = MESSAGE_IS_UNREAD; // backup, stating ETA of backup deployed.
priority = urgency;
time = new Timestamp(System.currentTimeMillis());
newMsg = message;
location = requesterLocale;
eta = myEta;
}

public void addMsg(String msg){
Expand Down Expand Up @@ -91,8 +120,4 @@ public void setTime(Timestamp time){
public Timestamp getTime(){
return this.time;
}

public void setComments(String comment){
this.comment = comment;
}
}
21 changes: 21 additions & 0 deletions src/seedu/addressbook/inbox/WriteNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,25 @@ public void writeToFile(Msg message) throws IOException{
myPrinter.close();
}

// Create overload function for write to file to write a set of notifications.
/*public void writeToFile(Hashmap) throws IOException{
FileWriter write = new FileWriter (path, isAppend);
PrintWriter myPrinter = new PrintWriter(write);
myPrinter.println("> START OF MESSAGE <");
myPrinter.println("Read status:" + message.isRead);
myPrinter.println("Priority:" + message.getPriority());
myPrinter.println("Timestamp:" + message.getTime());
myPrinter.println("Message:" + message.getMsg());
if(message.hasEta())
myPrinter.println("ETA:" + message.getEta());
else myPrinter.println('-');
if(message.isLocationAvailable) {
myPrinter.println("Location:" + message.getLatitude() + "," + message.getLongitude());
}
else myPrinter.println('-');
myPrinter.println("> END OF MESSAGE <"); // Notate the end of 1 message entry with "---"
myPrinter.close();
}*/

}

0 comments on commit f1ce81b

Please sign in to comment.