Created
February 2, 2012 02:34
-
-
Save osamingo/1721032 to your computer and use it in GitHub Desktop.
Enumを逆引きしたい
This file contains hidden or 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
| public enum JobEnum { | |
| MUSICIAN(1, "ミュージシャン"), | |
| MODEL(2, "モデル"), | |
| private Integer jobId; | |
| private String jobName; | |
| JobEnum(Integer jobId, String jobName) { | |
| this.jobId= jobId; | |
| this.jobName= jobName; | |
| } | |
| public Integer jobId() { | |
| return this.jobId; | |
| } | |
| public String jobName() { | |
| return this.jobName; | |
| } | |
| public static JobEnum getJobEnum(Integer jobId) { | |
| for (JobEnum job : JobEnum.values()) { | |
| if (job.jobId().equals(jobId)) { | |
| return job; | |
| } | |
| } | |
| return null; | |
| } | |
| public static JobEnum getJobEnum(String jobName) { | |
| for (JobEnum job : JobEnum.values()) { | |
| if (job.jobName.equals(jobName)) { | |
| return job; | |
| } | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment