/commandslib/src/com/google/android/marvin/commands/CommandImpl.java

http://eyes-free.googlecode.com/ · Java · 88 lines · 70 code · 12 blank · 6 comment · 20 complexity · a3f1bad5ab1c3ca9e6118ccaebbc66fc MD5 · raw file

  1. // Copyright 2010 Google Inc. All Rights Reserved.
  2. package com.google.android.marvin.commands;
  3. /**
  4. * A default implementation of {@link Command}.
  5. * @author clsimon@google.com (Cheryl Simon)
  6. *
  7. */
  8. public class CommandImpl implements Command {
  9. private final String commandName;
  10. private int modifierKey;
  11. private int keyCode;
  12. private final String action;
  13. public CommandImpl(String commandName, int modifierKey, int keyCode, String action) {
  14. this.commandName = commandName;
  15. this.modifierKey = modifierKey;
  16. this.keyCode = keyCode;
  17. this.action = action;
  18. }
  19. @Override
  20. public String toString() {
  21. return commandName + " " + modifierKey + " " + keyCode + " " + action;
  22. }
  23. @Override
  24. public String getAction() {
  25. return action;
  26. }
  27. @Override
  28. public String getDisplayName() {
  29. return commandName;
  30. }
  31. @Override
  32. public int getKeyCode() {
  33. return keyCode;
  34. }
  35. @Override
  36. public int getModifier() {
  37. return modifierKey;
  38. }
  39. @Override
  40. public int hashCode() {
  41. final int prime = 31;
  42. int result = 1;
  43. result = prime * result + ((action == null) ? 0 : action.hashCode());
  44. result = prime * result + ((commandName == null) ? 0 : commandName.hashCode());
  45. return result;
  46. }
  47. @Override
  48. public boolean equals(Object obj) {
  49. if (this == obj)
  50. return true;
  51. if (obj == null)
  52. return false;
  53. if (getClass() != obj.getClass())
  54. return false;
  55. CommandImpl other = (CommandImpl) obj;
  56. if (action == null) {
  57. if (other.action != null)
  58. return false;
  59. } else if (!action.equals(other.action))
  60. return false;
  61. if (commandName == null) {
  62. if (other.commandName != null)
  63. return false;
  64. } else if (!commandName.equals(other.commandName))
  65. return false;
  66. return true;
  67. }
  68. @Override
  69. public void setKeyCode(int keyCode) {
  70. this.keyCode = keyCode;
  71. }
  72. @Override
  73. public void setModifier(int modifierKey) {
  74. this.modifierKey = modifierKey;
  75. }
  76. }