OSDN Git Service

modify append()
authorOlyutorskii <olyutorskii@users.osdn.me>
Sun, 25 Mar 2018 18:21:25 +0000 (03:21 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Sun, 25 Mar 2018 18:21:25 +0000 (03:21 +0900)
src/main/java/jp/osdn/jindolf/parser/content/DecodedContent.java
src/test/java/jp/osdn/jindolf/parser/content/DecodedContentTest.java

index 9bfcd61..6edf26a 100644 (file)
@@ -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<DecodeErrorInfo> sourceErrorList;
+
+        List<DecodeErrorInfo> srcErrList;
         if(source.hasDecodeError()){
-            sourceErrorList = source.decodeError;
+            srcErrList = source.decodeError;
         }else{
             return this;
         }
 
-        List<DecodeErrorInfo> targetErrorList;
-        if(source != this) targetErrorList = this.decodeError;
-        else               targetErrorList = null;
+        List<DecodeErrorInfo> 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;
index 73c88a4..ace1695 100644 (file)
@@ -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();