added Javadoc in Class Message

This commit is contained in:
schrom01 2022-04-12 12:36:43 +02:00
parent 7e7333dfaf
commit 56200b749d
1 changed files with 30 additions and 0 deletions

View File

@ -1,11 +1,21 @@
package ch.zhaw.pm2.multichat.client; package ch.zhaw.pm2.multichat.client;
/**
A Message object represents one Message of a client. Can be stored in ClientMessageList.
*/
public class Message { public class Message {
private MessageType type; private MessageType type;
private String sender; private String sender;
private String receiver; private String receiver;
private String text; private String text;
/**
* Constructor of Message. Needs all Information about a Message to save them.
* @param type Message (if it's a message typed by a user), Error or Information (if it is generated automatically, in this case sender and reciever will be null)
* @param sender The User who has sent the message.
* @param receiver The User who should recieve the message.
* @param text The Text of the message.
*/
public Message(MessageType type, String sender, String receiver, String text) { public Message(MessageType type, String sender, String receiver, String text) {
this.type = type; this.type = type;
this.sender = sender; this.sender = sender;
@ -13,28 +23,48 @@ public class Message {
this.text = text; this.text = text;
} }
/**
* Checks if the Filter String is contained in one of the datafields sender, receiver or text
* @param filter The Filter String
* @return true if it the Filter String is contained in a datafield.
*/
public boolean matchesFilter(String filter){ public boolean matchesFilter(String filter){
return (sender != null && sender.contains(filter)) || return (sender != null && sender.contains(filter)) ||
(receiver != null && receiver.contains(filter)) || (receiver != null && receiver.contains(filter)) ||
(text != null && text.contains(filter)); (text != null && text.contains(filter));
} }
/**
* @return The type of the message.
*/
public MessageType getType() { public MessageType getType() {
return type; return type;
} }
/**
* @return The User who has sent the Message.
*/
public String getSender() { public String getSender() {
return sender; return sender;
} }
/**
* @return The Reciever who recieves the Message.
*/
public String getReceiver() { public String getReceiver() {
return receiver; return receiver;
} }
/**
* @return The Text of the Message.
*/
public String getText() { public String getText() {
return text; return text;
} }
/**
* Enummeration of Message Types.
*/
public enum MessageType { public enum MessageType {
INFO, MESSAGE, ERROR; INFO, MESSAGE, ERROR;
} }