use of services.moleculer.service.Version in project moleculer-java by moleculer-java.
the class CommonUtils method nameOf.
public static final String nameOf(Object object, boolean addQuotes) {
Class<?> c = object.getClass();
Version v = c.getAnnotation(Version.class);
String version = null;
if (v != null) {
version = v.value();
if (version != null) {
version = version.trim();
if (version.isEmpty()) {
version = null;
}
}
if (version != null) {
try {
Double.parseDouble(version);
version = 'v' + version;
} catch (Exception ignored) {
}
}
}
Name n = c.getAnnotation(Name.class);
String name = null;
if (n != null) {
name = n.value();
if (name != null) {
name = name.trim();
}
}
if (name == null || name.isEmpty()) {
name = c.getName();
int i = Math.max(name.lastIndexOf('.'), name.lastIndexOf('$'));
if (i > -1) {
name = name.substring(i + 1);
}
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
}
if (version != null) {
name = version + '.' + name;
}
if (addQuotes && name.indexOf(' ') == -1) {
name = "\"" + name + "\"";
}
return name;
}
Aggregations