Created
August 26, 2015 13:20
-
-
Save t-okushima/c1b7193697aeec16b21a to your computer and use it in GitHub Desktop.
enumでコードの集まりを作ってみる ref: http://qiita.com/t-okushima/items/fb76b4ea28423b8c69ff
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
public static final int SAFARI = 10; | |
public static final int CHROME = 20; | |
public static final int FIREFOX = 30; | |
public static final int OTHER = 99; |
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
public class Browser { | |
public static final int SAFARI = 10; | |
public static final int CHROME = 20; | |
public static final int FIREFOX = 30; | |
public static final int OTHER = 99; | |
} |
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
public enum BrowserKinds { | |
Safari(10), Chrome(20), FireFox(30), Other(99); | |
private final int code; | |
private BrowserKinds(int _code) { | |
this.code = _code; | |
} | |
public int getCode() { | |
return this.code; | |
} | |
public static BrowserKinds valueOf(final int _code) { | |
for (BrowserKinds kind : BrowserKinds.values()) { | |
if (kind.code == _code) { | |
return kind; | |
} | |
} | |
return BrowserKinds.Other; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment