Suppr clss Field, modif attr fields dans clss Message, ajout méthds hasField(..) et getField(...) dans clss Message

This commit is contained in:
Notmoo 2017-07-23 21:42:18 +02:00
parent fbdb2682cc
commit d2d45d93a0
3 changed files with 18 additions and 28 deletions

View File

@ -1,22 +0,0 @@
package com.pqt.core.entities.messages;
import java.io.Serializable;
public class Field implements Serializable{
private String header;
private String data;
public Field(String header, String data) {
this.header = header;
this.data = data;
}
public String getHeader() {
return header;
}
public String getData() {
return data;
}
}

View File

@ -3,11 +3,13 @@ package com.pqt.core.entities.messages;
import com.pqt.core.entities.members.PqtMember; import com.pqt.core.entities.members.PqtMember;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class Message { public class Message {
private List<Field> fields; private Map<String, String> fields;
private MessageType type; private MessageType type;
private PqtMember emitter, receiver; private PqtMember emitter, receiver;
@ -15,17 +17,27 @@ public class Message {
this(type, emitter, receiver, null); this(type, emitter, receiver, null);
} }
public Message(MessageType type, PqtMember emitter, PqtMember receiver, List<Field> fields) { public Message(MessageType type, PqtMember emitter, PqtMember receiver, Map<String, String> fields) {
this.emitter = emitter; this.emitter = emitter;
this.receiver = receiver; this.receiver = receiver;
this.type = type; this.type = type;
this.fields = new ArrayList<>(); this.fields = new HashMap<>();
if(fields!=null) if(fields!=null)
this.fields.addAll(fields); for(String key : fields.keySet()){
this.fields.put(key, fields.get(key));
}
} }
public List<Field> getFields() { public Map<String, String> getFields() {
return new ArrayList<>(fields); return new HashMap<>(fields);
}
public boolean hasField(String header){
return fields.containsKey(header);
}
public String getField(String header){
return fields.get(header);
} }
public PqtMember getEmitter() { public PqtMember getEmitter() {