package net.sourceforge.barbecue;


import net.sourceforge.barbecue.linear.code128.CharBuffer;
import net.sourceforge.barbecue.output.Output;
import net.sourceforge.barbecue.output.OutputException;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 作用请见 {@link CharBuffer}
 *
 * @author sunyj
 * @since 2017/11/13 11:42
 */
public class Module implements Serializable {

    private static final long serialVersionUID = 1L;

    protected final int[] bars;
    private String symbol;

    public Module(int[] var1) {
        this.bars = var1;
    }

    public String getSymbol() {
        return this.symbol;
    }

    public void setSymbol(String var1) {
        this.symbol = var1;
    }

    public int widthInBars() {
        int var1 = 0;

        for (int var2 = 0; var2 < this.bars.length; ++var2) {
            var1 += this.bars[var2];
        }

        return var1;
    }

    protected int draw(Output var1, int var2, int var3, int var4, int var5) throws OutputException {
        int var6 = 0;

        for (int var7 = 0; var7 < this.bars.length; ++var7) {
            int var8 = this.bars[var7];
            int var9 = var8 * var4;
            var6 += var1.drawBar(var2, var3, var9, var5, var7 % 2 == 0);
            var2 += var9;
        }

        return var6;
    }

    public boolean equals(Object var1) {
        if (this == var1) {
            return true;
        } else if (!(var1 instanceof Module)) {
            return false;
        } else {
            Module var2 = (Module) var1;
            return Arrays.equals(this.bars, var2.bars);
        }
    }

    public int hashCode() {
        int var1 = 0;

        for (int var2 = 0; var2 < this.bars.length; ++var2) {
            var1 += (var2 + 1) * this.bars[var2];
        }

        return var1;
    }

    public String toString() {
        StringBuffer var1 = new StringBuffer();

        for (int var2 = 0; var2 < this.bars.length; ++var2) {
            if (var2 > 0) {
                var1.append(", ");
            }

            var1.append(this.bars[var2]);
        }

        return var1.toString();
    }
}
