From 8847199149538f79462a03b07fe94fd81c887d69 Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Mon, 26 Mar 2018 03:21:25 +0900 Subject: [PATCH] modify append() --- .../jindolf/parser/content/DecodedContent.java | 29 ++++++++++++---------- .../jindolf/parser/content/DecodedContentTest.java | 6 +++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/jp/osdn/jindolf/parser/content/DecodedContent.java b/src/main/java/jp/osdn/jindolf/parser/content/DecodedContent.java index 9bfcd61..6edf26a 100644 --- a/src/main/java/jp/osdn/jindolf/parser/content/DecodedContent.java +++ b/src/main/java/jp/osdn/jindolf/parser/content/DecodedContent.java @@ -412,6 +412,7 @@ public class DecodedContent * @param len 追加される char の数 * @return thisオブジェクト * @throws IndexOutOfBoundsException 範囲指定が不正。 + * @see StringBuffer#append(char[], int, int) */ public DecodedContent append(char[] str, int offset, int len) throws IndexOutOfBoundsException{ @@ -427,6 +428,7 @@ public class DecodedContent * @param endPos 終了位置 * @return thisオブジェクト * @throws IndexOutOfBoundsException 範囲指定が変。 + * @see Appendable#append(CharSequence, int, int) */ public DecodedContent append(DecodedContent source, int startPos, int endPos) @@ -446,31 +448,32 @@ public class DecodedContent int oldLength = this.rawContent.length(); this.rawContent.append(source.rawContent, startPos, endPos); - List sourceErrorList; + + List srcErrList; if(source.hasDecodeError()){ - sourceErrorList = source.decodeError; + srcErrList = source.decodeError; }else{ return this; } - List targetErrorList; - if(source != this) targetErrorList = this.decodeError; - else targetErrorList = null; + List dstErrList; + if(source == this) dstErrList = null; + else dstErrList = this.decodeError; int gap = startPos - oldLength; - targetErrorList = appendGappedErrorInfo(sourceErrorList, - startPos, endPos, - targetErrorList, - gap); + dstErrList = appendGappedErrorInfo(srcErrList, + startPos, endPos, + dstErrList, + gap); - if(targetErrorList == null) return this; - if(targetErrorList == this.decodeError) return this; + if(dstErrList == null) return this; + if(dstErrList == this.decodeError) return this; if(this.decodeError == null){ - this.decodeError = targetErrorList; + this.decodeError = dstErrList; }else{ - this.decodeError.addAll(targetErrorList); + this.decodeError.addAll(dstErrList); } return this; diff --git a/src/test/java/jp/osdn/jindolf/parser/content/DecodedContentTest.java b/src/test/java/jp/osdn/jindolf/parser/content/DecodedContentTest.java index 73c88a4..ace1695 100644 --- a/src/test/java/jp/osdn/jindolf/parser/content/DecodedContentTest.java +++ b/src/test/java/jp/osdn/jindolf/parser/content/DecodedContentTest.java @@ -385,6 +385,8 @@ public class DecodedContentTest { seq = null; content.append(seq); assertEquals("abcdefnull", content.toString()); + content.append(new DecodedContent("dec")); + assertEquals("abcdefnulldec", content.toString()); return; } @@ -421,6 +423,10 @@ public class DecodedContentTest { assertEquals("23", content.toString()); content.init(); + content.append((CharSequence)new DecodedContent("PQR"), 1, 3); + assertEquals("QR", content.toString()); + + content.init(); try{ content.append(seq, 3, 1); fail(); -- 2.11.0