Command.java 832 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cn.sagacloud.pojo;
  2. /*
  3. * Author: Jxing
  4. * Create Time: 2019/3/11
  5. */
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. public enum Command {
  10. SendTask,
  11. RefuseTask,
  12. AcceptTask,
  13. DownloadError,
  14. CommandError,
  15. TaskSuccess,
  16. ClientInfo;
  17. private static ArrayList<Command> cmdList;
  18. static{
  19. cmdList = new ArrayList<>();
  20. cmdList.addAll(Arrays.asList(Command.values()));
  21. }
  22. public static Command getCmdById(int index) {
  23. if(index > -1 && index < cmdList.size()){
  24. return cmdList.get(index);
  25. }
  26. return null;
  27. }
  28. public static int getIdByCmd(Command cmd) {
  29. for(int i = 0; i < cmdList.size(); ++i){
  30. if(cmdList.get(i).equals(cmd))
  31. return i;
  32. }
  33. return -1;
  34. }
  35. }