@Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        } else if (o == null) {
            return false;
        }

        if (o instanceof final CharBuffer cb) {
            final int len1 = end - start;
            final int len2 = cb.end - cb.start;

            if (len1 != len2) {
                return false;
            }
            for (int i = start, j = cb.start; i < len1; ) {
                if (buffer[i++] != cb.buffer[j++]) {
                    return false;
                }
            }
            return true;
        } else if (o instanceof final CharSequence charSequence) {
            return (end - start) == charSequence.length() && toString().equals(charSequence.toString());
        }

        return false;
    }
Sets the length of the string to a certain size. This will effectively
trim the string if the length specified is less than the current length.
If the length is greater than the current length then more characters
will be included from the underlying buffer.
stroom-util/src/main/java/stroom/util/CharBuffer.java