-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Id22ba1ad117c640a146f025ba6521db5ec938202
- Loading branch information
Showing
13 changed files
with
578 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.atteo.evo.inflector; | ||
|
||
class CategoryRule implements Rule { | ||
private final String[] list; | ||
private final String singular; | ||
private final String plural; | ||
|
||
public CategoryRule(String[] list, String singular, String plural) { | ||
this.list = list; | ||
this.singular = singular; | ||
this.plural = plural; | ||
} | ||
|
||
@Override | ||
public String getPlural(String word) { | ||
String lowerWord = word.toLowerCase(); | ||
for (String suffix : list) { | ||
if (lowerWord.endsWith(suffix)) { | ||
if (!lowerWord.endsWith(singular)) { | ||
throw new RuntimeException("Internal error"); | ||
} | ||
return word.substring(0, word.length() - singular.length()) + plural; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.atteo.evo.inflector; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
class RegExpRule implements Rule { | ||
private final Pattern singular; | ||
private final String plural; | ||
|
||
RegExpRule(Pattern singular, String plural) { | ||
this.singular = singular; | ||
this.plural = plural; | ||
} | ||
|
||
RegExpRule(String singular, String plural) { | ||
this.singular = Pattern.compile(singular); | ||
this.plural = plural; | ||
} | ||
|
||
@Override | ||
public String getPlural(String word) { | ||
StringBuffer buffer = new StringBuffer(); | ||
Matcher matcher = singular.matcher(word); | ||
if (matcher.find()) { | ||
matcher.appendReplacement(buffer, plural); | ||
matcher.appendTail(buffer); | ||
return buffer.toString(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.atteo.evo.inflector; | ||
|
||
interface Rule { | ||
String getPlural(String singular); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.