Allocation.java

/*
 * Copyright 2005-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openwms.wms.inventory.allocation;

import org.openwms.core.units.api.Measurable;
import org.openwms.wms.inventory.LoadUnit;
import org.openwms.wms.inventory.Product;
import org.openwms.wms.location.Location;
import org.openwms.wms.transport.TransportUnit;

import java.util.StringJoiner;

/**
 * An Allocation.
 *
 * @author Heiko Scherrer
 */
public class Allocation {

    private TransportUnit transportUnit;
    private LoadUnit loadUnit;
    private Product product;
    private Location actualLocation;
    private Measurable qtyAvailable;
    private String reservationId;

    public TransportUnit getTransportUnit() {
        return transportUnit;
    }

    public void setTransportUnit(TransportUnit transportUnit) {
        this.transportUnit = transportUnit;
    }

    public LoadUnit getLoadUnit() {
        return loadUnit;
    }

    public boolean hasLoadUnit() {
        return loadUnit != null;
    }

    public void setLoadUnit(LoadUnit loadUnit) {
        this.loadUnit = loadUnit;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Location getActualLocation() {
        return actualLocation;
    }

    public void setActualLocation(Location actualLocation) {
        this.actualLocation = actualLocation;
    }

    public Measurable getQtyAvailable() {
        return qtyAvailable;
    }

    public void setQtyAvailable(Measurable qtyAvailable) {
        this.qtyAvailable = qtyAvailable;
    }

    public String getReservationId() {
        return reservationId;
    }

    public void setReservationId(String reservationId) {
        this.reservationId = reservationId;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Allocation.class.getSimpleName() + "[", "]")
                .add("transportUnit=" + transportUnit)
                .add("loadUnit=" + loadUnit)
                .add("product=" + product)
                .add("actualLocation=" + actualLocation)
                .add("qtyAvailable=" + qtyAvailable)
                .add("reservationId='" + reservationId + "'")
                .toString();
    }

    public static final class AllocationBuilder {
        private TransportUnit transportUnit;
        private LoadUnit loadUnit;
        private Product product;
        private Location actualLocation;
        private Measurable qtyAvailable;
        private String reservationId;

        private AllocationBuilder() {
        }

        public static AllocationBuilder anAllocation() {
            return new AllocationBuilder();
        }

        public AllocationBuilder transportUnit(TransportUnit transportUnit) {
            this.transportUnit = transportUnit;
            return this;
        }

        public AllocationBuilder loadUnit(LoadUnit loadUnit) {
            this.loadUnit = loadUnit;
            return this;
        }

        public AllocationBuilder product(Product product) {
            this.product = product;
            return this;
        }

        public AllocationBuilder actualLocation(Location actualLocation) {
            this.actualLocation = actualLocation;
            return this;
        }

        public AllocationBuilder qtyAvailable(Measurable qtyAvailable) {
            this.qtyAvailable = qtyAvailable;
            return this;
        }

        public AllocationBuilder reservationId(String reservationId) {
            this.reservationId = reservationId;
            return this;
        }

        public Allocation build() {
            Allocation allocation = new Allocation();
            allocation.setTransportUnit(transportUnit);
            allocation.setLoadUnit(loadUnit);
            allocation.setProduct(product);
            allocation.setActualLocation(actualLocation);
            allocation.setQtyAvailable(qtyAvailable);
            allocation.setReservationId(reservationId);
            return allocation;
        }
    }
}