Dimension.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;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

import java.io.Serializable;
import java.util.Objects;

/**
 * A Dimension encapsulates the capacity.
 */
@Embeddable
public class Dimension implements Serializable {

    @Column(name = "C_HEIGHT")
    private int height;
    @Column(name = "C_LENGTH")
    private int length;
    @Column(name = "C_WIDTH")
    private int width;
    /** The Unit of Measure (UOM) of each dimension value. */
    @Column(name = "C_UOM")
    private String uom;

    /** Dear JPA... */
    protected Dimension() { }

    public Dimension(int height, int length, int width, String uom) {
        this.height = height;
        this.length = length;
        this.width = width;
        this.uom = uom;
    }

    public int getHeight() {
        return height;
    }

    public int getLength() {
        return length;
    }

    public int getWidth() {
        return width;
    }

    public String getUom() {
        return uom;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dimension dimension = (Dimension) o;
        return height == dimension.height && length == dimension.length && width == dimension.width && Objects.equals(uom, dimension.uom);
    }

    @Override
    public int hashCode() {
        return Objects.hash(height, length, width, uom);
    }

    @Override
    public String toString() {
        return "Dimension{" +
                "height=" + height +
                ", length=" + length +
                ", width=" + width +
                ", uom='" + uom + '\'' +
                '}';
    }
}