OSDN Git Service

remove parseInt() from StringUtils.
authorOlyutorskii <olyutorskii@users.osdn.me>
Tue, 25 Feb 2020 03:38:01 +0000 (12:38 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Tue, 25 Feb 2020 03:38:01 +0000 (12:38 +0900)
src/main/java/jp/sfjp/jindolf/data/Anchor.java
src/main/java/jp/sfjp/jindolf/util/StringUtils.java
src/test/java/jp/sfjp/jindolf/data/AnchorTest.java [new file with mode: 0644]
src/test/java/jp/sfjp/jindolf/util/StringUtilsTest.java

index 7eb1b9b..4bbb20d 100644 (file)
@@ -11,7 +11,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import jp.sfjp.jindolf.util.StringUtils;
 
 /**
  * 発言アンカー。
@@ -186,7 +185,7 @@ public final class Anchor{
 
         /* G国アンカー */
         if(matcher.start(14) < matcher.end(14)){
-            int talkNo = StringUtils.parseInt(source, matcher, 14);
+            int talkNo = parseInt(source, matcher, 14);
             Anchor anchor = new Anchor(source, startPos, endPos, talkNo);
             return anchor;
         }
@@ -198,7 +197,7 @@ public final class Anchor{
             }else if(matcher.start(3) < matcher.end(3)){ // epilogue
                 day = EPILOGUEDAY;
             }else if(matcher.start(4) < matcher.end(4)){  // etc) "6d"
-                day = StringUtils.parseInt(source, matcher, 4);
+                day = parseInt(source, matcher, 4);
             }else{
                 assert false;
                 return null;
@@ -229,8 +228,8 @@ public final class Anchor{
             assert false;
             return null;
         }
-        int hour   = StringUtils.parseInt(source, matcher, hourGroup);
-        int minute = StringUtils.parseInt(source, matcher, minuteGroup);
+        int hour   = parseInt(source, matcher, hourGroup);
+        int minute = parseInt(source, matcher, minuteGroup);
 
         if(isPM && hour < 12) hour += 12;
         hour %= 24;
@@ -246,6 +245,49 @@ public final class Anchor{
     }
 
     /**
+     * 正規表現にマッチした領域を数値化する。
+     *
+     * @param seq 文字列
+     * @param matcher Matcher
+     * @param groupIndex 前方指定グループ番号
+     * @return 数値
+     * @throws IndexOutOfBoundsException 不正なグループ番号
+     */
+    static int parseInt(CharSequence seq,
+                        Matcher matcher,
+                        int groupIndex )
+            throws IndexOutOfBoundsException {
+        int startPos = matcher.start(groupIndex);
+        int endPos   = matcher.end(groupIndex);
+        return parseInt(seq, startPos, endPos);
+    }
+
+    /**
+     * 部分文字列を数値化する。
+     *
+     * @param seq 文字列
+     * @param startPos 範囲開始位置
+     * @param endPos 範囲終了位置
+     * @return パースした数値
+     * @throws IndexOutOfBoundsException 不正な位置指定
+     */
+    static int parseInt(CharSequence seq, int startPos, int endPos)
+            throws IndexOutOfBoundsException{
+        int result = 0;
+
+        for(int pos = startPos; pos < endPos; pos++){
+            char ch = seq.charAt(pos);
+            int digit = Character.digit(ch, 10);
+            if(digit < 0) break;
+            result *= 10;
+            result += digit;
+        }
+
+        return result;
+    }
+
+
+    /**
      * アンカーの含まれる文字列を返す。
      * @return アンカーの含まれる文字列
      */
index 120a9b6..830fa90 100644 (file)
@@ -7,8 +7,6 @@
 
 package jp.sfjp.jindolf.util;
 
-import java.util.regex.Matcher;
-
 /**
  * 文字列ユーティリティクラス。
  */
@@ -28,55 +26,6 @@ public final class StringUtils{
 
 
     /**
-     * 正規表現にマッチした領域を数値化する。
-     * @param seq 文字列
-     * @param matcher Matcher
-     * @param groupIndex 前方指定グループ番号
-     * @return 数値
-     * @throws IndexOutOfBoundsException 不正なグループ番号
-     */
-    public static int parseInt(CharSequence seq,
-                                Matcher matcher,
-                                int groupIndex     )
-            throws IndexOutOfBoundsException {
-        return parseInt(seq,
-                        matcher.start(groupIndex),
-                        matcher.end(groupIndex)   );
-    }
-
-    /**
-     * 文字列を数値化する。
-     * @param seq 文字列
-     * @return 数値
-     */
-    public static int parseInt(CharSequence seq){
-        return parseInt(seq, 0, seq.length());
-    }
-
-    /**
-     * 部分文字列を数値化する。
-     * @param seq 文字列
-     * @param startPos 範囲開始位置
-     * @param endPos 範囲終了位置
-     * @return パースした数値
-     * @throws IndexOutOfBoundsException 不正な位置指定
-     */
-    public static int parseInt(CharSequence seq, int startPos, int endPos)
-            throws IndexOutOfBoundsException{
-        int result = 0;
-
-        for(int pos = startPos; pos < endPos; pos++){
-            char ch = seq.charAt(pos);
-            int digit = Character.digit(ch, 10);
-            if(digit < 0) break;
-            result *= 10;
-            result += digit;
-        }
-
-        return result;
-    }
-
-    /**
      * 長い文字列を三点リーダで省略する。
      * 「abcdefg」→「abc…efg」
      * @param str 文字列
diff --git a/src/test/java/jp/sfjp/jindolf/data/AnchorTest.java b/src/test/java/jp/sfjp/jindolf/data/AnchorTest.java
new file mode 100644 (file)
index 0000000..fc2a22d
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ */
+
+package jp.sfjp.jindolf.data;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class AnchorTest {
+
+    public AnchorTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() {
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of parseInt method, of class Anchor.
+     */
+    @Test
+    public void testParseInt_3args_1() {
+        System.out.println("parseInt");
+
+        int result;
+        Matcher matcher;
+        Pattern pattern;
+        String input = "ABC123PQR456XYZ";
+
+        pattern = Pattern.compile("([0-9]+)[A-Z]*([0-9]+)");
+        matcher = pattern.matcher(input);
+
+        assertTrue(matcher.find());
+
+        result = Anchor.parseInt(input, matcher, 1);
+        assertEquals(123, result);
+
+        result = Anchor.parseInt(input, matcher, 2);
+        assertEquals(456, result);
+
+        try{
+            Anchor.parseInt(null, matcher, 1);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        try{
+            Anchor.parseInt(input, null, 1);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        return;
+    }
+
+    /**
+     * Test of parseInt method, of class Anchor.
+     */
+    @Test
+    public void testParseInt_3args_2() {
+        System.out.println("parseInt");
+
+        int result;
+
+        try{
+            Anchor.parseInt(null, 1, 3);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        result = Anchor.parseInt("1234567", 2, 5);
+        assertEquals(345, result);
+
+        result = Anchor.parseInt("1234567", 2, 3);
+        assertEquals(3, result);
+
+        result = Anchor.parseInt("1234567", 2, 2);
+        assertEquals(0, result);
+
+        result = Anchor.parseInt("1234567", 2, 1);
+        assertEquals(0, result);
+
+        result = Anchor.parseInt("1234567", 0, 0);
+        assertEquals(0, result);
+
+        try{
+            Anchor.parseInt("1234567", 2, 999);
+            fail();
+        }catch(StringIndexOutOfBoundsException e){
+        }
+
+        try{
+            Anchor.parseInt("1234567", -1, 5);
+            fail();
+        }catch(StringIndexOutOfBoundsException e){
+        }
+
+        return;
+    }
+
+}
index 92c82ed..7610998 100644 (file)
@@ -6,8 +6,6 @@
 
 package jp.sfjp.jindolf.util;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -41,122 +39,6 @@ public class StringUtilsTest {
     }
 
     /**
-     * Test of parseInt method, of class StringUtils.
-     */
-    @Test
-    public void testParseInt_3args_1(){
-        System.out.println("parseInt");
-
-        int result;
-        Matcher matcher;
-        Pattern pattern;
-        String input = "ABC123PQR456XYZ";
-
-        pattern = Pattern.compile("([0-9]+)[A-Z]*([0-9]+)");
-        matcher = pattern.matcher(input);
-
-        assertTrue(matcher.find());
-
-        result = StringUtils.parseInt(input, matcher, 1);
-        assertEquals(123, result);
-
-        result = StringUtils.parseInt(input, matcher, 2);
-        assertEquals(456, result);
-
-        try{
-            StringUtils.parseInt(null, matcher, 1);
-            fail();
-        }catch(NullPointerException e){
-        }
-
-        try{
-            StringUtils.parseInt(input, null, 1);
-            fail();
-        }catch(NullPointerException e){
-        }
-
-        return;
-    }
-
-    /**
-     * Test of parseInt method, of class StringUtils.
-     */
-    @Test
-    public void testParseInt_CharSequence(){
-        System.out.println("parseInt");
-
-        int result;
-
-        try{
-            StringUtils.parseInt(null);
-            fail();
-        }catch(NullPointerException e){
-        }
-
-        result = StringUtils.parseInt("");
-        assertEquals(0, result);
-
-        result = StringUtils.parseInt("0");
-        assertEquals(0, result);
-
-        result = StringUtils.parseInt("999");
-        assertEquals(999, result);
-
-        result = StringUtils.parseInt("X");
-        assertEquals(0, result);
-
-        result = StringUtils.parseInt("-1");
-        assertEquals(0, result);
-
-        return;
-    }
-
-    /**
-     * Test of parseInt method, of class StringUtils.
-     */
-    @Test
-    public void testParseInt_3args_2(){
-        System.out.println("parseInt");
-
-        int result;
-
-        try{
-            StringUtils.parseInt(null, 1, 3);
-            fail();
-        }catch(NullPointerException e){
-        }
-
-        result = StringUtils.parseInt("1234567", 2, 5);
-        assertEquals(345, result);
-
-        result = StringUtils.parseInt("1234567", 2, 3);
-        assertEquals(3, result);
-
-        result = StringUtils.parseInt("1234567", 2, 2);
-        assertEquals(0, result);
-
-        result = StringUtils.parseInt("1234567", 2, 1);
-        assertEquals(0, result);
-
-        result = StringUtils.parseInt("1234567", 0, 0);
-        assertEquals(0, result);
-
-        try{
-            StringUtils.parseInt("1234567", 2, 999);
-            fail();
-        }catch(StringIndexOutOfBoundsException e){
-        }
-
-        try{
-            StringUtils.parseInt("1234567", -1, 5);
-            fail();
-        }catch(StringIndexOutOfBoundsException e){
-        }
-
-        return;
-    }
-
-    /**
      * Test of suppressString method, of class StringUtils.
      */
     @Test