Unverified Commit 6e2019f5 authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Improve Name keywords detection

parent 3858b3fe
...@@ -94,15 +94,44 @@ public class Name implements Serializable { ...@@ -94,15 +94,44 @@ public class Name implements Serializable {
* @return matched * @return matched
*/ */
public boolean matchWith(List<String> keywords) { public boolean matchWith(List<String> keywords) {
boolean[] matched = {false, false}; return matchWithSpecie(keywords) && matchWithType(keywords);
}
/**
* For check if this Name Generator specie match with list of keywords given
* @param keywords : List of String represent keyword used
* @return matched
*/
public boolean matchWithSpecie(List<String> keywords) {
boolean matched = false;
for (String keyword: keywords) { for (String keyword: keywords) {
String word = keyword.trim(); String word = keyword.trim();
if (!matched[0] && specie.equalsIgnoreCase(word)) if (word.contains(",")) {
matched[0] = true; matched = matchWithType(Arrays.asList(word.split(",")));
if (type != null && !matched[1] && type.equalsIgnoreCase(word)) }
matched[1] = true; if (!matched && specie.equalsIgnoreCase(word))
matched = true;
} }
return matched[0] && (type == null || matched[1]); return matched;
}
/**
* For check if this Name Generator type match with list of keywords given
* @param keywords : List of String represent keyword used
* @return matched
*/
public boolean matchWithType(List<String> keywords) {
boolean matched = type == null;
if (type != null)
for (String keyword: keywords) {
String word = keyword.trim();
if (word.contains(",")) {
matched = matchWithType(Arrays.asList(word.split(",")));
}
if (!matched && type.equalsIgnoreCase(word))
matched = true;
}
return matched;
} }
/** /**
......
...@@ -61,6 +61,9 @@ public class NameTest { ...@@ -61,6 +61,9 @@ public class NameTest {
assertFalse(example.matchWith("Truc", "Bidule")); assertFalse(example.matchWith("Truc", "Bidule"));
assertTrue(exampleTruc.matchWith("ExAmple", "Truc", "Bidule")); assertTrue(exampleTruc.matchWith("ExAmple", "Truc", "Bidule"));
assertTrue(exampleTruc.matchWith(" Example", "truc ", "Bidule")); assertTrue(exampleTruc.matchWith(" Example", "truc ", "Bidule"));
assertTrue(exampleTruc.matchWith("ExAmple, Truc", "Bidule"));
assertTrue(exampleTruc.matchWith("ExAmple", "Truc, Bidule"));
assertTrue(exampleTruc.matchWith("ExAmple, Truc, Bidule"));
assertFalse(exampleTruc.matchWith("Truc", "Bidule")); assertFalse(exampleTruc.matchWith("Truc", "Bidule"));
assertFalse(exampleTruc.matchWith("Example", "Bidule")); assertFalse(exampleTruc.matchWith("Example", "Bidule"));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment