Don't match numbers that are too long

This commit is contained in:
Reinhard Pointner 2016-02-09 15:02:41 +00:00
parent 49710f27f9
commit fcb003f440
3 changed files with 36 additions and 6 deletions

View File

@ -24,7 +24,11 @@ public final class StringUtilities {
List<Integer> numbers = new ArrayList<Integer>();
Matcher matcher = DIGIT.matcher(s);
while (matcher.find()) {
numbers.add(new Integer(matcher.group()));
try {
numbers.add(new Integer(matcher.group()));
} catch (NumberFormatException e) {
// ignore
}
}
return numbers;
}
@ -36,7 +40,11 @@ public final class StringUtilities {
Matcher matcher = DIGIT.matcher(s);
if (matcher.find()) {
return new Integer(matcher.group());
try {
return new Integer(matcher.group());
} catch (NumberFormatException e) {
// ignore
}
}
return null;
}

View File

@ -0,0 +1,25 @@
package net.filebot.util;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
public class StringUtilitiesTest {
@Test
public void matchInteger() {
Integer n = StringUtilities.matchInteger("1091_20150217210000");
assertEquals("1091", n.toString());
}
@Test
public void matchIntegers() {
List<Integer> n = StringUtilities.matchIntegers("1091_20150217210000");
assertEquals("[1091]", n.toString());
}
}

View File

@ -1,14 +1,11 @@
package net.filebot.util;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class })
@SuiteClasses({ FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class, StringUtilities.class })
public class UtilTestSuite {
}