Ver código fonte

Parser style improvements

git-svn-id: http://svn.dmdirc.com/trunk@1968 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith 16 anos atrás
pai
commit
69ff03a9b9

+ 10
- 19
src/com/dmdirc/parser/ProcessWho.java Ver arquivo

@@ -24,15 +24,8 @@
24 24
 
25 25
 package com.dmdirc.parser;
26 26
 
27
-import java.util.Enumeration;
28
-
29
-import com.dmdirc.parser.ClientInfo;
30
-import com.dmdirc.parser.ChannelClientInfo;
31
-import com.dmdirc.parser.ChannelInfo;
32 27
 import com.dmdirc.parser.callbacks.CallbackOnAwayStateOther;
33
-import com.dmdirc.parser.callbacks.interfaces.IAwayStateOther;
34 28
 import com.dmdirc.parser.callbacks.CallbackOnChannelAwayStateOther;
35
-import com.dmdirc.parser.callbacks.interfaces.IChannelAwayStateOther;
36 29
 
37 30
 /**
38 31
  * Process a /who reply
@@ -44,7 +37,7 @@ public class ProcessWho extends IRCProcessor {
44 37
 	 * @param sParam Type of line to process ("352")
45 38
 	 * @param token IRCTokenised line to process
46 39
 	 */
47
-	public void process(String sParam, String[] token) {
40
+	public void process(final String sParam, final String[] token) {
48 41
 		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot shane Tobavaj.users.quakenet.org *.quakenet.org Tobavaj G+x :3 Tobavaj - http://shane.dmdirc.com/scriptbot.php
49 42
 		//              0               1      2        3     4              5                      6           7     8        9
50 43
 		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot ~Dataforce ResNetUser-BrynDinas-147.143.246.102.bangor.ac.uk *.quakenet.org Dataforce H@ :0 Dataforce
@@ -57,29 +50,27 @@ public class ProcessWho extends IRCProcessor {
57 50
 //		ChannelInfo channel = myParser.getChannelInfo(token[3]);
58 51
 //		ChannelClientInfo channelClient = channel.getUser(token[7]);
59 52
 //		ClientInfo client = channelClient.getClient();
60
-		ClientInfo client = myParser.getClientInfo(token[7]);
53
+		final ClientInfo client = myParser.getClientInfo(token[7]);
61 54
 		if (client != null) {
62 55
 			// Update ident/host
63 56
 			client.setUserBits(token[7]+"!"+token[4]+"@"+token[5], false);
64 57
 			// Update real name
65 58
 			if (client.getRealName().equals("")) {
66 59
 				try {
67
-					String name = token[9].split(" ", 2)[1];
60
+					final String name = token[9].split(" ", 2)[1];
68 61
 					client.setRealName(name);
69 62
 				} catch (Exception e) { /* Do Nothing */ }
70 63
 			}
71 64
 			// Update away state
72
-			String mode = token[8];
73
-			boolean isAway = mode.matches(".*G.*");
65
+			final String mode = token[8];
66
+			final boolean isAway = mode.indexOf('G') != -1;
74 67
 			if (client.getAwayState() != isAway) {
75 68
 //				System.out.println("Away state for '"+client+"' changed to: "+isAway);
76 69
 				client.setAwayState(isAway);
77 70
 				callAwayStateOther(client, isAway);
78 71
 				
79
-				ChannelInfo iChannel;
80 72
 				ChannelClientInfo iChannelClient;
81
-				for (Enumeration e = myParser.hChannelList.keys(); e.hasMoreElements();) {
82
-					iChannel = myParser.hChannelList.get(e.nextElement());
73
+				for (ChannelInfo iChannel : myParser.hChannelList.values()) {
83 74
 					iChannelClient = iChannel.getUser(client);
84 75
 					if (iChannelClient != null) {
85 76
 						callChannelAwayStateOther(iChannel,iChannelClient,isAway);
@@ -97,8 +88,8 @@ public class ProcessWho extends IRCProcessor {
97 88
 	 * @param state Away State (true if away, false if here)
98 89
 	 * @return true if a method was called, false otherwise
99 90
 	 */
100
-	protected boolean callAwayStateOther(ClientInfo client, boolean state) {
101
-		CallbackOnAwayStateOther cb = (CallbackOnAwayStateOther)myParser.getCallbackManager().getCallbackType("OnAwayStateOther");
91
+	protected boolean callAwayStateOther(final ClientInfo client, final boolean state) {
92
+		final CallbackOnAwayStateOther cb = (CallbackOnAwayStateOther)myParser.getCallbackManager().getCallbackType("OnAwayStateOther");
102 93
 		if (cb != null) { return cb.call(client, state); }
103 94
 		return false;
104 95
 	}
@@ -112,8 +103,8 @@ public class ProcessWho extends IRCProcessor {
112 103
 	 * @param state Away State (true if away, false if here)
113 104
 	 * @return true if a method was called, false otherwise
114 105
 	 */
115
-	protected boolean callChannelAwayStateOther(ChannelInfo channel, ChannelClientInfo channelClient, boolean state) {
116
-		CallbackOnChannelAwayStateOther cb = (CallbackOnChannelAwayStateOther)myParser.getCallbackManager().getCallbackType("OnChannelAwayStateOther");
106
+	protected boolean callChannelAwayStateOther(final ChannelInfo channel, final ChannelClientInfo channelClient, final boolean state) {
107
+		final CallbackOnChannelAwayStateOther cb = (CallbackOnChannelAwayStateOther)myParser.getCallbackManager().getCallbackType("OnChannelAwayStateOther");
117 108
 		if (cb != null) { return cb.call(channel, channelClient, state); }
118 109
 		return false;
119 110
 	}

+ 14
- 21
src/com/dmdirc/parser/ProcessingManager.java Ver arquivo

@@ -23,10 +23,10 @@
23 23
  */
24 24
 
25 25
 package com.dmdirc.parser;
26
-import com.dmdirc.parser.callbacks.interfaces.INumeric;
26
+
27 27
 import com.dmdirc.parser.callbacks.CallbackOnNumeric;
28
+
28 29
 import java.util.Hashtable;
29
-import java.util.Enumeration;
30 30
 
31 31
 /**
32 32
  * IRC Parser Processing Manager.
@@ -40,7 +40,7 @@ public class ProcessingManager {
40 40
 	IRCParser myParser = null;
41 41
 	
42 42
 	/** Hashtable used to store the different types of IRCProcessor known. */
43
-	private Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
43
+	private final Hashtable<String,IRCProcessor> processHash = new Hashtable<String,IRCProcessor>();
44 44
 
45 45
 	/**
46 46
 	 * Constructor to create a ProcessingManager
@@ -54,7 +54,7 @@ public class ProcessingManager {
54 54
 	/**
55 55
 	 * Debugging Data to the console.
56 56
 	 */
57
-	private void DoDebug(String line, Object... args) {
57
+	private void DoDebug(final String line, final Object... args) {
58 58
 		myParser.callDebugInfo(myParser.DEBUG_PROCESSOR, line, args);
59 59
 	}
60 60
 	
@@ -129,18 +129,13 @@ public class ProcessingManager {
129 129
 	public void empty() {
130 130
 		processHash.clear();
131 131
 	}
132
-	
133
-	/** Empty clone method to prevent cloning to get more copies of the ProcessingManager */
134
-	public Object clone() throws CloneNotSupportedException {
135
-		throw new CloneNotSupportedException();
136
-	}
137 132
 
138 133
 	/**
139 134
 	 * Add new Process type.
140 135
 	 *
141 136
 	 * @param processor IRCProcessor subclass for the processor.
142 137
 	 */
143
-	public void addProcessor(IRCProcessor processor) {	
138
+	public void addProcessor(final IRCProcessor processor) {	
144 139
 		// handles() returns a String array of all the tokens
145 140
 		// that this processor will parse.
146 141
 		addProcessor(processor.handles(), processor);
@@ -152,7 +147,7 @@ public class ProcessingManager {
152 147
 	 * @param processor IRCProcessor subclass for the processor.
153 148
 	 * @param handles String Array of tokens to add this processor as a hadler for
154 149
 	 */
155
-	public void addProcessor(String[] handles, IRCProcessor processor) {	
150
+	public void addProcessor(final String[] handles, final IRCProcessor processor) {	
156 151
 		DoDebug("Adding processor: "+processor.getName());
157 152
 		
158 153
 		try {
@@ -175,12 +170,10 @@ public class ProcessingManager {
175 170
 	 *
176 171
 	 * @param processor IRCProcessor subclass for the processor.
177 172
 	 */
178
-	public void delProcessor(IRCProcessor processor) {	
173
+	public void delProcessor(final IRCProcessor processor) {	
179 174
 		IRCProcessor testProcessor;
180
-		String elementName;
181 175
 		DoDebug("Deleting processor: "+processor.getName());
182
-		for (Enumeration e = processHash.keys(); e.hasMoreElements();) {
183
-			elementName = (String)e.nextElement();
176
+		for (String elementName : processHash.keySet()) {
184 177
 			DoDebug("\t Checking handler for: "+elementName);
185 178
 			testProcessor = processHash.get(elementName);
186 179
 			if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
@@ -196,7 +189,7 @@ public class ProcessingManager {
196 189
 	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
197 190
 	 * @return IRCProcessor for the given param.
198 191
 	 */
199
-	public IRCProcessor getProcessor(String sParam) throws ProcessorNotFound {
192
+	public IRCProcessor getProcessor(final String sParam) throws ProcessorNotFound {
200 193
 		if (processHash.containsKey(sParam.toLowerCase())) {
201 194
 			return processHash.get(sParam.toLowerCase());
202 195
 		} else {
@@ -211,7 +204,7 @@ public class ProcessingManager {
211 204
 	 * @param token IRCTokenised line to process
212 205
 	 * @throws ProcessorNotFound exception if no processors exists to handle the line
213 206
 	 */
214
-	public void process(String sParam, String[] token) throws ProcessorNotFound {
207
+	public void process(final String sParam, final String[] token) throws ProcessorNotFound {
215 208
 		IRCProcessor messageProcessor = null;
216 209
 		try {
217 210
 			messageProcessor = getProcessor(sParam);
@@ -219,9 +212,9 @@ public class ProcessingManager {
219 212
 		} catch (ProcessorNotFound p) {
220 213
 			throw p;
221 214
 		} catch (Exception e) {
222
-			StringBuilder line = new StringBuilder();
215
+			final StringBuilder line = new StringBuilder();
223 216
 			for (int i = 0; i < token.length; ++i ) { line.append(" ").append(token[i]); }
224
-			ParserError ei = new ParserError(ParserError.ERROR_WARNING,"Exception in Parser. [Param: "+sParam+"] [Processor: "+messageProcessor+"]", line.toString().trim());
217
+			final ParserError ei = new ParserError(ParserError.ERROR_WARNING,"Exception in Parser. [Param: "+sParam+"] [Processor: "+messageProcessor+"]", line.toString().trim());
225 218
 			ei.setException(e);
226 219
 			myParser.callErrorInfo(ei);
227 220
 		} finally {
@@ -241,8 +234,8 @@ public class ProcessingManager {
241 234
 	 * @param token IRC Tokenised line
242 235
 	 * @return true if a method was called, false otherwise
243 236
 	 */
244
-	protected boolean callNumeric(int numeric, String[] token) {
245
-		CallbackOnNumeric cb = (CallbackOnNumeric)myParser.getCallbackManager().getCallbackType("OnNumeric");
237
+	protected boolean callNumeric(final int numeric, final String[] token) {
238
+		final CallbackOnNumeric cb = (CallbackOnNumeric)myParser.getCallbackManager().getCallbackType("OnNumeric");
246 239
 		if (cb != null) { return cb.call(numeric, token); }
247 240
 		return false;
248 241
 	}

+ 1
- 1
src/com/dmdirc/parser/ProcessorNotFound.java Ver arquivo

@@ -43,7 +43,7 @@ public class ProcessorNotFound extends Exception {
43 43
 	 *
44 44
 	 * @param message Reason for exception
45 45
 	 */
46
-	public ProcessorNotFound(String message) { super(message); }
46
+	public ProcessorNotFound(final String message) { super(message); }
47 47
 	
48 48
 	/**
49 49
 	 * Get SVN Version information.

+ 8
- 7
src/com/dmdirc/parser/RegexStringList.java Ver arquivo

@@ -33,15 +33,16 @@ import java.util.ArrayList;
33 33
  * @version $Id$
34 34
  */
35 35
 public class RegexStringList {
36
+	
36 37
 	/** Arraylist storing ignore patterns */
37
-	private ArrayList<String> ignoreInfo = new ArrayList<String>();
38
+	private final ArrayList<String> ignoreInfo = new ArrayList<String>();
38 39
 	
39 40
 	/**
40 41
 	 * Add a new ignore pattern to the ignore list.
41 42
 	 *
42 43
 	 * @param pattern Regex syntax for the ignore (Pattern is matched case-insensitively as ^pattern$)
43 44
 	 */
44
-	public void add(String pattern) {
45
+	public void add(final String pattern) {
45 46
 		for (int i = 0; i < this.count(); ++i) {
46 47
 			if (pattern.equalsIgnoreCase(this.get(i))) {
47 48
 				return;
@@ -55,7 +56,7 @@ public class RegexStringList {
55 56
 	 *
56 57
 	 * @param position Position in the list to remove
57 58
 	 */
58
-	public void remove(int position) {
59
+	public void remove(final int position) {
59 60
 		if (position < this.count()) {
60 61
 			ignoreInfo.remove(position);
61 62
 		}
@@ -74,7 +75,7 @@ public class RegexStringList {
74 75
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
75 76
 	 * @return integer showing the position of the first match in the ignore list (-1 if none)
76 77
 	 */
77
-	public int matches(String check) {
78
+	public int matches(final String check) {
78 79
 		for (int i = 0; i < this.count(); ++i) {
79 80
 			if (check.matches("(?i)"+this.get(i))) {
80 81
 				return i;
@@ -90,7 +91,7 @@ public class RegexStringList {
90 91
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
91 92
 	 * @return boolean true/false
92 93
 	 */
93
-	public boolean matches(int position, String check) {
94
+	public boolean matches(final int position, final String check) {
94 95
 		if (position < this.count()) {
95 96
 			return check.matches("(?i)"+this.get(position));
96 97
 		} else {
@@ -104,7 +105,7 @@ public class RegexStringList {
104 105
 	 * @param position Position to check
105 106
 	 * @return String showing the pattern. ("" if position isn't valid)
106 107
 	 */
107
-	public String get(int position) {
108
+	public String get(final int position) {
108 109
 		if (position < this.count()) {
109 110
 			return ignoreInfo.get(position);
110 111
 		} else {
@@ -118,7 +119,7 @@ public class RegexStringList {
118 119
 	 * @param position Position to change
119 120
 	 * @param pattern New pattern
120 121
 	 */
121
-	public void set(int position, String pattern) {
122
+	public void set(final int position, final String pattern) {
122 123
 		if (position < this.count()) {
123 124
 			ignoreInfo.set(position, pattern);
124 125
 		}

+ 7
- 7
src/com/dmdirc/parser/ServerInfo.java Ver arquivo

@@ -71,7 +71,7 @@ public class ServerInfo {
71 71
 	 *
72 72
 	 * @param newValue Value to set to.
73 73
 	 */
74
-	public void setHost(String newValue) { host = newValue; }
74
+	public void setHost(final String newValue) { host = newValue; }
75 75
 	
76 76
 	/**
77 77
 	 * Get the hostname.
@@ -85,7 +85,7 @@ public class ServerInfo {
85 85
 	 *
86 86
 	 * @param newValue Value to set to.
87 87
 	 */
88
-	public void setPort(int newValue) { port = newValue; }
88
+	public void setPort(final int newValue) { port = newValue; }
89 89
 	
90 90
 	/**
91 91
 	 * Get the port.
@@ -99,7 +99,7 @@ public class ServerInfo {
99 99
 	 *
100 100
 	 * @param newValue Value to set to.
101 101
 	 */
102
-	public void setPassword(String newValue) { password = newValue; }
102
+	public void setPassword(final String newValue) { password = newValue; }
103 103
 	
104 104
 	/**
105 105
 	 * Get the password.
@@ -113,7 +113,7 @@ public class ServerInfo {
113 113
 	 *
114 114
 	 * @param newValue true if server uses ssl, else false
115 115
 	 */
116
-	public void setSSL(boolean newValue) { isSSL = newValue; }
116
+	public void setSSL(final boolean newValue) { isSSL = newValue; }
117 117
 	
118 118
 	/**
119 119
 	 * Get if the server uses ssl.
@@ -127,7 +127,7 @@ public class ServerInfo {
127 127
 	 *
128 128
 	 * @param newValue true if we are using socks, else false
129 129
 	 */
130
-	public void setUseSocks(boolean newValue) { useSocksProxy = newValue; }
130
+	public void setUseSocks(final boolean newValue) { useSocksProxy = newValue; }
131 131
 	
132 132
 	/**
133 133
 	 * Get if we are connecting via a socks proxy.
@@ -141,7 +141,7 @@ public class ServerInfo {
141 141
 	 *
142 142
 	 * @param newValue Value to set to.
143 143
 	 */
144
-	public void setProxyHost(String newValue) { proxyHost = newValue; }
144
+	public void setProxyHost(final String newValue) { proxyHost = newValue; }
145 145
 	
146 146
 	/**
147 147
 	 * Get the Proxy hostname.
@@ -155,7 +155,7 @@ public class ServerInfo {
155 155
 	 *
156 156
 	 * @param newValue Value to set to.
157 157
 	 */
158
-	public void setProxyPort(int newValue) { proxyPort = newValue; }
158
+	public void setProxyPort(final int newValue) { proxyPort = newValue; }
159 159
 	
160 160
 	/**
161 161
 	 * Get the Proxy port.

Carregando…
Cancelar
Salvar