Package.java

package com.tradecloud.domain.model.ordermanagement;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.base.utils.ObjectUtil;

import javax.persistence.Entity;
import java.math.BigDecimal;
import java.math.MathContext;

@Entity
public class Package extends PersistenceBase {
    private String reference;
    private BigDecimal quantity;
    private BigDecimal length;
    private BigDecimal width;
    private BigDecimal height;
    private BigDecimal volume;
    private BigDecimal weight;
    private BigDecimal totalVolume;
    private BigDecimal totalWeight;

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public BigDecimal getLength() {
        return length;
    }

    public void setLength(BigDecimal length) {
        this.length = length;
    }

    public BigDecimal getWidth() {
        return width;
    }

    public void setWidth(BigDecimal width) {
        this.width = width;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public void setHeight(BigDecimal height) {
        this.height = height;
    }

    public BigDecimal getVolume() {
        this.volume = ObjectUtil.allNotNull(length, width, height, quantity)
                ? length.multiply(width).multiply(height).divide(BigDecimal.valueOf(1000000), MathContext.DECIMAL128)
                : BigDecimal.ZERO;
        return this.volume;
    }

    public void setVolume(BigDecimal volume) {
        this.volume = ObjectUtil.allNotNull(length, width, height, quantity)
                ? length.multiply(width).multiply(height).divide(BigDecimal.valueOf(1000000), MathContext.DECIMAL128)
                : BigDecimal.ZERO;
    }

    public BigDecimal getWeight() {
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public BigDecimal getTotalVolume() {
        return this.volume != null && this.quantity != null ? totalVolume = this.volume.multiply(this.quantity) :
                null;
    }

    public void setTotalVolume(BigDecimal totalVolume) {

    }

    public BigDecimal getTotalWeight() {
        return this.weight != null && this.quantity != null ? totalWeight = this.weight.multiply(this.quantity) :
                null;
    }

    public void setTotalWeight(BigDecimal totalWeight) {

    }
}