All Downloads are FREE. Search and download functionalities are using the official Maven repository.

global.maplink.freight.schema.FreightCalculationResponse Maven / Gradle / Ivy

The newest version!
package global.maplink.freight.schema;

import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import static lombok.AccessLevel.PRIVATE;

@Data
@Builder
@RequiredArgsConstructor(staticName = "of")
@NoArgsConstructor(force = true, access = PRIVATE)
public class FreightCalculationResponse {
    private final String source;
    private final Map>> results;
    private final BigDecimal minimumFreight;
    private final BigDecimal minimumFreightWithCosts;

    public Optional getResult(OperationType operationType, Integer axis, GoodsType goodsType) {
        return Optional.ofNullable(results)
                .map(byKey(operationType))
                .map(byKey(axis))
                .map(byKey(goodsType));
    }

    private  Function, R> byKey(T key) {
        return (map) -> map.get(key);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy