mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-22 00:03:20 +00:00
Modification IMessageToolFactory et impl : suppr méthodes spécifiques, ajout méthodes génériques de formatter et de parser
This commit is contained in:
parent
524838cd09
commit
ca6d81423d
@ -23,99 +23,16 @@ public class GSonMessageToolFactory implements IMessageToolFactory {
|
||||
gson = new GsonBuilder().create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<Message> getMessageFormatter() {
|
||||
return getObjectFormatter(Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<Message> getMessageParser() {
|
||||
return (str)->gson.fromJson(str, Message.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<Product> getProductFormatter() {
|
||||
return getObjectFormatter(Product.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<Product> getProductParser() {
|
||||
return getObjectParser(Product.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<List<Product>> getProductListFormatter() {
|
||||
return getListFormatter(Product.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<List<Product>> getProductListParser() {
|
||||
return getListParser(Product.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<Sale> getSaleFormatter() {
|
||||
return getObjectFormatter(Sale.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<Sale> getSaleParser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<PqtMember> getPqtMemberFormatter() {
|
||||
return getObjectFormatter(PqtMember.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<PqtMember> getPqtMemberParser() {
|
||||
return getObjectParser(PqtMember.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<ProductUpdate> getProductUpdateFormatter() {
|
||||
return getObjectFormatter(ProductUpdate.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<ProductUpdate> getProductUpdateParser() {
|
||||
return getObjectParser(ProductUpdate.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<MessageType> getMessageTypeFormatter() {
|
||||
return getObjectFormatter(MessageType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<MessageType> getMessageTypeParser() {
|
||||
return getObjectParser(MessageType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectFormatter<PqtMemberType> getPqtMemberTypeFormatter() {
|
||||
return getObjectFormatter(PqtMemberType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectParser<PqtMemberType> getPqtMemberTypeParser() {
|
||||
return getObjectParser(PqtMemberType.class);
|
||||
}
|
||||
|
||||
private <T> IObjectFormatter<T> getObjectFormatter(Class<T> clazz){
|
||||
public <T> IObjectFormatter<T> getObjectFormatter(Class<T> clazz){
|
||||
return (obj)->gson.toJson(obj);
|
||||
}
|
||||
|
||||
private <T> IObjectParser<T> getObjectParser(Class<T> clazz){
|
||||
public <T> IObjectParser<T> getObjectParser(Class<T> clazz){
|
||||
return (str)->gson.fromJson(str, clazz);
|
||||
}
|
||||
|
||||
private <T> IObjectFormatter<List<T>> getListFormatter(Class<T> clazz){
|
||||
public <T> IObjectFormatter<List<T>> getListFormatter(Class<T> clazz){
|
||||
return (obj)->gson.toJson(obj);
|
||||
}
|
||||
|
||||
private <T> IObjectParser<List<T>> getListParser(Class<T> clazz){
|
||||
public <T> IObjectParser<List<T>> getListParser(Class<T> clazz){
|
||||
Type listType = new TypeToken<ArrayList<T>>(){}.getType();
|
||||
return (str)->gson.fromJson(str, listType);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pqt.core.communication;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.pqt.core.entities.members.PqtMember;
|
||||
import com.pqt.core.entities.members.PqtMemberType;
|
||||
import com.pqt.core.entities.messages.Message;
|
||||
@ -8,39 +9,17 @@ import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.core.entities.sale.Sale;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface IMessageToolFactory {
|
||||
|
||||
IObjectFormatter<Message> getMessageFormatter();
|
||||
<T> IObjectFormatter<T> getObjectFormatter(Class<T> clazz);
|
||||
|
||||
IObjectParser<Message> getMessageParser();
|
||||
<T> IObjectParser<T> getObjectParser(Class<T> clazz);
|
||||
|
||||
IObjectFormatter<Product> getProductFormatter();
|
||||
<T> IObjectFormatter<List<T>> getListFormatter(Class<T> clazz);
|
||||
|
||||
IObjectParser<Product> getProductParser();
|
||||
|
||||
IObjectFormatter<List<Product>> getProductListFormatter();
|
||||
|
||||
IObjectParser<List<Product>> getProductListParser();
|
||||
|
||||
IObjectFormatter<Sale> getSaleFormatter();
|
||||
|
||||
IObjectParser<Sale> getSaleParser();
|
||||
|
||||
IObjectFormatter<PqtMember> getPqtMemberFormatter();
|
||||
|
||||
IObjectParser<PqtMember> getPqtMemberParser();
|
||||
|
||||
IObjectFormatter<ProductUpdate> getProductUpdateFormatter();
|
||||
|
||||
IObjectParser<ProductUpdate> getProductUpdateParser();
|
||||
|
||||
IObjectFormatter<MessageType> getMessageTypeFormatter();
|
||||
|
||||
IObjectParser<MessageType> getMessageTypeParser();
|
||||
|
||||
IObjectFormatter<PqtMemberType> getPqtMemberTypeFormatter();
|
||||
|
||||
IObjectParser<PqtMemberType> getPqtMemberTypeParser();
|
||||
<T> IObjectParser<List<T>> getListParser(Class<T> clazz);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user