class CIDRange
{

    private final int from;
    private int to;
    private final int unicode;
    private final int codeLength;

    /**
     * Constructor.
     * 
     * @param from       start value of COD range
     * @param to         end value of CID range
     * @param unicode        unicode start value
     * @param codeLength byte length of CID values
     */
    CIDRange(int from, int to, int unicode, int codeLength)
    {
        this.from = from;
        this.to = to;
        this.unicode = unicode;
        this.codeLength = codeLength;
    }

    /**
     * Returns the byte length of the codes of the CID range.
     * 
     * @return the code length
     */
    public int getCodeLength()
    {
        return codeLength;
    }

    /**
     * Maps the given Unicode character to the corresponding CID in this range.
     *
     * @param bytes Unicode character
     * @return corresponding CID, or -1 if the character is out of range
     */
    public int map(byte[] bytes)
    {
        if (bytes.length == codeLength)
        {
            int ch = CMap.toInt(bytes);
            if (from <= ch && ch <= to)
            {
                return unicode + (ch - from);
            }
        }
        return -1;
    }

    /**
     * Maps the given Unicode character to the corresponding CID in this range.
     *
     * @param code   Unicode character
     * @param length origin byte length of the code
     * @return corresponding CID, or -1 if the character is out of range
     */
    public int map(int code, int length)
    {
        if (length == codeLength && from <= code && code <= to)
        {
            return unicode + (code - from);
        }
        return -1;
    }

    /**
     * Maps the given CID to the corresponding Unicode character in this range.
     *
     * @param code CID
     * @return corresponding Unicode character, or -1 if the CID is out of range
     */
    public int unmap(int code)
    {
        if (unicode <= code && code <= unicode + (to - from))
        {
            return from + (code - unicode);
        }
        return -1;
    }

    /**
     * Check if the given values represent a consecutive range of the given range. If so, extend the given range instead of
     * creating a new one.
     * 
     * @param newFrom start value of the new range
     * @param newTo   end value of the new range
     * @param newCid  start CID value of the range
     * @param length  byte length of CIDs
     * @return true if the given range was extended
     */
    public boolean extend(int newFrom, int newTo, int newCid, int length)
    {<FILL_FUNCTION_BODY>}

}

        if (codeLength == length && (newFrom == to + 1) && (newCid == unicode + to - from + 1))
        {
            to = newTo;
            return true;
        }
        return false;
    
<no_super_class>