Skip to content

Commit

Permalink
fix for stripping prefix on single enums (#7726)
Browse files Browse the repository at this point in the history
  • Loading branch information
lborupj authored and wing328 committed Mar 9, 2018
1 parent 1947220 commit e73eeb4
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,25 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
}

/**
* Returns the common prefix of variables for enum naming
* Returns the common prefix of variables for enum naming if
* two or more variables are present
*
* @param vars List of variable names
* @return the common prefix for naming
*/
public String findCommonPrefixOfVars(List<Object> vars) {
try {
String[] listStr = vars.toArray(new String[vars.size()]);
String prefix = StringUtils.getCommonPrefix(listStr);
// exclude trailing characters that should be part of a valid variable
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
} catch (ArrayStoreException e) {
return "";
if (vars.size() > 1) {
try {
String[] listStr = vars.toArray(new String[vars.size()]);
String prefix = StringUtils.getCommonPrefix(listStr);
// exclude trailing characters that should be part of a valid variable
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
} catch (ArrayStoreException e) {
// do nothing, just return default value
}
}
return "";
}

/**
Expand Down

0 comments on commit e73eeb4

Please # to comment.