Skip to content

Instantly share code, notes, and snippets.

@roberto-filho
Created September 13, 2012 12:29
Show Gist options
  • Save roberto-filho/3714005 to your computer and use it in GitHub Desktop.
Save roberto-filho/3714005 to your computer and use it in GitHub Desktop.
Enum maroto para gerar Ids
package br.com.germantech.ecf.aplicacao.helpers;
import br.com.germantech.ecf.dominio.modelo.fornecedor.ClienteFornecedor;
import br.com.germantech.ecf.dominio.modelo.produto.Produto;
public enum ClassId {
CLIFOR(ClienteFornecedor.class, "C"),
PRODUTO(Produto.class, "P");
private Class<?> classe;
private String identificador;
private ClassId(Class<?> classe, String identificador) {
this.classe = classe;
this.identificador = identificador;
}
public Class<?> getClasse() {
return classe;
}
public String getIdentificador() {
return identificador;
}
public static String getId(Object obj, Long stringId) {
ClassId id = fromClass(obj.getClass());
if(id != null) {
return id.getIdentificador()+stringId;
}
return "";
}
public static ClassId fromClass(Class<?> c) {
for (ClassId cId : values()) {
if(cId.getClass().equals(c))
return cId;
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment