PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

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