xapi.model.impl.ModelNameUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-dev Show documentation
Show all versions of xapi-dev Show documentation
Everything needed to run a comprehensive dev environment.
Just type X_ and pick a service from autocomplete;
new dev modules will be added as they are built.
The only dev service not included in the uber jar is xapi-dev-maven,
as it includes all runtime dependencies of maven, adding ~4 seconds to build time,
and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).
The newest version!
/**
*
*/
package xapi.model.impl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author James X. Nelson ([email protected], @james)
*
*/
public class ModelNameUtil {
private static final Pattern GETTER_MATCHER = Pattern.compile(
"(?:get|has|is)(\\w+)"
);
private static final Pattern SETTER_MATCHER = Pattern.compile(
"(?:setAll|putAll|addAll|add|put|set)(\\w+)"
);
private static final Pattern REMOVER_MATCHER = Pattern.compile(
"(?:removeAll|remove|rem|deleteAll|delete|del)(\\w+)"
);
public static String stripGetter (String name) {
final Matcher matcher = GETTER_MATCHER.matcher(name);
if (matcher.matches()) {
name = matcher.group(1);
}
return Character.toLowerCase(name.charAt(0))+name.substring(1);
}
public static String stripSetter(String name) {
final Matcher matcher = SETTER_MATCHER.matcher(name);
if (matcher.matches()) {
name = matcher.group(1);
}
return Character.toLowerCase(name.charAt(0))+name.substring(1);
}
public static String stripRemover (String name) {
final Matcher matcher = REMOVER_MATCHER.matcher(name);
if (matcher.matches()) {
name = matcher.group(1);
}
return Character.toLowerCase(name.charAt(0))+name.substring(1);
}
}