Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koneru9999 committed May 25, 2024
1 parent 836bfd9 commit 796893a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {

/**
* Set number of printing labels per cut. 0<= pieces <=65535.
* Shall append the this command with the number of pieces.
* Shall append the command with the number of pieces.
*/
PARTIAL_CUTTER_PIECES(DeviceConfigCommand.PARTIAL_CUTTER, PartialCutterValues.Pieces),

Expand All @@ -64,7 +64,7 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {

/**
* Set number of printing labels per cut. 0<= pieces <=65535.
* Shall append the this command with the number of pieces.
* Shall append the command with the number of pieces.
*/
CUTTER_PIECES(DeviceConfigCommand.CUTTER, PartialCutterValues.Pieces),

Expand Down Expand Up @@ -108,15 +108,15 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {
*/
ENCODER_OFF(DeviceConfigCommand.ENCODER, EncoderCommandValues.OFF);

private DeviceConfigCommand command;
private CommandValues commandValue;
private final DeviceConfigCommand command;
private final CommandValues<String> commandValue;

/**
* @param command
* @param commandValue
*/
TSPLDeviceConfigurationCommands(DeviceConfigCommand command,
CommandValues commandValue) {
CommandValues<String> commandValue) {
this.command = command;
this.commandValue = commandValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,75 +107,72 @@ public class AztecBarcode implements TSPLCommand {
*/
@Override
public String getCommand() {
validateRequiredFields();

return new StringBuilder(AZTEC.name())
.append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(rotation.getRotation()).append(COMMA)
.append(getModuleSizeCommandPart())
.append(getErrorControlCommandPart())
.append(getEscapeFlagCommandPart())
.append(getMenuCommandPart())
.append(getMultiCommandPart())
.append(getRevCommandPart())
.append(getBytesCommandPart())
.append(content)
.append(LF)
.toString();
}

private void validateRequiredFields() {
if (xCoordinate == null || yCoordinate == null) {
throw new LabelParserException("AZTEC: x and y positions are required");
}

if (rotation == null) {
throw new LabelParserException("AZTEC: rotation is required");
}

if (moduleSize != null && (moduleSize < 1 || moduleSize > 20)) {
throw new LabelParserException("AZTEC: invalid module size value");
}

if (errorControl != null && (errorControl == 100
|| (errorControl > 104 && errorControl <= 200)
|| (errorControl > 232 && errorControl < 300)
|| (errorControl > 300))) {
if (errorControl != null && checkInvalidErrorControl()) {
throw new LabelParserException("AZTEC: invalid error control parameter");
}
}

StringBuilder commandBuilder = new StringBuilder(AZTEC.name());
commandBuilder.append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(rotation.getRotation()).append(COMMA);

if (moduleSize == null) {
commandBuilder.append("6").append(COMMA);
} else {
commandBuilder.append(moduleSize).append(COMMA);
}

if (errorControl == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(errorControl).append(COMMA);
}

commandBuilder.append(escapeFlag).append(COMMA);
private boolean checkInvalidErrorControl() {
return errorControl == 100
|| (errorControl > 104 && errorControl <= 200)
|| (errorControl > 232 && errorControl < 300)
|| (errorControl > 300);
}

if (menu == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(menu ? "1" : "0").append(COMMA);
}
private String getModuleSizeCommandPart() {
return (moduleSize == null ? "6" : moduleSize) + COMMA;
}

if (multi == null) {
commandBuilder.append("6").append(COMMA);
} else {
commandBuilder.append(multi).append(COMMA);
}
private String getErrorControlCommandPart() {
return (errorControl == null ? "0" : errorControl) + COMMA;
}

if (rev == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(rev ? "1" : "0").append(COMMA);
}
private String getEscapeFlagCommandPart() {
return escapeFlag + COMMA;
}

if (bytes != null) {
commandBuilder.append(bytes).append(COMMA)
.append("\"");
}
private String getMenuCommandPart() {
return (menu == null ? "0" : (menu ? "1" : "0")) + COMMA;
}

commandBuilder.append(content);
private String getMultiCommandPart() {
return (multi == null ? "6" : multi) + COMMA;
}

if (bytes != null) {
commandBuilder.append("\"");
}
private String getRevCommandPart() {
return (rev == null ? "0" : (rev ? "1" : "0")) + COMMA;
}

commandBuilder.append(LF);
return commandBuilder.toString();
private String getBytesCommandPart() {
return bytes == null ? "" : bytes + COMMA + '"';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public String getCommand() {
throw new LabelParserException("BAR: height is required");
}

return LabelFormatCommand.BAR.name() + EMPTY_SPACE
+ xCoordinate + COMMA
+ yCoordinate + COMMA
+ width + COMMA
+ height
+ LF;
return new StringBuilder(LabelFormatCommand.BAR.name()).append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(width).append(COMMA)
.append(height).append(LF)
.toString();
}
}

0 comments on commit 796893a

Please sign in to comment.