JsonScope

因爲寫JsonReader和JsonWriter的時候有依賴,爲了便於說明問題。單獨把JsonScope列出來,請大家理解哈。
從這些常量,我們可以簡單的理解下Gson設計思想的一些方面,比如,邏輯層次、顆粒度等

隨着大家編碼經驗越來越多,相信很多人已經認識到了顆粒度劃分和層次劃分的重要,這行能力對大家轉型做設計(架構師)具有很大的意義。

EMPTY_DOCUMENT 和 NONEMPTY_DOCUMENT  文檔
EMPTY_ARRAY   和   NONEMPTY_ARRAY    數珠
EMPTY_OBJECT  和   NONEMPTY_OBJECT。 對象(和map類似,所有的值都是key-value的形式),先輸出key(name)然後才輸出value,所以需要增加一個常量DANGLING_NAME
CLOSED所有操作結束後變成close狀態,不能夠再做任何操作
/**
 * Lexical scoping elements within a JSON reader or writer.
 *
 * @author Jesse Wilson
 * @since 1.6
 */
final class JsonScope {

    /**
     * An array with no elements requires no separators or newlines before
     * it is closed.
     */
    static final int EMPTY_ARRAY = 1;

    /**
     * A array with at least one value requires a comma and newline before
     * the next element.
     */
    static final int NONEMPTY_ARRAY = 2;

    /**
     * An object with no name/value pairs requires no separators or newlines
     * before it is closed.
     */
    static final int EMPTY_OBJECT = 3;

    /**
     * An object whose most recent element is a key. The next element must
     * be a value.
     */
    static final int DANGLING_NAME = 4;

    /**
     * An object with at least one name/value pair requires a comma and
     * newline before the next element.
     */
    static final int NONEMPTY_OBJECT = 5;

    /**
     * No object or array has been started.
     */
    static final int EMPTY_DOCUMENT = 6;

    /**
     * A document with at an array or object.
     */
    static final int NONEMPTY_DOCUMENT = 7;

    /**
     * A document that's been closed and cannot be accessed.
     */
    static final int CLOSED = 8;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章