浏览代码

Initial implementation of CommandArguments class

tags/0.6.3m1rc1
Chris Smith 15 年前
父节点
当前提交
e8594a14e5
共有 1 个文件被更改,包括 62 次插入0 次删除
  1. 62
    0
      src/com/dmdirc/commandparser/CommandArguments.java

+ 62
- 0
src/com/dmdirc/commandparser/CommandArguments.java 查看文件

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.commandparser;
24
+
25
+/**
26
+ * Represents a command and its arguments.
27
+ *
28
+ * @author chris
29
+ */
30
+public class CommandArguments {
31
+
32
+    /** The raw line that was input. */
33
+    private final String line;
34
+
35
+    private String[] arguments;
36
+
37
+    public CommandArguments(final String line) {
38
+        this.line = line;
39
+    }
40
+    
41
+    public synchronized String[] getArguments() {
42
+        if (arguments == null) {
43
+            parse();
44
+        }
45
+        
46
+        return arguments;
47
+    }
48
+
49
+    protected void parse() {
50
+        arguments = line.split("\\s+");
51
+    }
52
+
53
+    public boolean isCommand() {
54
+        return !line.isEmpty() && line.charAt(0) == CommandManager.getCommandChar();
55
+    }
56
+
57
+    public boolean isSilent() {
58
+        return isCommand() && line.length() >= 2 &&
59
+                line.charAt(1) == CommandManager.getSilenceChar();
60
+    }
61
+
62
+}

正在加载...
取消
保存