protected void append()

in src/main/java/org/apache/pdfbox/jbig2/decoder/huffman/InternalNode.java [46:109]


    protected void append(Code c)
    {
        // ignore unused codes
        if (c.prefixLength == 0)
            return;

        int shift = c.prefixLength - 1 - depth;

        if (shift < 0)
            throw new IllegalArgumentException("Negative shifting is not possible.");

        int bit = (c.code >> shift) & 1;
        if (shift == 0)
        {
            if (c.rangeLength == -1)
            {
                // the child will be a OutOfBand
                if (bit == 1)
                {
                    if (one != null)
                        throw new IllegalStateException("already have a OOB for " + c);
                    one = new OutOfBandNode(c);
                }
                else
                {
                    if (zero != null)
                        throw new IllegalStateException("already have a OOB for " + c);
                    zero = new OutOfBandNode(c);
                }
            }
            else
            {
                // the child will be a ValueNode
                if (bit == 1)
                {
                    if (one != null)
                        throw new IllegalStateException("already have a ValueNode for " + c);
                    one = new ValueNode(c);
                }
                else
                {
                    if (zero != null)
                        throw new IllegalStateException("already have a ValueNode for " + c);
                    zero = new ValueNode(c);
                }
            }
        }
        else
        {
            // the child will be an InternalNode
            if (bit == 1)
            {
                if (one == null)
                    one = new InternalNode(depth + 1);
                ((InternalNode) one).append(c);
            }
            else
            {
                if (zero == null)
                    zero = new InternalNode(depth + 1);
                ((InternalNode) zero).append(c);
            }
        }
    }