import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import jp.sfjp.jindolf.util.StringUtils;
/**
* 発言アンカー。
/* 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;
}
}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;
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;
}
/**
+ * 正規表現にマッチした領域を数値化する。
+ *
+ * @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 アンカーの含まれる文字列
*/
package jp.sfjp.jindolf.util;
-import java.util.regex.Matcher;
-
/**
* 文字列ユーティリティクラス。
*/
/**
- * 正規表現にマッチした領域を数値化する。
- * @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 文字列
--- /dev/null
+/*
+ */
+
+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;
+ }
+
+}
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;
}
/**
- * 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