Browse Source

Parser style improvements

git-svn-id: http://svn.dmdirc.com/trunk@1968 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith 16 years ago
parent
commit
69ff03a9b9

+ 10
- 19
src/com/dmdirc/parser/ProcessWho.java View File

24
 
24
 
25
 package com.dmdirc.parser;
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
 import com.dmdirc.parser.callbacks.CallbackOnAwayStateOther;
27
 import com.dmdirc.parser.callbacks.CallbackOnAwayStateOther;
33
-import com.dmdirc.parser.callbacks.interfaces.IAwayStateOther;
34
 import com.dmdirc.parser.callbacks.CallbackOnChannelAwayStateOther;
28
 import com.dmdirc.parser.callbacks.CallbackOnChannelAwayStateOther;
35
-import com.dmdirc.parser.callbacks.interfaces.IChannelAwayStateOther;
36
 
29
 
37
 /**
30
 /**
38
  * Process a /who reply
31
  * Process a /who reply
44
 	 * @param sParam Type of line to process ("352")
37
 	 * @param sParam Type of line to process ("352")
45
 	 * @param token IRCTokenised line to process
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
 		// :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
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
 		//              0               1      2        3     4              5                      6           7     8        9
42
 		//              0               1      2        3     4              5                      6           7     8        9
50
 		// :blueyonder2.uk.quakenet.org 352 Dataforce #mdbot ~Dataforce ResNetUser-BrynDinas-147.143.246.102.bangor.ac.uk *.quakenet.org Dataforce H@ :0 Dataforce
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
 //		ChannelInfo channel = myParser.getChannelInfo(token[3]);
50
 //		ChannelInfo channel = myParser.getChannelInfo(token[3]);
58
 //		ChannelClientInfo channelClient = channel.getUser(token[7]);
51
 //		ChannelClientInfo channelClient = channel.getUser(token[7]);
59
 //		ClientInfo client = channelClient.getClient();
52
 //		ClientInfo client = channelClient.getClient();
60
-		ClientInfo client = myParser.getClientInfo(token[7]);
53
+		final ClientInfo client = myParser.getClientInfo(token[7]);
61
 		if (client != null) {
54
 		if (client != null) {
62
 			// Update ident/host
55
 			// Update ident/host
63
 			client.setUserBits(token[7]+"!"+token[4]+"@"+token[5], false);
56
 			client.setUserBits(token[7]+"!"+token[4]+"@"+token[5], false);
64
 			// Update real name
57
 			// Update real name
65
 			if (client.getRealName().equals("")) {
58
 			if (client.getRealName().equals("")) {
66
 				try {
59
 				try {
67
-					String name = token[9].split(" ", 2)[1];
60
+					final String name = token[9].split(" ", 2)[1];
68
 					client.setRealName(name);
61
 					client.setRealName(name);
69
 				} catch (Exception e) { /* Do Nothing */ }
62
 				} catch (Exception e) { /* Do Nothing */ }
70
 			}
63
 			}
71
 			// Update away state
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
 			if (client.getAwayState() != isAway) {
67
 			if (client.getAwayState() != isAway) {
75
 //				System.out.println("Away state for '"+client+"' changed to: "+isAway);
68
 //				System.out.println("Away state for '"+client+"' changed to: "+isAway);
76
 				client.setAwayState(isAway);
69
 				client.setAwayState(isAway);
77
 				callAwayStateOther(client, isAway);
70
 				callAwayStateOther(client, isAway);
78
 				
71
 				
79
-				ChannelInfo iChannel;
80
 				ChannelClientInfo iChannelClient;
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
 					iChannelClient = iChannel.getUser(client);
74
 					iChannelClient = iChannel.getUser(client);
84
 					if (iChannelClient != null) {
75
 					if (iChannelClient != null) {
85
 						callChannelAwayStateOther(iChannel,iChannelClient,isAway);
76
 						callChannelAwayStateOther(iChannel,iChannelClient,isAway);
97
 	 * @param state Away State (true if away, false if here)
88
 	 * @param state Away State (true if away, false if here)
98
 	 * @return true if a method was called, false otherwise
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
 		if (cb != null) { return cb.call(client, state); }
93
 		if (cb != null) { return cb.call(client, state); }
103
 		return false;
94
 		return false;
104
 	}
95
 	}
112
 	 * @param state Away State (true if away, false if here)
103
 	 * @param state Away State (true if away, false if here)
113
 	 * @return true if a method was called, false otherwise
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
 		if (cb != null) { return cb.call(channel, channelClient, state); }
108
 		if (cb != null) { return cb.call(channel, channelClient, state); }
118
 		return false;
109
 		return false;
119
 	}
110
 	}

+ 14
- 21
src/com/dmdirc/parser/ProcessingManager.java View File

23
  */
23
  */
24
 
24
 
25
 package com.dmdirc.parser;
25
 package com.dmdirc.parser;
26
-import com.dmdirc.parser.callbacks.interfaces.INumeric;
26
+
27
 import com.dmdirc.parser.callbacks.CallbackOnNumeric;
27
 import com.dmdirc.parser.callbacks.CallbackOnNumeric;
28
+
28
 import java.util.Hashtable;
29
 import java.util.Hashtable;
29
-import java.util.Enumeration;
30
 
30
 
31
 /**
31
 /**
32
  * IRC Parser Processing Manager.
32
  * IRC Parser Processing Manager.
40
 	IRCParser myParser = null;
40
 	IRCParser myParser = null;
41
 	
41
 	
42
 	/** Hashtable used to store the different types of IRCProcessor known. */
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
 	 * Constructor to create a ProcessingManager
46
 	 * Constructor to create a ProcessingManager
54
 	/**
54
 	/**
55
 	 * Debugging Data to the console.
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
 		myParser.callDebugInfo(myParser.DEBUG_PROCESSOR, line, args);
58
 		myParser.callDebugInfo(myParser.DEBUG_PROCESSOR, line, args);
59
 	}
59
 	}
60
 	
60
 	
129
 	public void empty() {
129
 	public void empty() {
130
 		processHash.clear();
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
 	 * Add new Process type.
134
 	 * Add new Process type.
140
 	 *
135
 	 *
141
 	 * @param processor IRCProcessor subclass for the processor.
136
 	 * @param processor IRCProcessor subclass for the processor.
142
 	 */
137
 	 */
143
-	public void addProcessor(IRCProcessor processor) {	
138
+	public void addProcessor(final IRCProcessor processor) {	
144
 		// handles() returns a String array of all the tokens
139
 		// handles() returns a String array of all the tokens
145
 		// that this processor will parse.
140
 		// that this processor will parse.
146
 		addProcessor(processor.handles(), processor);
141
 		addProcessor(processor.handles(), processor);
152
 	 * @param processor IRCProcessor subclass for the processor.
147
 	 * @param processor IRCProcessor subclass for the processor.
153
 	 * @param handles String Array of tokens to add this processor as a hadler for
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
 		DoDebug("Adding processor: "+processor.getName());
151
 		DoDebug("Adding processor: "+processor.getName());
157
 		
152
 		
158
 		try {
153
 		try {
175
 	 *
170
 	 *
176
 	 * @param processor IRCProcessor subclass for the processor.
171
 	 * @param processor IRCProcessor subclass for the processor.
177
 	 */
172
 	 */
178
-	public void delProcessor(IRCProcessor processor) {	
173
+	public void delProcessor(final IRCProcessor processor) {	
179
 		IRCProcessor testProcessor;
174
 		IRCProcessor testProcessor;
180
-		String elementName;
181
 		DoDebug("Deleting processor: "+processor.getName());
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
 			DoDebug("\t Checking handler for: "+elementName);
177
 			DoDebug("\t Checking handler for: "+elementName);
185
 			testProcessor = processHash.get(elementName);
178
 			testProcessor = processHash.get(elementName);
186
 			if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
179
 			if (testProcessor.getName().equalsIgnoreCase(processor.getName())) {
196
 	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
189
 	 * @param sParam Type of line to process ("005", "PRIVMSG" etc)
197
 	 * @return IRCProcessor for the given param.
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
 		if (processHash.containsKey(sParam.toLowerCase())) {
193
 		if (processHash.containsKey(sParam.toLowerCase())) {
201
 			return processHash.get(sParam.toLowerCase());
194
 			return processHash.get(sParam.toLowerCase());
202
 		} else {
195
 		} else {
211
 	 * @param token IRCTokenised line to process
204
 	 * @param token IRCTokenised line to process
212
 	 * @throws ProcessorNotFound exception if no processors exists to handle the line
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
 		IRCProcessor messageProcessor = null;
208
 		IRCProcessor messageProcessor = null;
216
 		try {
209
 		try {
217
 			messageProcessor = getProcessor(sParam);
210
 			messageProcessor = getProcessor(sParam);
219
 		} catch (ProcessorNotFound p) {
212
 		} catch (ProcessorNotFound p) {
220
 			throw p;
213
 			throw p;
221
 		} catch (Exception e) {
214
 		} catch (Exception e) {
222
-			StringBuilder line = new StringBuilder();
215
+			final StringBuilder line = new StringBuilder();
223
 			for (int i = 0; i < token.length; ++i ) { line.append(" ").append(token[i]); }
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
 			ei.setException(e);
218
 			ei.setException(e);
226
 			myParser.callErrorInfo(ei);
219
 			myParser.callErrorInfo(ei);
227
 		} finally {
220
 		} finally {
241
 	 * @param token IRC Tokenised line
234
 	 * @param token IRC Tokenised line
242
 	 * @return true if a method was called, false otherwise
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
 		if (cb != null) { return cb.call(numeric, token); }
239
 		if (cb != null) { return cb.call(numeric, token); }
247
 		return false;
240
 		return false;
248
 	}
241
 	}

+ 1
- 1
src/com/dmdirc/parser/ProcessorNotFound.java View File

43
 	 *
43
 	 *
44
 	 * @param message Reason for exception
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
 	 * Get SVN Version information.
49
 	 * Get SVN Version information.

+ 8
- 7
src/com/dmdirc/parser/RegexStringList.java View File

33
  * @version $Id$
33
  * @version $Id$
34
  */
34
  */
35
 public class RegexStringList {
35
 public class RegexStringList {
36
+	
36
 	/** Arraylist storing ignore patterns */
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
 	 * Add a new ignore pattern to the ignore list.
41
 	 * Add a new ignore pattern to the ignore list.
41
 	 *
42
 	 *
42
 	 * @param pattern Regex syntax for the ignore (Pattern is matched case-insensitively as ^pattern$)
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
 		for (int i = 0; i < this.count(); ++i) {
46
 		for (int i = 0; i < this.count(); ++i) {
46
 			if (pattern.equalsIgnoreCase(this.get(i))) {
47
 			if (pattern.equalsIgnoreCase(this.get(i))) {
47
 				return;
48
 				return;
55
 	 *
56
 	 *
56
 	 * @param position Position in the list to remove
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
 		if (position < this.count()) {
60
 		if (position < this.count()) {
60
 			ignoreInfo.remove(position);
61
 			ignoreInfo.remove(position);
61
 		}
62
 		}
74
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
75
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
75
 	 * @return integer showing the position of the first match in the ignore list (-1 if none)
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
 		for (int i = 0; i < this.count(); ++i) {
79
 		for (int i = 0; i < this.count(); ++i) {
79
 			if (check.matches("(?i)"+this.get(i))) {
80
 			if (check.matches("(?i)"+this.get(i))) {
80
 				return i;
81
 				return i;
90
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
91
 	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
91
 	 * @return boolean true/false
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
 		if (position < this.count()) {
95
 		if (position < this.count()) {
95
 			return check.matches("(?i)"+this.get(position));
96
 			return check.matches("(?i)"+this.get(position));
96
 		} else {
97
 		} else {
104
 	 * @param position Position to check
105
 	 * @param position Position to check
105
 	 * @return String showing the pattern. ("" if position isn't valid)
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
 		if (position < this.count()) {
109
 		if (position < this.count()) {
109
 			return ignoreInfo.get(position);
110
 			return ignoreInfo.get(position);
110
 		} else {
111
 		} else {
118
 	 * @param position Position to change
119
 	 * @param position Position to change
119
 	 * @param pattern New pattern
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
 		if (position < this.count()) {
123
 		if (position < this.count()) {
123
 			ignoreInfo.set(position, pattern);
124
 			ignoreInfo.set(position, pattern);
124
 		}
125
 		}

+ 7
- 7
src/com/dmdirc/parser/ServerInfo.java View File

71
 	 *
71
 	 *
72
 	 * @param newValue Value to set to.
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
 	 * Get the hostname.
77
 	 * Get the hostname.
85
 	 *
85
 	 *
86
 	 * @param newValue Value to set to.
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
 	 * Get the port.
91
 	 * Get the port.
99
 	 *
99
 	 *
100
 	 * @param newValue Value to set to.
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
 	 * Get the password.
105
 	 * Get the password.
113
 	 *
113
 	 *
114
 	 * @param newValue true if server uses ssl, else false
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
 	 * Get if the server uses ssl.
119
 	 * Get if the server uses ssl.
127
 	 *
127
 	 *
128
 	 * @param newValue true if we are using socks, else false
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
 	 * Get if we are connecting via a socks proxy.
133
 	 * Get if we are connecting via a socks proxy.
141
 	 *
141
 	 *
142
 	 * @param newValue Value to set to.
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
 	 * Get the Proxy hostname.
147
 	 * Get the Proxy hostname.
155
 	 *
155
 	 *
156
 	 * @param newValue Value to set to.
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
 	 * Get the Proxy port.
161
 	 * Get the Proxy port.

Loading…
Cancel
Save