Skip to content

Instantly share code, notes, and snippets.

@DaddyMoe
Created February 19, 2017 02:36
Show Gist options
  • Save DaddyMoe/38992cc0249cbf19ce74e184056e2767 to your computer and use it in GitHub Desktop.
Save DaddyMoe/38992cc0249cbf19ce74e184056e2767 to your computer and use it in GitHub Desktop.
Converts Class Object to Enum equivalent
public class ConvertObjectToEnumOneLineInstantiation {
/*
* To:
`HIGHLIGHT("highlight", false, "field", false, "title,description,body", null),`
*
* From:
*
`HIGHLIGHT {
public String getName() {return "highlight";}
public boolean isRequired() {return false;}
public String getLevel() {return "field";}
public boolean isExposed() {return false; }
public String getField() {return "title,description,body";}
public FieldTypes getParent() {return null;}
},`
*/
public static void main(String[] args) throws Exception {
for (FieldTypes value : FieldTypes.values()) {
StringBuilder builder = new StringBuilder();
builder.append(value.name());
builder.append("(");
builder.append("\"" + value.getName() + "\",");
builder.append(value.isRequired() + ",");
builder.append("\"" + value.getLevel() + "\",");
builder.append(value.isExposed() + ",");
builder.append("\"" + value.getField() + "\",");
builder.append(value.getParent());
builder.append("),");
System.out.println(builder.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment