OSDN Git Service

clear checkstyle warning
authorOlyutorskii <olyutorskii@users.osdn.me>
Sun, 9 Apr 2017 03:13:55 +0000 (12:13 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Sun, 9 Apr 2017 03:13:55 +0000 (12:13 +0900)
pmdrules.xml
src/main/java/jp/sourceforge/jindolf/parser/AbstractParser.java
src/main/java/jp/sourceforge/jindolf/parser/ContentBuilderSJ.java
src/main/java/jp/sourceforge/jindolf/parser/DecodeException.java
src/main/java/jp/sourceforge/jindolf/parser/EntityConverter.java
src/main/java/jp/sourceforge/jindolf/parser/ShiftJis.java
src/test/java/jp/sourceforge/jindolf/parser/ContentBuilderSJTest.java

index 09e1d3e..6cac6e8 100644 (file)
@@ -60,6 +60,7 @@
 
     <rule ref="rulesets/java/design.xml">
         <exclude name="UnnecessaryLocalBeforeReturn" />
+        <exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
     </rule>
 
     <rule ref="rulesets/java/empty.xml" />
@@ -84,6 +85,7 @@
 
     <rule ref="rulesets/java/naming.xml">
         <exclude name="ShortVariable" />
+        <exclude name="LongVariable" />
     </rule>
 
     <rule ref="rulesets/java/optimizations.xml">
index ac5dbb6..85dfc7f 100644 (file)
@@ -192,8 +192,8 @@ public abstract class AbstractParser implements ChainedParser{
      */
     protected boolean findProbe(Pattern pattern){
         switchPattern(pattern);
-        if( getMatcher().find() ) return true;
-        return false;
+        boolean result = getMatcher().find();
+        return result;
     }
 
     /**
@@ -203,8 +203,8 @@ public abstract class AbstractParser implements ChainedParser{
      */
     protected boolean lookingAtProbe(Pattern pattern){
         switchPattern(pattern);
-        if( getMatcher().lookingAt() ) return true;
-        return false;
+        boolean result = getMatcher().lookingAt();
+        return result;
     }
 
     /**
@@ -214,8 +214,8 @@ public abstract class AbstractParser implements ChainedParser{
      */
     protected boolean matchesProbe(Pattern pattern){
         switchPattern(pattern);
-        if( getMatcher().matches() ) return true;
-        return false;
+        boolean result = getMatcher().matches();
+        return result;
     }
 
     /**
@@ -266,8 +266,8 @@ public abstract class AbstractParser implements ChainedParser{
      * @return ヒットしていたらtrue
      */
     protected boolean isGroupMatched(int group){
-        if(matchStart(group) >= 0) return true;
-        return false;
+        boolean result = matchStart(group) >= 0;
+        return result;
     }
 
     /**
@@ -355,18 +355,24 @@ public abstract class AbstractParser implements ChainedParser{
         for( ; regionStart < regionEnd; regionStart++){
             char letter = rawContent.charAt(regionStart);
 
+            boolean spaceCh;
             switch(letter){
             case '\u0020':
             case '\t':
             case '\n':
             case '\r':
-                hasSpace = true;
-                continue;
+                spaceCh = true;
+                break;
             default:
+                spaceCh = false;
                 break;
             }
 
-            break;
+            if(spaceCh){
+                hasSpace = true;
+            }else{
+                break;
+            }
         }
 
         if(hasSpace){
index 0562067..bcb14a8 100644 (file)
@@ -99,14 +99,8 @@ public class ContentBuilderSJ extends ContentBuilder{
         int limit = offset + length;
         for(int bpos = offset; bpos < limit; bpos++){
             byte bval = errorArray[bpos];
-            if( ! this.hasByte1st){
-                if(ShiftJis.isShiftJIS1stByte(bval)){
-                    this.byte1st = bval;
-                    this.hasByte1st = true;
-                }else{
-                    getContent().addDecodeError(bval);
-                }
-            }else{
+
+            if(this.hasByte1st){
                 if(ShiftJis.isShiftJIS2ndByte(bval)){   // 文字集合エラー
                     getContent().addDecodeError(this.byte1st, bval);
                     this.hasByte1st = false;
@@ -119,7 +113,15 @@ public class ContentBuilderSJ extends ContentBuilder{
                     getContent().addDecodeError(bval);
                     this.hasByte1st = false;
                 }
+            }else{
+                if(ShiftJis.isShiftJIS1stByte(bval)){
+                    this.byte1st = bval;
+                    this.hasByte1st = true;
+                }else{
+                    getContent().addDecodeError(bval);
+                }
             }
+
         }
 
         return;
index e830595..85d0f54 100644 (file)
@@ -18,6 +18,9 @@ package jp.sourceforge.jindolf.parser;
 @SuppressWarnings("serial")
 public class DecodeException extends Exception{
 
+    private static final char CH_SP = '\u0020';
+
+
     private final int bytePos;
     private final int charPos;
 
@@ -87,15 +90,15 @@ public class DecodeException extends Exception{
      */
     @Override
     public String getMessage(){
-        StringBuilder result = new StringBuilder();
+        StringBuilder result = new StringBuilder(20);
 
         String message = super.getMessage();
         if(message != null && message.length() > 0){
-            result.append(message).append(' ');
+            result.append(message).append(CH_SP);
         }
 
         result.append("bytePos=").append(this.bytePos);
-        result.append(' ');
+        result.append(CH_SP);
         result.append("charPos=").append(this.charPos);
 
         return result.toString();
index ae18d4c..becd08f 100644 (file)
@@ -224,7 +224,7 @@ public class EntityConverter{
          * @param regex 置換元パターン正規表現
          * @param altTxt 置換文字列。
          */
-        private RegexRep(String regex, String altTxt){
+        RegexRep(String regex, String altTxt){
             this.regex = regex;
             this.altTxt = altTxt;
             return;
index 1e4b2fd..ab686da 100644 (file)
@@ -43,11 +43,10 @@ public final class ShiftJis{
      * @return シフトJISの1バイト目でありうるならtrue
      */
     public static boolean isShiftJIS1stByte(byte bval){
-        if(    (byte) 0x81 <= bval && bval <= (byte) 0x9f
-            || (byte) 0xe0 <= bval && bval <= (byte) 0xfc){
-            return true;
-        }
-        return false;
+        boolean result =
+               (byte) 0x81 <= bval && bval <= (byte) 0x9f
+            || (byte) 0xe0 <= bval && bval <= (byte) 0xfc;
+        return result;
     }
 
     /**
@@ -57,11 +56,10 @@ public final class ShiftJis{
      * @return シフトJISの2バイト目でありうるならtrue
      */
     public static boolean isShiftJIS2ndByte(byte bval){
-        if(    (byte) 0x40 <= bval && bval <= (byte) 0x7e
-            || (byte) 0x80 <= bval && bval <= (byte) 0xfc){
-            return true;
-        }
-        return false;
+        boolean result =
+               (byte) 0x40 <= bval && bval <= (byte) 0x7e
+            || (byte) 0x80 <= bval && bval <= (byte) 0xfc;
+        return result;
     }
 
     /**
@@ -72,11 +70,10 @@ public final class ShiftJis{
      * @return シフトJISならtrue
      */
     public static boolean isShiftJIS(byte b1st, byte b2nd){
-        if(    ShiftJis.isShiftJIS1stByte(b1st)
-            && ShiftJis.isShiftJIS2ndByte(b2nd)){
-            return true;
-        }
-        return false;
+        boolean result =
+               ShiftJis.isShiftJIS1stByte(b1st)
+            && ShiftJis.isShiftJIS2ndByte(b2nd);
+        return result;
     }
 
 }
index 7740f94..2638bd7 100644 (file)
@@ -92,6 +92,8 @@ public class ContentBuilderSJTest {
 
     /**
      * Test of SjisDecoder & ContentBuilder.
+     * @throws java.io.IOException
+     * @throws jp.sourceforge.jindolf.parser.DecodeException
      */
     @Test
     public void testDecoding() throws IOException, DecodeException{
@@ -172,6 +174,8 @@ public class ContentBuilderSJTest {
 
     /**
      * Test of unmappable character.
+     * @throws java.io.IOException
+     * @throws jp.sourceforge.jindolf.parser.DecodeException
      */
     @Test
     public void testUnmap() throws IOException, DecodeException{
@@ -272,6 +276,8 @@ public class ContentBuilderSJTest {
 
     /**
      * Test of malformed character.
+     * @throws java.io.IOException
+     * @throws jp.sourceforge.jindolf.parser.DecodeException
      */
     @Test
     public void testMalform() throws IOException, DecodeException{
@@ -327,6 +333,8 @@ public class ContentBuilderSJTest {
 
     /**
      * Test of Bounds buffering.
+     * @throws java.io.IOException
+     * @throws jp.sourceforge.jindolf.parser.DecodeException
      */
     @Test
     public void testBounds() throws IOException, DecodeException{