Barcode.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.transport.barcode;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Objects;
/**
* A Barcode is a printable item with a unique identifier to label {@code TransportUnit}s. The identifier has a defined number of
* characters whereas these characters are aligned either left or right. Non filled positions of a Barcode are padded with a so-called
* padding character.
*
* @author Heiko Scherrer
* @GlossaryTerm
*/
@Embeddable
public class Barcode implements Serializable {
/** 'Identifier' of the {@code Barcode}. <p> <i>Note:</i>It is not guaranteed that this field must be unique. </p> */
@Column(name = "C_BARCODE")
@NotBlank
private String value;
/*~ ----------------------------- constructors ------------------- */
/** Dear JPA... */
protected Barcode() {
}
private Barcode(String value) {
this.value = value;
}
/**
* Simple factory method to replace default constructor in application logic (still needed for framework stuff).
*
* @param value The value of the {@code Barcode} as String
* @return Formatted Barcode instance
*/
public static Barcode of(String value) {
return new Barcode(value);
}
/*~ ----------------------------- methods ------------------- */
/**
* Return the {@code Barcode} value.
*
* @return The value of the {@code Barcode}
*/
public String getValue() {
return value;
}
/**
* Set the {@code Barcode} value.
*
* @param value The value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* Return the value of the {@code Barcode} as String.
*
* @return As String
* @see #getValue()
*/
@Override
public String toString() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Barcode barcode = (Barcode) o;
return value.equals(barcode.value);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hash(value);
}
}