Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. /**
  2. * Created by admiral on 10.10.15.
  3. */
  4. public class Something {
  5. public static void main(String[] args) {
  6. User user = new User(null,null);
  7. Integer str = 1; //тут допустим к нам пришел пол
  8. user.setSex(Sex.getSex(str));
  9. System.out.println(user);
  10. }
  11. }
  12.  
  13. public enum Sex {
  14. NONE(0, ""),
  15. MALE(1,"Мужской"),
  16. FEMALE(2, "Женский");
  17.  
  18. private final Integer value;
  19. private final String type;
  20.  
  21. Sex(Integer value, String type) {
  22. this.type = type;
  23. this.value = value;
  24. }
  25.  
  26. public Integer getValue(){
  27. return value;
  28. }
  29.  
  30. public String getType() {
  31. return type;
  32. }
  33.  
  34. public static Sex getSex(Integer value) {
  35. for (Sex sex : Sex.values()) {
  36. if(sex.getValue().equals(value)){
  37. return sex;
  38. }
  39. }
  40. return null;
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement