You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-third-java/src/main/java/com/glxp/mipsdl/util/gs1/Segment.java

36 lines
836 B
Java

package com.glxp.mipsdl.util.gs1;
import org.apache.commons.lang3.Validate;
/**
* @author guilherme.pacheco
*/
public final class Segment {
private final AI ai;
private final String value;
private final Format format;
public Segment(AI ai, String value) {
this.ai = Validate.notNull(ai, "Invalid AI");
format = Format.valueOf(ai.getFormat());
this.value = validateValue(format, value);
}
private String validateValue(Format format, String value) {
Validate.notBlank(value, "Invalid segment value");
Validate.notNull(format, "Invalid format");
Validate.isTrue(format.isValid(value));
return value;
}
String encode() {
String codeValue = ai.getCode().concat(value);
if (format.isVaried()) {
return codeValue + Gs1128Utils.END_AI_VARIED;
}
return codeValue;
}
}