apachejavagen.generate_field_name_constants.mustache Maven / Gradle / Ivy
The newest version!
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements TFieldIdEnum {
{{#fields}}
{{#constant_name}}{{name}}{{/constant_name}}((short){{key}}, "{{name}}"){{#last}};{{/last}}{{^last}},{{/last}}
{{/fields}}
{{^has_fields}}
;
{{/has_fields}}
private static final Map byName = new HashMap();
static {
for (_Fields field : EnumSet.allOf(_Fields.class)) {
byName.put(field.getFieldName(), field);
}
}
/**
* Find the _Fields constant that matches fieldId, or null if its not found.
*/
public static _Fields findByThriftId(int fieldId) {
switch(fieldId) {
{{#fields}}
case {{key}}: // {{#constant_name}}{{name}}{{/constant_name}}
return {{#constant_name}}{{name}}{{/constant_name}};
{{/fields}}
default:
return null;
}
}
/**
* Find the _Fields constant that matches fieldId, throwing an exception
* if it is not found.
*/
public static _Fields findByThriftIdOrThrow(int fieldId) {
_Fields fields = findByThriftId(fieldId);
if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
return fields;
}
/**
* Find the _Fields constant that matches name, or null if its not found.
*/
public static _Fields findByName(String name) {
return byName.get(name);
}
private final short _thriftId;
private final String _fieldName;
_Fields(short thriftId, String fieldName) {
_thriftId = thriftId;
_fieldName = fieldName;
}
public short getThriftFieldId() {
return _thriftId;
}
public String getFieldName() {
return _fieldName;
}
}