Don't match numbers that are too long
This commit is contained in:
parent
49710f27f9
commit
fcb003f440
|
@ -24,7 +24,11 @@ public final class StringUtilities {
|
||||||
List<Integer> numbers = new ArrayList<Integer>();
|
List<Integer> numbers = new ArrayList<Integer>();
|
||||||
Matcher matcher = DIGIT.matcher(s);
|
Matcher matcher = DIGIT.matcher(s);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
try {
|
||||||
numbers.add(new Integer(matcher.group()));
|
numbers.add(new Integer(matcher.group()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +40,11 @@ public final class StringUtilities {
|
||||||
|
|
||||||
Matcher matcher = DIGIT.matcher(s);
|
Matcher matcher = DIGIT.matcher(s);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
try {
|
||||||
return new Integer(matcher.group());
|
return new Integer(matcher.group());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +1,11 @@
|
||||||
|
|
||||||
package net.filebot.util;
|
package net.filebot.util;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Suite;
|
import org.junit.runners.Suite;
|
||||||
import org.junit.runners.Suite.SuiteClasses;
|
import org.junit.runners.Suite.SuiteClasses;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(Suite.class)
|
@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 {
|
public class UtilTestSuite {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue