2019-11-23 21:16:03 +01:00
|
|
|
package org.mercury_im.messenger.data.mapping;
|
|
|
|
|
2019-12-26 08:46:55 +01:00
|
|
|
import org.mercury_im.messenger.util.Optional;
|
|
|
|
|
2019-11-25 15:17:49 +01:00
|
|
|
/**
|
|
|
|
* Interface that defines a mapping between entities and database models.
|
|
|
|
*
|
|
|
|
* @param <E> Entity
|
|
|
|
* @param <M> Model
|
|
|
|
*/
|
|
|
|
public interface Mapping<E, M> {
|
2019-11-23 21:16:03 +01:00
|
|
|
|
2019-11-25 15:17:49 +01:00
|
|
|
/**
|
2019-12-07 02:04:31 +01:00
|
|
|
* Map data from the entity to a new model.
|
2019-11-25 15:17:49 +01:00
|
|
|
*
|
|
|
|
* @param entity application entity
|
2019-12-07 02:04:31 +01:00
|
|
|
* @return new database model
|
|
|
|
*/
|
|
|
|
M toModel(E entity);
|
|
|
|
|
2019-12-26 08:46:55 +01:00
|
|
|
Optional<M> toModel(Optional<E> entity);
|
|
|
|
|
2019-12-07 02:04:31 +01:00
|
|
|
/**
|
|
|
|
* Copy data from the model to a new entity.
|
2019-11-25 15:17:49 +01:00
|
|
|
* @param model database model
|
2019-12-07 02:04:31 +01:00
|
|
|
* @return new application entity
|
2019-11-25 15:17:49 +01:00
|
|
|
*/
|
2019-12-07 02:04:31 +01:00
|
|
|
E toEntity(M model);
|
2019-11-23 21:16:03 +01:00
|
|
|
|
2019-12-26 08:46:55 +01:00
|
|
|
Optional<E> toEntity(Optional<M> model);
|
|
|
|
|
2019-11-25 15:17:49 +01:00
|
|
|
/**
|
2019-12-07 02:04:31 +01:00
|
|
|
* Map an entity to a model.
|
2019-11-25 15:17:49 +01:00
|
|
|
*
|
|
|
|
* @param entity entity
|
2019-12-07 02:04:31 +01:00
|
|
|
* @param model model
|
|
|
|
* @return model
|
2019-11-25 15:17:49 +01:00
|
|
|
*/
|
2019-12-07 02:04:31 +01:00
|
|
|
M toModel(E entity, M model);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map a model to an entity.
|
|
|
|
*
|
|
|
|
* @param model model
|
|
|
|
* @param entity entity
|
|
|
|
* @return entity
|
|
|
|
*/
|
|
|
|
E toEntity(M model, E entity);
|
|
|
|
|
|
|
|
|
2019-11-23 21:16:03 +01:00
|
|
|
}
|