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.
34 lines
819 B
Java
34 lines
819 B
Java
package com.glxp.api.util.gs1;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
import java.util.Collection;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @author guilherme.pacheco
|
|
*/
|
|
public final class Gs1128Encoder {
|
|
|
|
Gs1128Encoder() {
|
|
super();
|
|
}
|
|
|
|
public String encode(Collection<Segment> segments) {
|
|
Validate.notEmpty(segments);
|
|
String barcode = joinSegments(segments);
|
|
return checkBarcode(barcode);
|
|
}
|
|
|
|
private String checkBarcode(String barcode) {
|
|
return StringUtils.removeEnd(barcode, String.valueOf(Gs1128Utils.END_AI_VARIED));
|
|
}
|
|
|
|
private String joinSegments(Collection<Segment> segments) {
|
|
String joinValue = segments.stream().map(Segment::encode).collect(Collectors.joining());
|
|
return Gs1128Utils.PREFIX.concat(joinValue);
|
|
}
|
|
|
|
}
|