public static void main(String arg[]){
generateAttributeEnum(Person.class);
}
public static void generateAttributeEnum(Class<?> cls) {
Field[] fields = cls.getDeclaredFields();
StringBuilder enumBuild = new StringBuilder("public enum ATTRIBUTE {\n");
StringBuilder attributeName = null;
for(Field field : fields){
if(Modifier.isStatic(field.getModifiers())) continue;
attributeName = new StringBuilder();
for (int i = 0; i < field.getName().length(); i++) {
if(Character.isUpperCase(field.getName().charAt(i))) {
attributeName.append("_"+field.getName().charAt(i));
}else{
attributeName.append(Character.toUpperCase(field.getName().charAt(i)));
}
}
enumBuild.append(" "+attributeName+"(\""+field.getName()+"\"),\n");
}
enumBuild.replace(enumBuild.lastIndexOf(","), enumBuild.lastIndexOf(",")+1, ";");
System.out.println(enumBuild.toString());
System.out.println(" public String value;");
System.out.println(" ATTRIBUTE(String value) {");
System.out.println(" this.value = value;");
System.out.println(" };");
System.out.println("};");
}
generateAttributeEnum(Person.class);
}
public static void generateAttributeEnum(Class<?> cls) {
Field[] fields = cls.getDeclaredFields();
StringBuilder enumBuild = new StringBuilder("public enum ATTRIBUTE {\n");
StringBuilder attributeName = null;
for(Field field : fields){
if(Modifier.isStatic(field.getModifiers())) continue;
attributeName = new StringBuilder();
for (int i = 0; i < field.getName().length(); i++) {
if(Character.isUpperCase(field.getName().charAt(i))) {
attributeName.append("_"+field.getName().charAt(i));
}else{
attributeName.append(Character.toUpperCase(field.getName().charAt(i)));
}
}
enumBuild.append(" "+attributeName+"(\""+field.getName()+"\"),\n");
}
enumBuild.replace(enumBuild.lastIndexOf(","), enumBuild.lastIndexOf(",")+1, ";");
System.out.println(enumBuild.toString());
System.out.println(" public String value;");
System.out.println(" ATTRIBUTE(String value) {");
System.out.println(" this.value = value;");
System.out.println(" };");
System.out.println("};");
}