Created
September 13, 2012 12:29
-
-
Save roberto-filho/3714005 to your computer and use it in GitHub Desktop.
Enum maroto para gerar Ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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