Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mathieu Féry
mobile21
Commits
6e2019f5
Unverified
Commit
6e2019f5
authored
Apr 22, 2021
by
Mathieu Féry (Mathius)
Browse files
Improve Name keywords detection
parent
3858b3fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/iutnantes/miar/dndgenerator/api/donjon/bin/sh/Name.java
View file @
6e2019f5
...
...
@@ -94,15 +94,44 @@ public class Name implements Serializable {
* @return matched
*/
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
)
{
String
word
=
keyword
.
trim
();
if
(!
matched
[
0
]
&&
specie
.
equalsIgnoreCase
(
word
))
matched
[
0
]
=
true
;
if
(
type
!=
null
&&
!
matched
[
1
]
&&
type
.
equalsIgnoreCase
(
word
))
matched
[
1
]
=
true
;
if
(
word
.
contains
(
","
))
{
matched
=
matchWithType
(
Arrays
.
asList
(
word
.
split
(
","
)));
}
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
;
}
/**
...
...
app/src/test/java/fr/iutnantes/miar/dndgenerator/api/donjon/bin/sh/NameTest.java
View file @
6e2019f5
...
...
@@ -61,6 +61,9 @@ public class NameTest {
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"
));
assertFalse
(
exampleTruc
.
matchWith
(
"Truc"
,
"Bidule"
));
assertFalse
(
exampleTruc
.
matchWith
(
"Example"
,
"Bidule"
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment