4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sourceforge.jovsonz;
10 import java.io.IOException;
15 * <p>Javaのnullとは一切無関係。
24 public final class JsNull
25 implements JsValue, Comparable<JsNull> {
28 public static final JsNull NULL = new JsNull();
31 public static final String TEXT = "null";
34 public static final int ONLYHASH = 982451653; // 大きな素数;
47 * JSON文字列ソースからNULL型Valueを読み込む。
49 * <p>別型の可能性のある先頭文字を読み込んだ場合、
50 * ソースに文字を読み戻した後nullが返される。
52 * @param source 文字列ソース
53 * @return NULL型Value。別型の可能性がある場合はnull。
54 * @throws IOException 入力エラー
55 * @throws JsParseException 不正トークンもしくは意図しない入力終了
57 static JsNull parseNull(JsonSource source)
58 throws IOException, JsParseException{
59 char charHead = source.readOrDie();
62 source.unread(charHead);
66 if( ! source.matchOrDie("ull") ){
67 throw new JsParseException(JsParseException.ERRMSG_INVALIDTOKEN,
68 source.getLineNumber() );
77 * <p>常に{@link JsTypes#NULL}を返す。
79 * @return {@inheritDoc}
82 public JsTypes getJsTypes(){
89 * <p>この実装ではthisの出現のみを通知する。
91 * @param visitor {@inheritDoc}
92 * @throws JsVisitException {@inheritDoc}
95 public void traverse(ValueVisitor visitor)
96 throws JsVisitException{
97 visitor.visitValue(this);
105 * 常に{@value ONLYHASH}を返す。
107 * @return {@inheritDoc}
110 public int hashCode(){
118 * {@link #NULL}が渡された時のみtrueを返す。
120 * @param obj {@inheritDoc}
121 * @return {@inheritDoc}
124 public boolean equals(Object obj){
125 if(this == obj) return true;
126 if(obj instanceof JsNull) return true; // シングルトンには冗長
133 * <p>NULL型Valueを順序付ける。シングルトン相手にほぼ無意味。
136 * @param value {@inheritDoc}
137 * @return {@inheritDoc}
138 * @throws NullPointerException 引数がnull
141 public int compareTo(JsNull value) throws NullPointerException{
142 if(value == null) throw new NullPointerException();
150 * 常に文字列 {@value TEXT} を返す。
151 * JSON表記の一部としての利用も可能。
153 * @return {@inheritDoc}
156 public String toString(){