Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by admiral on 10.10.15.
- */
- public class Something {
- public static void main(String[] args) {
- User user = new User(null,null);
- Integer str = 1; //тут допустим к нам пришел пол
- user.setSex(Sex.getSex(str));
- System.out.println(user);
- }
- }
- public enum Sex {
- NONE(0, ""),
- MALE(1,"Мужской"),
- FEMALE(2, "Женский");
- private final Integer value;
- private final String type;
- Sex(Integer value, String type) {
- this.type = type;
- this.value = value;
- }
- public Integer getValue(){
- return value;
- }
- public String getType() {
- return type;
- }
- public static Sex getSex(Integer value) {
- for (Sex sex : Sex.values()) {
- if(sex.getValue().equals(value)){
- return sex;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement