Home / Class/ AppendableCharSequence Class — netty Architecture

AppendableCharSequence Class — netty Architecture

Architecture documentation for the AppendableCharSequence class in AppendableCharSequence.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  3c45deb3_208f_6378_979e_2c2209776324["AppendableCharSequence"]
  051333cb_703e_309b_fafb_d9f854ef7814["AppendableCharSequence.java"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|defined in| 051333cb_703e_309b_fafb_d9f854ef7814
  49c064f7_8d1d_a660_a31e_56a0797dca17["AppendableCharSequence()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| 49c064f7_8d1d_a660_a31e_56a0797dca17
  c46c927f_f600_a108_1ddf_9954dcbcd68b["setLength()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| c46c927f_f600_a108_1ddf_9954dcbcd68b
  ac3811da_365e_0b99_f4ef_bb314d19e632["length()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| ac3811da_365e_0b99_f4ef_bb314d19e632
  8c0747cc_b605_1631_f810_17df6e154f5d["charAt()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| 8c0747cc_b605_1631_f810_17df6e154f5d
  a95c8cbc_4089_8cbb_b693_c60de0b2bca4["charAtUnsafe()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| a95c8cbc_4089_8cbb_b693_c60de0b2bca4
  b7c0ec32_9542_47fc_a18e_f3d65d47f598["reset()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| b7c0ec32_9542_47fc_a18e_f3d65d47f598
  d4d6ad36_5db0_c503_bb74_1e70a77d50d1["String()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| d4d6ad36_5db0_c503_bb74_1e70a77d50d1
  d40dd526_f036_5cfa_1553_62b2628e159d["expand()"]
  3c45deb3_208f_6378_979e_2c2209776324 -->|method| d40dd526_f036_5cfa_1553_62b2628e159d

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/AppendableCharSequence.java lines 23–170

public final class AppendableCharSequence implements CharSequence, Appendable {
    private char[] chars;
    private int pos;

    public AppendableCharSequence(int length) {
        chars = new char[checkPositive(length, "length")];
    }

    private AppendableCharSequence(char[] chars) {
        this.chars = checkNonEmpty(chars, "chars");
        pos = chars.length;
    }

    public void setLength(int length) {
        if (length < 0 || length > pos) {
            throw new IllegalArgumentException("length: " + length + " (length: >= 0, <= " + pos + ')');
        }
        this.pos = length;
    }

    @Override
    public int length() {
        return pos;
    }

    @Override
    public char charAt(int index) {
        if (index > pos) {
            throw new IndexOutOfBoundsException();
        }
        return chars[index];
    }

    /**
     * Access a value in this {@link CharSequence}.
     * This method is considered unsafe as index values are assumed to be legitimate.
     * Only underlying array bounds checking is done.
     * @param index The index to access the underlying array at.
     * @return The value at {@code index}.
     */
    public char charAtUnsafe(int index) {
        return chars[index];
    }

    @Override
    public AppendableCharSequence subSequence(int start, int end) {
        if (start == end) {
            // If start and end index is the same we need to return an empty sequence to conform to the interface.
            // As our expanding logic depends on the fact that we have a char[] with length > 0 we need to construct
            // an instance for which this is true.
            return new AppendableCharSequence(Math.min(16, chars.length));
        }
        return new AppendableCharSequence(Arrays.copyOfRange(chars, start, end));
    }

    @Override
    public AppendableCharSequence append(char c) {
        if (pos == chars.length) {
            char[] old = chars;
            chars = new char[old.length << 1];
            System.arraycopy(old, 0, chars, 0, old.length);
        }
        chars[pos++] = c;
        return this;
    }

    @Override
    public AppendableCharSequence append(CharSequence csq) {
        return append(csq, 0, csq.length());
    }

    @Override
    public AppendableCharSequence append(CharSequence csq, int start, int end) {
        if (csq.length() < end) {
            throw new IndexOutOfBoundsException("expected: csq.length() >= ("
                    + end + "),but actual is (" + csq.length() + ")");
        }
        int length = end - start;
        if (length > chars.length - pos) {
            chars = expand(chars, pos + length, pos);
        }

Frequently Asked Questions

What is the AppendableCharSequence class?
AppendableCharSequence is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/AppendableCharSequence.java.
Where is AppendableCharSequence defined?
AppendableCharSequence is defined in common/src/main/java/io/netty/util/internal/AppendableCharSequence.java at line 23.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free