forked from NewtonGluten/CS401-Group-Four-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved MessageStatus enum into its own file.
- Loading branch information
1 parent
5c7d32a
commit 3adce74
Showing
2 changed files
with
94 additions
and
0 deletions.
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,90 @@ | ||
package commsProj; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
import java.io.Serializable; | ||
|
||
import java.text.SimpleDateFormat; | ||
|
||
public class ChatMessage implements Serializable { | ||
private static final long serialVersionUID = 3852684761703377574L; | ||
private String id; | ||
private Date timestamp; | ||
private String sender; | ||
private String contents; | ||
private MessageStatus status; | ||
|
||
public ChatMessage(String userId, String contents, MessageStatus status) { | ||
id = UUID.randomUUID().toString(); | ||
timestamp = new Date(); | ||
sender = userId; | ||
this.contents = contents; | ||
this.status = status; | ||
} | ||
|
||
public ChatMessage(String userId, Date timestamp, String contents) { | ||
id = UUID.randomUUID().toString(); | ||
this.timestamp = timestamp; | ||
sender = userId; | ||
this.contents = contents; | ||
status = MessageStatus.Delivered; | ||
} | ||
|
||
public ChatMessage(String line) { | ||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-yy HH:mm:ss"); | ||
//starts at 2nd char and is length 36 | ||
try { | ||
id = line.substring(1, 37); | ||
|
||
String userId = ""; | ||
int i = 39; | ||
while (line.charAt(i) != '@') { | ||
userId += line.charAt(i); | ||
i++; | ||
} | ||
sender = userId; | ||
i++; | ||
String date = ""; | ||
while (line.charAt(i) != ']') { | ||
date += line.charAt(i); | ||
i++; | ||
} | ||
timestamp = simpleDateFormat.parse(date); | ||
i += 2; | ||
contents = line.substring(i); | ||
status = MessageStatus.Delivered; | ||
} catch(Exception e) { | ||
|
||
} | ||
|
||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public Date getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public String getSender() { | ||
return sender; | ||
} | ||
|
||
public String contents() { | ||
return contents; | ||
} | ||
|
||
public MessageStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(MessageStatus status) { | ||
this.status = status; | ||
} | ||
|
||
public String toString() { | ||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-yy HH:mm:ss"); | ||
return '[' + id + "][" + sender + '@' + simpleDateFormat.format(timestamp) + "]:" + contents; | ||
} | ||
} |
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 commsProj; | ||
public enum MessageStatus { | ||
Pending, Delivered | ||
} |