[Cherbot-commit] SF.net SVN: cherbot: [31] trunk/src/net/sf/cherbot
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2006-10-29 13:50:05
|
Revision: 31
http://svn.sourceforge.net/cherbot/?rev=31&view=rev
Author: christianhujer
Date: 2006-10-29 05:49:33 -0800 (Sun, 29 Oct 2006)
Log Message:
-----------
Some code cleanup. Removed several warnings.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/BlackListManager.java
trunk/src/net/sf/cherbot/CherBotLogger.java
trunk/src/net/sf/cherbot/CherBotSecurityManager.java
trunk/src/net/sf/cherbot/CollectionsManager.java
trunk/src/net/sf/cherbot/Crime.java
trunk/src/net/sf/cherbot/CrimeManager.java
trunk/src/net/sf/cherbot/DummyManagerProxy.java
trunk/src/net/sf/cherbot/EmotesManager.java
trunk/src/net/sf/cherbot/ExampleTestCase.java
trunk/src/net/sf/cherbot/ExampleTester.java
trunk/src/net/sf/cherbot/GroupManager.java
trunk/src/net/sf/cherbot/MailManager.java
trunk/src/net/sf/cherbot/Manager.java
trunk/src/net/sf/cherbot/PlayerManager.java
trunk/src/net/sf/cherbot/PollManager.java
trunk/src/net/sf/cherbot/SalesManager.java
trunk/src/net/sf/cherbot/SmutManager.java
Modified: trunk/src/net/sf/cherbot/BlackListManager.java
===================================================================
--- trunk/src/net/sf/cherbot/BlackListManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/BlackListManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -105,6 +105,7 @@
/**
* Checks wether a player is blacklisted.
* @param player Player to check
+ * @return <code>true</code> if <var>player</var> is blacklisted, otherwise <code>false</code>.
*/
public boolean isBlacklisted(final String player) {
return blacklist.contains(player);
@@ -112,6 +113,7 @@
/**
* Checks wether the actor is blacklisted.
+ * @return <code>true</code> if the actor is blacklisted, otherwise <code>false</code>.
*/
public boolean isBlacklisted() {
return blacklist.contains(getActor());
Modified: trunk/src/net/sf/cherbot/CherBotLogger.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotLogger.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/CherBotLogger.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -23,6 +23,7 @@
/**
* Create a logger.
+ * @throws IOException in case of I/O problems during logger creation.
*/
@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
public CherBotLogger() throws IOException {
Modified: trunk/src/net/sf/cherbot/CherBotSecurityManager.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotSecurityManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/CherBotSecurityManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -129,6 +129,7 @@
/**
* Create the SecurityManager.
+ * @param cherBot reference to CherBot instance.
*/
public CherBotSecurityManager(final CherBot cherBot) {
super(cherBot, "security");
@@ -260,20 +261,17 @@
//} finally { try { in.close(); } catch (Exception e) { /* ignore */ } finally { in = null; }
// Binary interface:
- ObjectInputStream in = null;
try {
- in = new ObjectInputStream(new FileInputStream("security.dat"));
- permissions = (Map<String, Permissions>) in.readObject();
- } catch (ClassNotFoundException e) {
- final IOException ioe = new IOException("Error with file \"security.dat\":");
- ioe.initCause(e);
- throw ioe;
- } finally {
+ final ObjectInputStream in = new ObjectInputStream(new FileInputStream("security.dat"));
try {
+ permissions = (Map<String, Permissions>) in.readObject();
+ } finally {
in.close();
- } catch (Exception e) { /* ignore */ } finally {
- in = null;
}
+ } catch (final ClassNotFoundException e) {
+ final IOException ioe = new IOException("Error with file \"security.dat\":");
+ ioe.initCause(e);
+ throw ioe;
}
}
@@ -301,16 +299,11 @@
//} finally { try { out.close(); } catch (Exception e) { /* ignore */ } finally { in = null; }
// Binary interface:
- ObjectOutputStream out = null;
+ final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("security.dat"));
try {
- out = new ObjectOutputStream(new FileOutputStream("security.dat"));
out.writeObject(permissions);
} finally {
- try {
- out.close();
- } catch (Exception e) { /* ignore */ } finally {
- out = null;
- }
+ out.close();
}
}
Modified: trunk/src/net/sf/cherbot/CollectionsManager.java
===================================================================
--- trunk/src/net/sf/cherbot/CollectionsManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/CollectionsManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -80,10 +80,10 @@
/**
* {@inheritDoc}
*/
- public int compareTo(final Entry e) {
- int ret = collector.compareTo(e.collector);
+ public int compareTo(final Entry o) {
+ int ret = collector.compareTo(o.collector);
if (ret == 0) {
- ret = collectable.compareTo(e.collectable);
+ ret = collectable.compareTo(o.collectable);
}
return ret;
}
Modified: trunk/src/net/sf/cherbot/Crime.java
===================================================================
--- trunk/src/net/sf/cherbot/Crime.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/Crime.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -24,15 +24,15 @@
this.crimetype = crimetype;
}
- public boolean equals(final Object o) {
- if (o == null || !(o instanceof Crime)) {
+ @Override public boolean equals(final Object obj) {
+ if (obj == null || !(obj instanceof Crime)) {
return false;
}
- Crime c = (Crime) o;
+ Crime c = (Crime) obj;
return c.criminal.equals(criminal) && c.crimetype.equals(crimetype);
}
- public int hashCode() {
+ @Override public int hashCode() {
return criminal.hashCode() ^ crimetype.hashCode();
}
Modified: trunk/src/net/sf/cherbot/CrimeManager.java
===================================================================
--- trunk/src/net/sf/cherbot/CrimeManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/CrimeManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -166,7 +166,7 @@
//
/**
- * ...
+ * @param cherBot reference to CherBot.
*/
public CrimeManager(final CherBot cherBot) {
super(cherBot, "crimes");
Modified: trunk/src/net/sf/cherbot/DummyManagerProxy.java
===================================================================
--- trunk/src/net/sf/cherbot/DummyManagerProxy.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/DummyManagerProxy.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -22,6 +22,7 @@
/**
* Create a DummyManager.
* @param cherBot CherBot to create DummyManager for
+ * @param managers Managers to register
*/
public DummyManagerProxy(final CherBot cherBot, final Manager... managers) {
super(cherBot, "dummy");
Modified: trunk/src/net/sf/cherbot/EmotesManager.java
===================================================================
--- trunk/src/net/sf/cherbot/EmotesManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/EmotesManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -215,14 +215,9 @@
} // Commands
/**
- * The current matcher. Create an EmotesManager.
+ * Create an EmotesManager.
* @param cherBot CherBot
- * Create an EmotesManager.
- * @param cherBot CherBot
*/
- /** Create an EmotesManager.
- * @param cherBot CherBot
- */
public EmotesManager(final CherBot cherBot) {
super(cherBot, "emotes");
for (String pat : patternTexts) {
Modified: trunk/src/net/sf/cherbot/ExampleTestCase.java
===================================================================
--- trunk/src/net/sf/cherbot/ExampleTestCase.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/ExampleTestCase.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -53,15 +53,17 @@
/**
* {@inheritDoc}
*/
- @Override public void setUp() {
+ @Override public void setUp() throws Exception {
+ super.setUp();
pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
}
/**
* {@inheritDoc}
*/
- @Override public void tearDown() {
+ @Override public void tearDown() throws Exception {
pat = null;
+ super.tearDown();
}
/**
Modified: trunk/src/net/sf/cherbot/ExampleTester.java
===================================================================
--- trunk/src/net/sf/cherbot/ExampleTester.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/ExampleTester.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -29,6 +29,7 @@
/**
* Create a TestSuite for Cherbot.
* @param cherbot CherBot to create TestSuite for
+ * @return TestSuite for CherBot
*/
public static TestSuite createSuite(final CherBot cherbot) {
final TestSuite suite = new ExampleTester();
Modified: trunk/src/net/sf/cherbot/GroupManager.java
===================================================================
--- trunk/src/net/sf/cherbot/GroupManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/GroupManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -386,44 +386,43 @@
* List the groups for the Wiki.
*/
private void listGroupsForWiki() {
- PrintWriter out = null;
try {
- out = new PrintWriter("groupsForWiki.wiki", "iso-8859-1");
- out
- .append("This list is Cherbot's list of clans found on damn.\n\n")
- .append("If you want to found a clan yourself, read the Clan forum sticky [Clan registry (\"How do I start my own clan?\")|http://www.daimonin.net/index.php?name=PNphpBB2&file=viewtopic&t=665]\n\n")
- .append("|__Name__|__Size__|__Founder__\n")
- ;
- for (final String name : new TreeSet<String>(groups.keySet())) {
- final Group group = groups.get(name);
- if (group.isVisible()) {
- out
- .append('|')
- .append(wikiFix(group.name))
- .append('|')
- .append(Integer.toString(group.getMemberCount()))
- .append('|')
- .append(wikiFix(group.founder))
- .append('\n')
- ;
- }
- }
- out.append("\nNote: The list taken from Cherbot. Please do not modify this page since it is auto-generated. Your changes are likely to be overwritten with the next clan update. For complaints, send a pm to Cheristheus.\n");
- } catch (IOException e) {
- answer(e.toString());
- } finally {
+ final PrintWriter out = new PrintWriter("groupsForWiki.wiki", "iso-8859-1");
try {
+ out
+ .append("This list is Cherbot's list of clans found on damn.\n\n")
+ .append("If you want to found a clan yourself, read the Clan forum sticky [Clan registry (\"How do I start my own clan?\")|http://www.daimonin.net/index.php?name=PNphpBB2&file=viewtopic&t=665]\n\n")
+ .append("|__Name__|__Size__|__Founder__\n")
+ ;
+ for (final String name : new TreeSet<String>(groups.keySet())) {
+ final Group group = groups.get(name);
+ if (group.isVisible()) {
+ out
+ .append('|')
+ .append(escapeForWiki(group.name))
+ .append('|')
+ .append(Integer.toString(group.getMemberCount()))
+ .append('|')
+ .append(escapeForWiki(group.founder))
+ .append('\n')
+ ;
+ }
+ }
+ out.append("\nNote: The list taken from Cherbot. Please do not modify this page since it is auto-generated. Your changes are likely to be overwritten with the next clan update. For complaints, send a pm to Cheristheus.\n");
+ } finally {
out.close();
- } catch (Exception e) { /* ignore */ } finally {
- out = null;
}
+ } catch (final IOException e) {
+ answer(e.toString());
}
}
/**
- * Fix a String for the Wiki.
+ * Escape a String for the Wiki.
+ * @param s String to escape
+ * @return String escaped for Wiki
*/
- private static String wikiFix(final String s) {
+ private static String escapeForWiki(final String s) {
return s.replaceAll("(\\b[A-Z]\\w+[A-Z])", "!$1");
}
@@ -491,7 +490,7 @@
}
return ret;
}
- }
+ } // class MemberRankComparator
/**
* The manager of this Group.
@@ -597,10 +596,7 @@
*/
private boolean isAdmin() {
final Member member = members.get(manager.getActor());
- if (member == null) {
- return false;
- }
- return member.isAdmin();
+ return member != null && member.isAdmin();
}
/**
@@ -609,10 +605,7 @@
*/
private boolean isSender() {
final Member member = members.get(manager.getActor());
- if (member == null) {
- return false;
- }
- return member.isAdmin() || member.isSender();
+ return member != null && (member.isAdmin() || member.isSender());
}
/**
@@ -873,6 +866,7 @@
/**
* Returns wether the player applied for membership in this group.
+ * @param player Player to check whether he's an applicant
* @return <code>true</code> if the player applied for membership in this group
*/
boolean isApplicant(final String player) {
@@ -890,6 +884,7 @@
/**
* Return wether the player was invited to membership in this group.
+ * @param player Player to check whether he's an invitee
* @return <code>true</code> if the player was invited to membership in this group
*/
boolean isInvitee(final String player) {
@@ -1096,6 +1091,7 @@
/**
* Send message to all members.
+ * @param msg Message to send
*/
private void dispatch(final String msg) {
checkMaySend();
@@ -1109,6 +1105,9 @@
/**
* Implementation for deserialization:
* Take care about newly added fields
+ * @param stream Stream to deserialize with
+ * @throws IOException in case of I/O problems during deserialization
+ * @throws ClassNotFoundException in case a class required for deserialization was not found
*/
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
@@ -1153,7 +1152,7 @@
return false;
}
final Group other = (Group) obj;
- return other.name != null ? other.name.equals(name) : false;
+ return other.name != null && other.name.equals(name);
}
/**
@@ -1374,24 +1373,21 @@
@Override public void load() throws IOException {
// Text interface: TODO
// Binary interface:
- ObjectInputStream in = null;
try {
// The groups are completely restored, not merged on load. This is intentional.
- in = new ObjectInputStream(new FileInputStream("groups.dat"));
- groups = (Map<String, Group>) in.readObject();
- for (Map.Entry<String, Group> entry : groups.entrySet()) {
- entry.getValue().manager = this;
+ final ObjectInputStream in = new ObjectInputStream(new FileInputStream("groups.dat"));
+ try {
+ groups = (Map<String, Group>) in.readObject();
+ for (Map.Entry<String, Group> entry : groups.entrySet()) {
+ entry.getValue().manager = this;
+ }
+ } finally {
+ in.close();
}
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
final IOException ioe = new IOException("Error with file \"groups.dat\":");
ioe.initCause(e);
throw ioe;
- } finally {
- try {
- in.close();
- } catch (Exception e) { /* ignore */ } finally {
- in = null;
- }
}
}
@@ -1401,16 +1397,11 @@
@Override public void save() throws IOException {
// Text interface (loading is unfinished):
// Binary interface:
- ObjectOutputStream out = null;
+ final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("groups.dat"));
try {
- out = new ObjectOutputStream(new FileOutputStream("groups.dat"));
out.writeObject(groups);
} finally {
- try {
- out.close();
- } catch (Exception e) { /* ignore */ } finally {
- out = null;
- }
+ out.close();
}
}
Modified: trunk/src/net/sf/cherbot/MailManager.java
===================================================================
--- trunk/src/net/sf/cherbot/MailManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/MailManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -289,6 +289,7 @@
/**
* Checks wether someone has unread mail.
* @param who who has mail
+ * @return <code>true</code> in case <var>who</var> has unread mail, otherwise <code>false</code>.
*/
private boolean hasUnreadMail(final String who) {
final List<Mail> ms = mails.get(who);
@@ -306,6 +307,7 @@
/**
* Checks wether someone has mail.
* @param who who has mail
+ * @return <code>true</code> in case <var>who</var> has mail, otherwise <code>false</code>.
*/
private boolean hasMail(final String who) {
final List<Mail> ms = mails.get(who);
@@ -316,6 +318,7 @@
* Gets a mail.
* @param n number of mail to get
* @throws CherBotException if no such mail
+ * @return mail number <var>n</var> for the actor.
*/
private Mail getMail(final int n) {
try {
@@ -361,9 +364,9 @@
/**
* Send mail.
- * @param from
- * @param to
- * @param msg
+ * @param from Sender
+ * @param to Receiver
+ * @param msg Message body
*/
@Override public void mail(final String from, final String to, final String msg) {
new Mail(from, to, msg);
Modified: trunk/src/net/sf/cherbot/Manager.java
===================================================================
--- trunk/src/net/sf/cherbot/Manager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/Manager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -229,10 +229,7 @@
return false;
} // Return false since if not keeping track better treat noone as logged in
assert playerManager != this : "A Manager for \"players\" must override Manager.player(String)!";
- if (playerManager == this) {
- return false;
- } // simply return if assertions aren't enabled, to avoid endless recursion
- return playerManager.isLoggedIn(player);
+ return playerManager != this && playerManager.isLoggedIn(player);
}
/**
@@ -1013,7 +1010,7 @@
} finally {
try {
line = reader().readLine();
- } catch (IOException e) {
+ } catch (final IOException e) {
line = null;
this.e = e;
}
@@ -1067,7 +1064,7 @@
if (clearBeforeLoading) {
col.clear();
}
- for (String line : this) {
+ for (final String line : this) {
col.add(line);
}
}
@@ -1076,7 +1073,7 @@
* {@inheritDoc}
*/
@Override protected final void saveImpl() {
- for (String line : col) {
+ for (final String line : col) {
println(line);
}
}
Modified: trunk/src/net/sf/cherbot/PlayerManager.java
===================================================================
--- trunk/src/net/sf/cherbot/PlayerManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/PlayerManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -869,7 +869,7 @@
*/
private static enum Gender {
- male, female;
+ MALE, FEMALE
}
} // class LevelManager
Modified: trunk/src/net/sf/cherbot/PollManager.java
===================================================================
--- trunk/src/net/sf/cherbot/PollManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/PollManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -282,18 +282,13 @@
* {@inheritDoc}
*/
@Override public void save() throws IOException {
- PrintWriter out = null;
+ final PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("polls.txt")));
try {
- out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("polls.txt")));
- for (Poll poll : polls) {
+ for (final Poll poll : polls) {
poll.writeTo(out);
}
} finally {
- try {
- out.close();
- } catch (Exception e) { /* ignore */ } finally {
- out = null;
- }
+ out.close();
}
}
@@ -301,20 +296,15 @@
* {@inheritDoc}
*/
@Override public void load() throws IOException {
- BufferedReader in = null;
+ BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("polls.txt")));
try {
- in = new BufferedReader(new InputStreamReader(new FileInputStream("polls.txt")));
- try {
- while (polls.add(new Poll(in))) {
- ;
- }
- } catch (NullPointerException e) { /* ignore */ }
- } finally {
- try {
- in.close();
- } catch (Exception e) { /* ignore */ } finally {
- in = null;
+ while (polls.add(new Poll(in))) {
+ ;
}
+ } catch (final NullPointerException e) {
+ /* ignore */
+ } finally {
+ in.close();
}
}
Modified: trunk/src/net/sf/cherbot/SalesManager.java
===================================================================
--- trunk/src/net/sf/cherbot/SalesManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/SalesManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -133,7 +133,7 @@
/**
* List the sellers that sell a specific ware.
- * @param ware
+ * @param ware Ware to sell
*/
private void listSellers(final String ware) {
final Set<String> sellers = new TreeSet<String>();
Modified: trunk/src/net/sf/cherbot/SmutManager.java
===================================================================
--- trunk/src/net/sf/cherbot/SmutManager.java 2006-10-29 13:13:32 UTC (rev 30)
+++ trunk/src/net/sf/cherbot/SmutManager.java 2006-10-29 13:49:33 UTC (rev 31)
@@ -129,6 +129,7 @@
/**
* Remove a pattern to the list of smut patterns.
* @param pattern pattern to remove
+ * @return whether remove was successful
*/
public boolean remove(final String pattern) {
return patterns.remove(Pattern.compile(pattern));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|