konta-walutowe/src/main/java/eu/ztsh/wymiana/util/CurrencyMapper.java

33 lines
1 KiB
Java

package eu.ztsh.wymiana.util;
import eu.ztsh.wymiana.data.entity.CurrencyEntity;
import eu.ztsh.wymiana.model.Currency;
import eu.ztsh.wymiana.model.Symbol;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CurrencyMapper {
public static Currency entityToPojo(CurrencyEntity entity) {
return new Currency(entity.getSymbol(), entity.getAmount());
}
public static CurrencyEntity pojoToEntity(Currency pojo, String pesel) {
return new CurrencyEntity(pesel, pojo.symbol(), pojo.amount());
}
public static Map<Symbol, Currency> entitiesToPojoMap(List<CurrencyEntity> values) {
return values.stream().map(CurrencyMapper::entityToPojo)
.collect(Collectors.toMap(Currency::symbol, pojo -> pojo));
}
public static List<CurrencyEntity> pojoMapToEntities(Map<Symbol, Currency> currencies, String pesel) {
return currencies.values().stream().map(entry -> pojoToEntity(entry, pesel)).toList();
}
private CurrencyMapper() {
}
}