complex-barcode/maxicode-structured-codetext.js

const { MwMaxiCodeStandartSecondMessage, MwMaxiCodeStructuredSecondMessage, instanceOf } = require("../_mwbridge/_mw-bridge.js");

const MaxiCodeCodetext = require("./maxicode-codetext");
const MaxiCodeStructuredSecondMessage  = require("./maxicode-structured-second-message");
const MaxiCodeStandardSecondMessage  = require("./maxicode-standard-second-message.js");
const BarcodeException  = require("../barcode-exception");
const {MwMaxiCodeStandardSecondMessage} = require("../_mwbridge/_mw-bridge");
/**
 * Base class for encoding and decoding the text embedded in the MaxiCode code for modes 2 and 3.
 *
 *  @example
 *  This sample shows how to decode raw MaxiCode codetext to MaxiCodeStructuredCodetext instance.
 *
 *  let reader = new BarCodeReader("c:\\test.png", null, DecodeType.MAXI_CODE);
 *  let results = reader.readBarCodes();
 *  for(let i = 0; i < results.length; i++)
 *  {
 *     let result = results[i];
 *      let resultMaxiCodeCodetext = ComplexCodetextReader.tryDecodeMaxiCode(result.getExtended().getMaxiCode().getMaxiCodeMode(), result.getCodeText());
 *      if (resultMaxiCodeCodetext instanceof MaxiCodeStructuredCodetext)
 *      {
 *          let maxiCodeStructuredCodetext = resultMaxiCodeCodetext;
 *          console.log("BarCode Type: " + maxiCodeStructuredCodetext.getPostalCode());
 *          console.log("MaxiCode mode: " + maxiCodeStructuredCodetext.getCountryCode());
 *          console.log("BarCode CodeText: " + maxiCodeStructuredCodetext.getServiceCategory());
 *      }
 *  }
 */
class MaxiCodeStructuredCodetext extends MaxiCodeCodetext
{
    maxiCodeSecondMessage;

    constructor(mwObject)
    {
        try
        {
            super(mwObject);
        }
        catch (ex)
        {
            throw new BarcodeException(ex);
        }
    }

    _initializeWrapperMembers()
    {
        let mwMaxiCodeSecondMessage = this.getJavaClass().getSecondMessageSync();
        let mwMaxiCodeStandardSecondMessage = new MwMaxiCodeStandardSecondMessage();
        let mwMaxiCodeStructuredSecondMessage = new MwMaxiCodeStructuredSecondMessage();

        if(mwMaxiCodeSecondMessage === null)
        {
            this.maxiCodeSecondMessage = null;
        }
        else if(instanceOf(mwMaxiCodeSecondMessage, mwMaxiCodeStandardSecondMessage))
        {
            this.maxiCodeSecondMessage = MaxiCodeStandardSecondMessage._fromMwObject(MwMaxiCodeStandardSecondMessage.asMwMaxiCodeStandardSecondMessageSync(this.getJavaClass().getSecondMessageSync()));
        }
        else if(instanceOf(mwMaxiCodeSecondMessage, mwMaxiCodeStructuredSecondMessage))
        {
            this.maxiCodeSecondMessage = MaxiCodeStructuredSecondMessage._fromMwObject(MwMaxiCodeStructuredSecondMessage.asMwMaxiCodeStructuredSecondMessageSync(this.getJavaClass().getSecondMessageSync()));
        }
    }

    /**
     * Identifies the postal code. Must be 9 digits in mode 2 or<br>
     * 6 alphanumeric symbols in mode 3.
     */
    getPostalCode()
    {
        return this.getJavaClass().getPostalCodeSync();
    }

    /**
     * Identifies the postal code. Must be 9 digits in mode 2 or
     * 6 alphanumeric symbols in mode 3.
     */
    setPostalCode(value)
    {
        this.getJavaClass().setPostalCodeSync(value);
    }

    /**
     * Identifies 3 digit country code.
     */
    getCountryCode()
    {
        return this.getJavaClass().getCountryCodeSync();
    }

    /**
     * Identifies 3 digit country code.
     */
    setCountryCode(value)
    {
        this.getJavaClass().setCountryCodeSync(value);
    }

    /**
     * Identifies 3 digit service category.
     */
    getServiceCategory()
    {
        return this.getJavaClass().getServiceCategorySync();
    }

    /**
     * Identifies 3 digit service category.
     */
    setServiceCategory(value)
    {
        this.getJavaClass().setServiceCategorySync(value);
    }

    /**
     * Identifies second message of the barcode.
     */
    getSecondMessage()
    {
        return this.maxiCodeSecondMessage;
    }

    /**
     * Identifies second message of the barcode.
     */
    setSecondMessage(value)
    {
        this.maxiCodeSecondMessage = value;
        this.getJavaClass().setSecondMessageSync(value.getJavaClass());
    }

    /**
     * Constructs codetext
     * @return Constructed codetext
     */
    getConstructedCodetext()
    {
        return this.getJavaClass().getConstructedCodetextSync();
    }

    /**
     * Initializes instance from constructed codetext.
     * @param constructedCodetext Constructed codetext.
     */
    initFromString(constructedCodetext)
    {
        this.getJavaClass().initFromStringSync(constructedCodetext);
    }

    /**
     * Returns a value indicating whether this instance is equal to a specified <see cref="MaxiCodeStructuredCodetext"/> value.
     * @param obj An <see cref="MaxiCodeStructuredCodetext"/> value to compare to this instance
     * @return <b>true</b> if obj has the same value as this instance; otherwise, <b>false</b>
     */
    equals(obj)
    {
        return this.getJavaClass().equalsSync(obj.getJavaClass());
    }

    /**
     * Returns the hash code for this instance.
     * @return A 32-bit signed integer hash code.
     */
    getHashCode()
    {
        return this.getJavaClass().getHashCodeSync();
    }
}

module.exports = MaxiCodeStructuredCodetext