/**
* JSON文字出力用ビジター。
- * <p>
- * JSON Valueのトラバース時にこのビジターを指定すると、
+ *
+ * <p>JSON Valueのトラバース時にこのビジターを指定すると、
* 事前に用意した文字出力先にJSONフォーマットで出力される。
- * </p>
- * <p>
- * 出力に伴う{@link java.io.IOException}は
+ *
+ * <p>出力に伴う{@link java.io.IOException}は
* {@link JsVisitException}のチェーン例外となる。
- * </p>
- * <p>
- * 前回パースの成功/失敗に関わらず、
+ *
+ * <p>前回パースの成功/失敗に関わらず、
* インスタンスの再利用時の挙動は保証されない。
- * </p>
*/
class JsonAppender implements ValueVisitor {
private final Appendable appout;
private final Stack<DumpContext> contextStack =
- new Stack<DumpContext>();
+ new Stack<>();
private IOException ioException = null;
/**
* コンストラクタ。
+ *
* @param appout 出力先
* @throws NullPointerException 引数がnull
*/
/**
* コンテキストをプッシュ退避する。
+ *
* @param composition 現在のコンテキスト
*/
- protected void pushComposition(JsComposition composition){
+ protected void pushComposition(JsComposition<?> composition){
DumpContext context = new DumpContext(composition);
this.contextStack.push(context);
return;
/**
* コンテキストをポップ復帰する。
+ *
* @return スタックトップのコンテキスト
* @throws EmptyStackException スタック構造が空
*/
- protected JsComposition popComposition() throws EmptyStackException{
+ protected JsComposition<?> popComposition() throws EmptyStackException{
DumpContext context = this.contextStack.pop();
- JsComposition composition = context.getComposition();
+ JsComposition<?> composition = context.getComposition();
return composition;
}
/**
* ネスト構造の深さを返す。
+ *
* @return 0から始まる深さ
*/
protected int nestDepth(){
/**
* ネスト構造が空(深さ0)か判定する。
+ *
* @return 空ならtrue
*/
protected boolean isNestEmpty(){
/**
* ネスト後、一つでも子要素が出力されたか判定する。
+ *
* @return 子要素が出力されていればtrue
*/
protected boolean hasChildDumped(){
/**
* 現在のコンテキストがARRAY型配列要素出力中の状態か否か判定する。
+ *
* @return 現在のコンテキストがARRAY型配列要素出力中ならtrue
*/
protected boolean isArrayContext(){
if(isNestEmpty()) return false;
DumpContext context = this.contextStack.peek();
- JsComposition composition = context.getComposition();
+ JsComposition<?> composition = context.getComposition();
JsTypes type = composition.getJsTypes();
if(type != JsTypes.ARRAY) return false;
/**
* 1文字出力。
+ *
* @param ch 文字
* @throws JsVisitException 出力エラー。
+ *
* @see java.lang.Appendable#append(char)
*/
protected void append(char ch) throws JsVisitException{
/**
* 文字列出力。
+ *
* @param seq 文字列
* @throws JsVisitException 出力エラー。
+ *
* @see java.lang.Appendable#append(CharSequence)
*/
protected void append(CharSequence seq) throws JsVisitException{
/**
* 可能であれば出力先をフラッシュする。
+ *
* @throws JsVisitException 出力エラー
+ *
* @see java.io.Flushable
*/
protected void flush() throws JsVisitException{
/**
* トラバース中断の原因となったIOExceptionを返す。
+ *
* @return トラバース中断の原因となったIOException。なければnull。
*/
public IOException getIOException(){
/**
* トラバース中断の原因となったIOExceptionがあるか判定する。
+ *
* @return トラバース中断の原因となったIOExceptionがあればtrue
*/
public boolean hasIOException(){
/**
* pairの名前を出力する。
+ *
* @param name pair名
* @throws JsVisitException 出力エラー
*/
/**
* pair区切りコロンを出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putPairSeparator() throws JsVisitException{
/**
* 要素間区切りコンマを出力する。
- * JSONでは最後の要素の後にコンマを出力してはいけない。
+ *
+ * <p>JSONでは最後の要素の後にコンマを出力してはいけない。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putComma() throws JsVisitException{
/**
* 改行を出力する。
+ *
* @throws JsVisitException 出力エラー。
*/
protected void putNewLine() throws JsVisitException{
/**
* インデントを出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putIndent() throws JsVisitException{
/**
* OBJECT及びARRAY型の最初の要素の前部分を出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putBefore1stElement() throws JsVisitException{
/**
* OBJECT及びARRAY型の要素間区切りを出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putBetweenElement() throws JsVisitException{
/**
* OBJECT及びARRAY型の最後の要素の後部分を出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putAfterLastElement() throws JsVisitException{
/**
* OBJECT及びARRAY型の空要素を出力する。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putEmptyElement() throws JsVisitException{
/**
* パース前の出力を行う。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putBeforeParse() throws JsVisitException{
/**
* パース後の出力を行う。
+ *
* @throws JsVisitException 出力エラー
*/
protected void putAfterParse() throws JsVisitException{
/**
* {@inheritDoc}
- * Valueの出力を行う。
+ *
+ * <p>Valueの出力を行う。
+ *
* @param value {@inheritDoc}
* @throws JsVisitException {@inheritDoc}
*/
if(type.isComposition()){
assert value instanceof JsComposition;
- JsComposition composition = (JsComposition) value;
+ JsComposition<?> composition = (JsComposition) value;
pushComposition(composition);
}
/**
* {@inheritDoc}
- * OBJECT内の各pairの名前を出力する。
+ *
+ * <p>OBJECT内の各pairの名前を出力する。
+ *
* @param pairName {@inheritDoc}
* @throws JsVisitException {@inheritDoc}
*/
/**
* {@inheritDoc}
- * 閉じ括弧を出力する。
+ *
+ * <p>閉じ括弧を出力する。
+ *
* @param closed {@inheritDoc}
* @throws JsVisitException {@inheritDoc}
*/
@Override
- public void visitCompositionClose(JsComposition closed)
+ public void visitCompositionClose(JsComposition<?> closed)
throws JsVisitException{
boolean hasDumped = hasChildDumped();
- JsComposition composition = popComposition();
+ JsComposition<?> composition = popComposition();
if(hasDumped) putAfterLastElement();
else putEmptyElement();
* ネストされた各JSON集約型コンテキストの出力状況。
*/
private static class DumpContext{
- private final JsComposition composition;
+ private final JsComposition<?> composition;
private boolean childDumped;
/**
* コンストラクタ。
- * 子要素が出力された事実は無い状態で始まる。
+ *
+ * <p>子要素が出力された事実は無い状態で始まる。
+ *
* @param composition レベルに対応するOBJECTもしくはARRAY型Value
*/
- DumpContext(JsComposition composition){
+ DumpContext(JsComposition<?> composition){
this.composition = composition;
this.childDumped = false;
return;
/**
* このレベルに対応するJSON集約型を返す。
+ *
* @return OBJECTもしくはARRAY型Value
*/
- JsComposition getComposition(){
+ JsComposition<?> getComposition(){
return this.composition;
}
/**
* このレベルで子要素出力が行われたか判定する。
+ *
* @return 子要素出力が行われていたならtrue
*/
boolean hasChildDumped(){