Avoids Integer allocations, removes unnecessary fields by making inner classes static.

cusax-fix
Lyubomir Marinov 18 years ago
parent 9fd6a51a96
commit bcada6b6cc

@ -913,7 +913,8 @@ else if (event.getType() == ServiceEvent.UNREGISTERING)
/**
* Joins a chat room in an asynchronous way.
*/
private class JoinChatRoomTask extends SwingWorker<String, Object>
private static class JoinChatRoomTask
extends SwingWorker<String, Object>
{
private static final String SUCCESS = "Success";
@ -932,11 +933,11 @@ private class JoinChatRoomTask extends SwingWorker<String, Object>
private static final String UNKNOWN_ERROR
= "UnknownError";
private ChatRoomWrapper chatRoomWrapper;
private final ChatRoomWrapper chatRoomWrapper;
private String nickName;
private final String nickName;
private byte[] password;
private final byte[] password;
JoinChatRoomTask( ChatRoomWrapper chatRoomWrapper,
String nickName,
@ -971,29 +972,19 @@ else if (nickName != null)
logger.trace("Failed to join chat room: "
+ chatRoom.getName(), e);
if(e.getErrorCode()
== OperationFailedException.AUTHENTICATION_FAILED)
switch (e.getErrorCode())
{
case OperationFailedException.AUTHENTICATION_FAILED:
return AUTHENTICATION_FAILED;
}
else if(e.getErrorCode()
== OperationFailedException.REGISTRATION_REQUIRED)
{
case OperationFailedException.REGISTRATION_REQUIRED:
return REGISTRATION_REQUIRED;
}
else if(e.getErrorCode()
== OperationFailedException.PROVIDER_NOT_REGISTERED)
{
case OperationFailedException.PROVIDER_NOT_REGISTERED:
return PROVIDER_NOT_REGISTERED;
}
else if(e.getErrorCode()
== OperationFailedException
.SUBSCRIPTION_ALREADY_EXISTS)
{
case OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS:
return SUBSCRIPTION_ALREADY_EXISTS;
}
else
default:
return UNKNOWN_ERROR;
}
}
}
@ -1070,11 +1061,12 @@ else if(SUBSCRIPTION_ALREADY_EXISTS.equals(returnCode))
/**
* Finds a chat room in asynchronous way.
*/
private class FindRoomTask extends SwingWorker<ChatRoom, Object>
private static class FindRoomTask
extends SwingWorker<ChatRoom, Object>
{
private String chatRoomName;
private final String chatRoomName;
private ChatRoomProviderWrapper chatRoomProvider;
private final ChatRoomProviderWrapper chatRoomProvider;
FindRoomTask( String chatRoomName,
ChatRoomProviderWrapper chatRoomProvider)
@ -1109,9 +1101,10 @@ public ChatRoom doInBackground()
}
}
private class FindAllRoomsTask extends SwingWorker<List<String>, Object>
private static class FindAllRoomsTask
extends SwingWorker<List<String>, Object>
{
private ChatRoomProviderWrapper chatRoomProvider;
private final ChatRoomProviderWrapper chatRoomProvider;
FindAllRoomsTask(ChatRoomProviderWrapper provider)
{

@ -814,7 +814,7 @@ protected AimConnection getAimConnection()
return aimConnection;
}
public class AimIcbmListener implements IcbmListener
public static class AimIcbmListener implements IcbmListener
{
public void newConversation(IcbmService service, Conversation conv)
@ -834,7 +834,6 @@ public void sendAutomaticallyFailed(
net.kano.joustsim.oscar.oscar.service.icbm.Message message,
Set triedConversations)
{
}
}

@ -61,7 +61,7 @@ public class ChatRoomMemberRole
/**
* the name of this role.
*/
private String roleName = null;
private final String roleName;
/**
* The index of a role is used to allow ordering of roles by other modules
@ -69,7 +69,7 @@ public class ChatRoomMemberRole
* Higher values of the role index indicate roles with more permissions and
* lower values pertain to more restrictive roles.
*/
private int roleIndex;
private final int roleIndex;
/**
* Creates a role with the specified <tt>roleName</tt>. The constructor
@ -136,17 +136,22 @@ public int getRoleIndex()
*/
public boolean equals(Object obj)
{
if( obj == null
|| !(obj instanceof ChatRoomMemberRole)
|| !((ChatRoomMemberRole)obj).getRoleName().equals(roleName)
|| ((ChatRoomMemberRole)obj).getRoleIndex() != getRoleIndex())
{
return false;
}
else
{
if (obj == this)
return true;
}
/*
* XXX Implementing Object#equals(Object) with instanceof is error
* prone. The safe and recommended approach is to return true only if
* the runtime types of the two Objects being tested are one and the
* same i.e. getClass().equals(obj.getClass()).
*/
if (!(obj instanceof ChatRoomMemberRole))
return false;
ChatRoomMemberRole role = (ChatRoomMemberRole) obj;
return role.getRoleName().equals(getRoleName())
&& (role.getRoleIndex() == getRoleIndex());
}
/**
@ -176,8 +181,7 @@ public int hashCode()
public int compareTo(Object obj)
throws ClassCastException
{
return new Integer(getRoleIndex())
.compareTo(new Integer(((ChatRoomMemberRole)obj).getRoleIndex()));
return getRoleIndex() - ((ChatRoomMemberRole) obj).getRoleIndex();
}
}

Loading…
Cancel
Save