All over our project, we have this kind of enums. They works just fine, but we are not sure about them.
Specially with the getDocumentType(String) method.
Is there a way to avoid the iteration over all the Enums field ?
public enum DocumentType {
UNKNOWN("Unknown"),
ANY("Any"),
ASSET(Asset.class.getSimpleName()),
MEDIA(Media.class.getSimpleName()),
MEDIA35MM(Media.class.getSimpleName() + " 35mm");
private String label;
private DocumentType(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public static DocumentType getDocumentType(String label){
for(DocumentType documentType : DocumentType.values()){
if(documentType.getLabel().equals(label)){
return documentType;
}
}
return UNKNOWN;
}
}
Edit : Check the newacct response. She's fine too.