diff --git a/barcode4j/src/main/java/org/krysalis/barcode4j/BarGroup.java b/barcode4j/src/main/java/org/krysalis/barcode4j/BarGroup.java index 819c2cc..490fa9a 100644 --- a/barcode4j/src/main/java/org/krysalis/barcode4j/BarGroup.java +++ b/barcode4j/src/main/java/org/krysalis/barcode4j/BarGroup.java @@ -15,45 +15,78 @@ */ package org.krysalis.barcode4j; -import java.util.Map; - /** * Enumeration type for bar groups. * * @author Jeremias Maerki * @version $Id: BarGroup.java,v 1.3 2004-10-02 14:53:22 jmaerki Exp $ */ -public class BarGroup { +public enum BarGroup { + + /** + * Used to indicate a start character when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + START_CHARACTER("start-char"), + + /** + * Used to indicate a stop character when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + STOP_CHARACTER("stop-char"), - private static final Map MAP = new java.util.HashMap<>(); + /** + * Used to indicate a message character when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + MSG_CHARACTER("msg-char"), - /** Bar group is represents a start character */ - public static final BarGroup START_CHARACTER = new BarGroup("start-char", MAP); - /** Bar group is represents a stop character */ - public static final BarGroup STOP_CHARACTER = new BarGroup("stop-char", MAP); - /** Bar group is represents a message character or a part of the message */ - public static final BarGroup MSG_CHARACTER = new BarGroup("msg-char", MAP); - /** Bar group is represents a UPC/EAN guard */ - public static final BarGroup UPC_EAN_GUARD = new BarGroup("upc-ean-guard", MAP); - /** Bar group is represents a UPC/EAN lead */ - public static final BarGroup UPC_EAN_LEAD = new BarGroup("upc-ean-lead", MAP); - /** Bar group is represents a UPC/EAN character group */ - public static final BarGroup UPC_EAN_GROUP = new BarGroup("upc-ean-group", MAP); - /** Bar group is represents a UPC/EAN check character */ - public static final BarGroup UPC_EAN_CHECK = new BarGroup("upc-ean-check", MAP); - /** Bar group is represents a UPC/EAN supplemental */ - public static final BarGroup UPC_EAN_SUPP = new BarGroup("upc-ean-supp", MAP); + /** + * Used to indicate a UPC/EAN Guard when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + UPC_EAN_GUARD("upc-ean-guard"), + + /** + * Used to indicate a UPC/EAN Lead when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + UPC_EAN_LEAD("upc-ean-lead"), + + /** + * Used to indicate a UPC/EAN character group when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + UPC_EAN_GROUP("upc-ean-group"), + + /** + * Used to indicate a UPC/EAN check character when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + UPC_EAN_CHECK("upc-ean-check"), + + /** + * Used to indicate a UPC/EAN supplemental when calling startBarGroup() + * + * @see ClassicBarcodeLogicHandler#startBarGroup(BarGroup, String) + */ + UPC_EAN_SUPP("upc-ean-supp"); private final String name; /** * Creates a new BarGroup instance. * @param name name of the BarGroup - * @param map Map to register the instance in. */ - protected BarGroup(String name, final Map map) { + BarGroup(final String name) { this.name = name; - MAP.put(name, this); } /** @@ -63,17 +96,4 @@ public String getName() { return this.name; } - /** - * Returns a BarGroup instance by name. - * @param name the name of the desired BarGroup - * @return the requested BarGroup instance - */ - public static BarGroup byName(String name) { - final BarGroup bg = MAP.get(name); - if (bg == null) { - throw new IllegalArgumentException("Invalid BarGroup: " + name); - } - return bg; - } - } diff --git a/barcode4j/src/main/java/org/krysalis/barcode4j/HumanReadablePlacement.java b/barcode4j/src/main/java/org/krysalis/barcode4j/HumanReadablePlacement.java index c705e03..567963b 100644 --- a/barcode4j/src/main/java/org/krysalis/barcode4j/HumanReadablePlacement.java +++ b/barcode4j/src/main/java/org/krysalis/barcode4j/HumanReadablePlacement.java @@ -1,12 +1,12 @@ /* * Copyright 2002-2004 Jeremias Maerki. - * + * * 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. @@ -16,57 +16,53 @@ package org.krysalis.barcode4j; /** - * Enumeration for placement of the human readable part of a barcode. - * + * Enumeration for placement of the human-readable part of a barcode. + * * @author Jeremias Maerki * @version $Id: HumanReadablePlacement.java,v 1.3 2004-10-02 14:53:22 jmaerki Exp $ */ -public class HumanReadablePlacement { +public enum HumanReadablePlacement { /** The human-readable part is suppressed. */ - public static final HumanReadablePlacement HRP_NONE - = new HumanReadablePlacement("none"); + HRP_NONE("none"), /** The human-readable part is placed at the top of the barcode. */ - public static final HumanReadablePlacement HRP_TOP - = new HumanReadablePlacement("top"); + HRP_TOP("top"), /** The human-readable part is placed at the bottom of the barcode. */ - public static final HumanReadablePlacement HRP_BOTTOM - = new HumanReadablePlacement("bottom"); + HRP_BOTTOM("bottom"); + + private final String name; - private String name; - /** * Creates a new HumanReadablePlacement instance. * @param name the name for the instance */ - protected HumanReadablePlacement(String name) { + HumanReadablePlacement(final String name) { this.name = name; } - + /** * @return the name of the instance. */ public String getName() { return this.name; } - + /** * Returns a HumanReadablePlacement instance by name. * @param name the name of the instance * @return the requested instance */ - public static HumanReadablePlacement byName(String name) { - if (name.equalsIgnoreCase(HumanReadablePlacement.HRP_NONE.getName())) { - return HumanReadablePlacement.HRP_NONE; - } else if (name.equalsIgnoreCase(HumanReadablePlacement.HRP_TOP.getName())) { - return HumanReadablePlacement.HRP_TOP; - } else if (name.equalsIgnoreCase(HumanReadablePlacement.HRP_BOTTOM.getName())) { - return HumanReadablePlacement.HRP_BOTTOM; - } else { - throw new IllegalArgumentException( - "Invalid HumanReadablePlacement: " + name); + public static HumanReadablePlacement byName(final String name) { + switch (name.toLowerCase()) { + case "none": + return HumanReadablePlacement.HRP_NONE; + case "top": + return HumanReadablePlacement.HRP_TOP; + case "bottom": + return HumanReadablePlacement.HRP_BOTTOM; + default: + throw new IllegalArgumentException("Invalid HumanReadablePlacement: " + name); } } - -} \ No newline at end of file +} diff --git a/barcode4j/src/main/java/org/krysalis/barcode4j/TextAlignment.java b/barcode4j/src/main/java/org/krysalis/barcode4j/TextAlignment.java index 9030eec..5b55f85 100644 --- a/barcode4j/src/main/java/org/krysalis/barcode4j/TextAlignment.java +++ b/barcode4j/src/main/java/org/krysalis/barcode4j/TextAlignment.java @@ -45,25 +45,4 @@ public String getName() { return this.name; } - /** - * Returns a TextAlignment instance by name. - * @param name the name of the instance - * @return the requested instance - * @deprecated not needed, just use the enum values - */ - @Deprecated - public static TextAlignment byName(final String name) { - if (name.equalsIgnoreCase(TextAlignment.TA_LEFT.getName())) { - return TextAlignment.TA_LEFT; - } else if (name.equalsIgnoreCase(TextAlignment.TA_CENTER.getName())) { - return TextAlignment.TA_CENTER; - } else if (name.equalsIgnoreCase(TextAlignment.TA_RIGHT.getName())) { - return TextAlignment.TA_RIGHT; - } else if (name.equalsIgnoreCase(TextAlignment.TA_JUSTIFY.getName())) { - return TextAlignment.TA_JUSTIFY; - } else { - throw new IllegalArgumentException("Invalid TextAlignment: " + name); - } - } - }