446b1947b26c6103c7b54bb5a401ffe5f87ac00a
1 package be
.nikiroo
.jvcard
.remote
;
3 public class CommandInstance
{
9 * Create a new, empty {@link CommandInstance} with the given
10 * {@link Command} and version.
17 public CommandInstance(Command command
, int version
) {
18 this(command
, null, version
);
22 * Create a new, empty {@link CommandInstance} with the given
23 * {@link Command} and version.
30 public CommandInstance(Command cmd
, String param
, int version
) {
32 this.version
= version
;
37 * Read a command line (starting with a {@link Command}) and process its
38 * content here in a more readable format.
43 * the version (which can be overrided by a
44 * {@link Command#VERSION} command)
46 public CommandInstance(String input
, int version
) {
47 this.version
= version
;
51 int indexSp
= input
.indexOf(" ");
53 v
= input
.substring(0, indexSp
);
56 for (Command command
: Command
.values()) {
57 if (v
.equals(command
.name())) {
65 param
= input
.substring(indexSp
+ 1);
69 if (cmd
== Command
.VERSION
) {
71 version
= Integer
.parseInt(param
);
72 } catch (NumberFormatException e
) {
85 public int getVersion() {
90 * Return the {@link Command}
92 * @return the {@link Command}
94 public Command
getCommand() {
99 * Return the parameter of this {@link CommandInstance} if any.
101 * @return the parameter or NULL
103 public String
getParam() {
108 public String
toString() {
110 return "[null command]";
114 return cmd
.name() + " " + version
;
116 return cmd
.name() + (param
== null ?
"" : " " + param
);