Applied style fixes.

fix-message-formatting
Danny van Heumen 11 years ago
parent 02e9304973
commit c878830f7b

@ -5,7 +5,7 @@
/**
* IRC contact implementation.
*
* @author danny
* @author Danny van Heumen
*/
public class ContactIrcImpl
extends AbstractContact
@ -35,18 +35,25 @@ public class ContactIrcImpl
*
* @param provider Protocol provider service instance.
* @param id Contact id.
* @param parentGroup The parent group of the contact.
*/
public ContactIrcImpl(ProtocolProviderServiceIrcImpl provider, String id,
ContactGroupIrcImpl parentGroup, PresenceStatus initialStatus)
{
if (provider == null)
{
throw new IllegalArgumentException("provider cannot be null");
}
this.provider = provider;
if (id == null)
{
throw new IllegalArgumentException("id cannot be null");
}
this.id = id;
if (parentGroup == null)
{
throw new IllegalArgumentException("parentGroup cannot be null");
}
this.parentGroup = parentGroup;
this.presence =
initialStatus == null ? IrcStatusEnum.ONLINE : initialStatus;
@ -75,7 +82,7 @@ public String getDisplayName()
}
/**
* Get contact image (avatar)
* Get contact image (avatar).
*
* @return returns image data
*/
@ -104,7 +111,9 @@ public PresenceStatus getPresenceStatus()
protected void setPresenceStatus(PresenceStatus status)
{
if (status == null)
{
throw new IllegalArgumentException("status cannot be null");
}
this.presence = status;
}

@ -39,12 +39,12 @@ public class IrcStack
private static final long CHAT_ROOM_LIST_CACHE_EXPIRATION = 60000000000L;
/**
* Logger
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(IrcStack.class);
/**
* Parent provider for IRC
* Parent provider for IRC.
*/
private final ProtocolProviderServiceIrcImpl provider;
@ -98,7 +98,7 @@ public class IrcStack
new Container<List<String>>(null);
/**
* Constructor
* Constructor.
*
* @param parentProvider Parent provider
* @param nick User's nick name
@ -145,16 +145,21 @@ public boolean isSecureConnection()
*
* @param host IRC server's host name
* @param port IRC port
* @param password
* @param autoNickChange
* @throws Exception
* @param password password for the specified nick name
* @param secureConnection true to set up secure connection, or false if
* not.
* @param autoNickChange do automatic nick changes if nick is in use
* @throws Exception throws exceptions
*/
public void connect(String host, int port, String password,
boolean secureConnection, boolean autoNickChange) throws Exception
public void connect(final String host, final int port,
final String password, final boolean secureConnection,
final boolean autoNickChange) throws Exception
{
if (this.session.get() != null && this.connectionState != null
&& this.connectionState.isConnected())
{
return;
}
// Make sure we start with an empty joined-channel list.
this.joined.clear();
@ -186,7 +191,7 @@ public void connect(String host, int port, String password,
{
@Override
public void onMessage(IMessage aMessage)
public void onMessage(final IMessage aMessage)
{
LOGGER.trace("(" + aMessage + ") " + aMessage.asRaw());
}
@ -204,7 +209,6 @@ public void onMessage(IMessage aMessage)
/**
* Perform synchronized connect operation.
*
* @return returns true upon successful connection, false otherwise
* @throws Exception exception thrown when connect fails
*/
private void connectSynchronized() throws Exception
@ -226,7 +230,7 @@ private void connectSynchronized() throws Exception
{
@Override
public void onSuccess(IIRCState state)
public void onSuccess(final IIRCState state)
{
synchronized (result)
{
@ -237,7 +241,7 @@ public void onSuccess(IIRCState state)
}
@Override
public void onFailure(Exception e)
public void onFailure(final Exception e)
{
synchronized (result)
{
@ -277,7 +281,9 @@ public void onFailure(Exception e)
RegistrationState.CONNECTION_FAILED);
Exception e = result.getException();
if (e != null)
{
throw e;
}
}
}
catch (IOException e)
@ -301,10 +307,13 @@ public void onFailure(Exception e)
/**
* Create a custom SSL context for this particular server.
*
* @param hostname host name of the host we are connecting to such that we
* can verify that the same host name is on the server
* certificate
* @return returns a customized SSL context or <tt>null</tt> if one cannot
* be created.
*/
private SSLContext getCustomSSLContext(String hostname)
private SSLContext getCustomSSLContext(final String hostname)
{
SSLContext context = null;
try
@ -323,12 +332,14 @@ private SSLContext getCustomSSLContext(String hostname)
}
/**
* Disconnect from the IRC server
* Disconnect from the IRC server.
*/
public void disconnect()
{
if (this.connectionState == null && this.session.get() == null)
{
return;
}
synchronized (this.joined)
{
@ -365,7 +376,7 @@ public void disconnect()
}
/**
* Dispose
* Dispose.
*/
public void dispose()
{
@ -380,7 +391,9 @@ public void dispose()
public Set<Character> getChannelTypes()
{
if (!isConnected())
{
throw new IllegalStateException("not connected to IRC server");
}
return this.connectionState.getServerOptions().getChanTypes();
}
@ -392,8 +405,14 @@ public Set<Character> getChannelTypes()
*/
public String getNick()
{
return (this.connectionState == null) ? this.params.getNickname()
: this.connectionState.getNickname();
if (this.connectionState == null)
{
return this.params.getNickname();
}
else
{
return this.connectionState.getNickname();
}
}
/**
@ -401,7 +420,7 @@ public String getNick()
*
* @param nick the new nick name
*/
public void setUserNickname(String nick)
public void setUserNickname(final String nick)
{
LOGGER.trace("Setting user's nick name to " + nick);
if (isConnected())
@ -421,13 +440,17 @@ public void setUserNickname(String nick)
* @param chatroom The chat room for which to set the subject.
* @param subject The subject.
*/
public void setSubject(ChatRoomIrcImpl chatroom, String subject)
public void setSubject(final ChatRoomIrcImpl chatroom, final String subject)
{
if (!isConnected())
{
throw new IllegalStateException(
"Please connect to an IRC server first.");
}
if (chatroom == null)
{
throw new IllegalArgumentException("Cannot have a null chatroom");
}
LOGGER.trace("Setting chat room topic to '" + subject + "'");
this.session.get().changeTopic(chatroom.getIdentifier(),
subject == null ? "" : subject);
@ -440,7 +463,7 @@ public void setSubject(ChatRoomIrcImpl chatroom, String subject)
* @return Returns true in case the user is already joined, or false if the
* user has not joined.
*/
public boolean isJoined(ChatRoomIrcImpl chatroom)
public boolean isJoined(final ChatRoomIrcImpl chatroom)
{
return this.joined.get(chatroom.getIdentifier()) != null;
}
@ -510,7 +533,8 @@ public List<String> getServerChatRoomList()
* @param chatroom Chat room to join.
* @throws OperationFailedException failed to join the chat room
*/
public void join(ChatRoomIrcImpl chatroom) throws OperationFailedException
public void join(final ChatRoomIrcImpl chatroom)
throws OperationFailedException
{
join(chatroom, "");
}
@ -530,14 +554,20 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
throws OperationFailedException
{
if (!isConnected())
{
throw new IllegalStateException(
"Please connect to an IRC server first");
}
if (chatroom == null || chatroom.getIdentifier() == null
|| chatroom.getIdentifier().isEmpty())
{
throw new IllegalArgumentException(
"chatroom cannot be null or emtpy");
}
if (password == null)
{
throw new IllegalArgumentException("password cannot be null");
}
// Get instance of irc client api.
final IRCApi irc = this.session.get();
@ -579,7 +609,7 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
{
@Override
public void onSuccess(IRCChannel channel)
public void onSuccess(final IRCChannel channel)
{
if (LOGGER.isTraceEnabled())
{
@ -661,7 +691,7 @@ public void onSuccess(IRCChannel channel)
}
@Override
public void onFailure(Exception e)
public void onFailure(final Exception e)
{
LOGGER.trace("Started callback for failed attempt to "
+ "join channel '" + chatRoomId + "'.");
@ -722,7 +752,7 @@ public void onFailure(Exception e)
*
* @param chatroom The chat room to part from.
*/
public void leave(ChatRoomIrcImpl chatroom)
public void leave(final ChatRoomIrcImpl chatroom)
{
LOGGER.trace("Leaving chat room '" + chatroom.getIdentifier() + "'.");
@ -736,10 +766,12 @@ public void leave(ChatRoomIrcImpl chatroom)
*
* @param chatRoomName The chat room to part from.
*/
private void leave(String chatRoomName)
private void leave(final String chatRoomName)
{
if (!isConnected())
{
return;
}
final IRCApi irc = this.session.get();
try
@ -758,10 +790,12 @@ private void leave(String chatRoomName)
* @param chatroom chat room to ban from
* @param member member to ban
* @param reason reason for banning
* @throws OperationFailedException
* @throws OperationFailedException throws operation failed in case of
* trouble.
*/
public void banParticipant(ChatRoomIrcImpl chatroom, ChatRoomMember member,
String reason) throws OperationFailedException
public void banParticipant(final ChatRoomIrcImpl chatroom,
final ChatRoomMember member, final String reason)
throws OperationFailedException
{
// TODO Implement banParticipant.
throw new OperationFailedException("Not implemented yet.",
@ -775,11 +809,13 @@ public void banParticipant(ChatRoomIrcImpl chatroom, ChatRoomMember member,
* @param member member to kick
* @param reason kick message to deliver
*/
public void kickParticipant(ChatRoomIrcImpl chatroom,
ChatRoomMember member, String reason)
public void kickParticipant(final ChatRoomIrcImpl chatroom,
final ChatRoomMember member, final String reason)
{
if (!isConnected())
{
return;
}
final IRCApi irc = this.session.get();
irc.kick(chatroom.getIdentifier(), member.getContactAddress(), reason);
@ -791,10 +827,12 @@ public void kickParticipant(ChatRoomIrcImpl chatroom,
* @param memberId member to invite
* @param chatroom channel to invite to
*/
public void invite(String memberId, ChatRoomIrcImpl chatroom)
public void invite(final String memberId, final ChatRoomIrcImpl chatroom)
{
if (!isConnected())
{
return;
}
final IRCApi irc = this.session.get();
irc.rawMessage("INVITE " + memberId + " " + chatroom.getIdentifier());
@ -804,7 +842,7 @@ public void invite(String memberId, ChatRoomIrcImpl chatroom)
* Send a command to the IRC server.
*
* @param chatroom the chat room
* @param command the command message
* @param message the command message
*/
public void command(final ChatRoomIrcImpl chatroom, final String message)
{
@ -814,8 +852,8 @@ public void command(final ChatRoomIrcImpl chatroom, final String message)
/**
* Send a command to the IRC server.
*
* @param chatroom the chat room
* @param command the command message
* @param contact the chat room
* @param message the command message
*/
public void command(final Contact contact, final String message)
{
@ -861,7 +899,7 @@ private void command(final String source, final String message)
* @param chatroom The chat room to send the message to.
* @param message The message to send.
*/
public void message(ChatRoomIrcImpl chatroom, String message)
public void message(final ChatRoomIrcImpl chatroom, final String message)
{
final IRCApi irc = this.session.get();
String target = chatroom.getIdentifier();
@ -901,7 +939,8 @@ public void message(final Contact contact, final Message message)
* @param userAddress user to grant permissions to
* @param mode mode to grant
*/
public void grant(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
public void grant(final ChatRoomIrcImpl chatRoom, final String userAddress,
final Mode mode)
{
if (mode.getRole() == null)
{
@ -920,7 +959,8 @@ public void grant(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
* @param userAddress user
* @param mode mode
*/
public void revoke(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
public void revoke(final ChatRoomIrcImpl chatRoom,
final String userAddress, final Mode mode)
{
if (mode.getRole() == null)
{
@ -978,7 +1018,7 @@ private void prepareChatRoom(final ChatRoomIrcImpl chatRoom,
* @return Return the instance of ChatRoomMemberRole corresponding to the
* member mode character.
*/
private static ChatRoomMemberRole convertMemberMode(char modeSymbol)
private static ChatRoomMemberRole convertMemberMode(final char modeSymbol)
{
return Mode.bySymbol(modeSymbol).getRole();
}
@ -998,7 +1038,7 @@ private class ServerListener
* @param msg the server notice
*/
@Override
public void onServerNotice(ServerNotice msg)
public void onServerNotice(final ServerNotice msg)
{
LOGGER.debug("NOTICE: " + msg.getText());
}
@ -1010,7 +1050,7 @@ public void onServerNotice(ServerNotice msg)
* @param msg the numeric message
*/
@Override
public void onServerNumericMessage(ServerNumericMessage msg)
public void onServerNumericMessage(final ServerNumericMessage msg)
{
if (LOGGER.isDebugEnabled())
{
@ -1110,7 +1150,7 @@ public void onServerNumericMessage(ServerNumericMessage msg)
* @param msg the error message
*/
@Override
public void onError(ErrorMessage msg)
public void onError(final ErrorMessage msg)
{
if (LOGGER.isDebugEnabled())
{
@ -1162,8 +1202,8 @@ public void onUserPrivMessage(final UserPrivMsg msg)
// MetaContactGroup for NonPersistent group, since this is an
// outstanding error.
LOGGER.error(
"Error occurred while delivering private message from user '"
+ user + "': " + text, e);
"Error occurred while delivering private message from user"
+ " '" + user + "': " + text, e);
}
}
@ -1174,8 +1214,13 @@ public void onUserPrivMessage(final UserPrivMsg msg)
* @param msg user notice message
*/
@Override
public void onUserNotice(UserNotice msg)
public void onUserNotice(final UserNotice msg)
{
// TODO Probably better to deliver NOTICEs to all channels, instead
// of setting up private chat. You are not supposed to reply to
// NOTICEs and setting up a private chat session kind of does that.
// Even though the user should respond themslves in the default
// Jitsi set up.
final String user = msg.getSource().getNick();
final String text =
Utils.formatNotice(Utils.parse(msg.getText()), user);
@ -1198,7 +1243,7 @@ public void onUserNotice(UserNotice msg)
* @param msg user action message
*/
@Override
public void onUserAction(UserActionMsg msg)
public void onUserAction(final UserActionMsg msg)
{
final String user = msg.getSource().getNick();
final String text =
@ -1284,7 +1329,7 @@ public void onUserQuit(QuitMessage msg)
* @author Danny van Heumen
*
*/
private class ChatRoomListener
private final class ChatRoomListener
extends VariousMessageListenerAdapter
{
/**
@ -1300,12 +1345,14 @@ private class ChatRoomListener
/**
* Constructor. Instantiate listener for the provided chat room.
*
* @param chatroom
* @param chatroom the chat room
*/
private ChatRoomListener(ChatRoomIrcImpl chatroom)
private ChatRoomListener(final ChatRoomIrcImpl chatroom)
{
if (chatroom == null)
{
throw new IllegalArgumentException("chatroom cannot be null");
}
this.chatroom = chatroom;
}
@ -1316,10 +1363,12 @@ private ChatRoomListener(ChatRoomIrcImpl chatroom)
* @param msg topic change message
*/
@Override
public void onTopicChange(TopicMessage msg)
public void onTopicChange(final TopicMessage msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
this.chatroom.updateSubject(msg.getTopic().getValue());
}
@ -1330,10 +1379,12 @@ public void onTopicChange(TopicMessage msg)
* @param msg channel mode message
*/
@Override
public void onChannelMode(ChannelModeMessage msg)
public void onChannelMode(final ChannelModeMessage msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
processModeMessage(msg);
}
@ -1344,10 +1395,12 @@ public void onChannelMode(ChannelModeMessage msg)
* @param msg channel join message
*/
@Override
public void onChannelJoin(ChanJoinMessage msg)
public void onChannelJoin(final ChanJoinMessage msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
String user = msg.getSource().getNick();
ChatRoomMemberIrcImpl member =
@ -1363,10 +1416,12 @@ public void onChannelJoin(ChanJoinMessage msg)
* @param msg channel part message
*/
@Override
public void onChannelPart(ChanPartMessage msg)
public void onChannelPart(final ChanPartMessage msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
IRCUser user = msg.getSource();
if (isMe(user))
@ -1399,7 +1454,7 @@ public void onChannelPart(ChanPartMessage msg)
*
* @param msg IRC server numeric message
*/
public void onServerNumericMessage(ServerNumericMessage msg)
public void onServerNumericMessage(final ServerNumericMessage msg)
{
Integer code = msg.getNumericCode();
if (code == null)
@ -1432,10 +1487,12 @@ public void onServerNumericMessage(ServerNumericMessage msg)
* @param msg channel kick message
*/
@Override
public void onChannelKick(ChannelKick msg)
public void onChannelKick(final ChannelKick msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
if (!IrcStack.this.isConnected())
{
@ -1475,7 +1532,7 @@ public void onChannelKick(ChannelKick msg)
* @param msg user quit message
*/
@Override
public void onUserQuit(QuitMessage msg)
public void onUserQuit(final QuitMessage msg)
{
String user = msg.getSource().getNick();
ChatRoomMember member = this.chatroom.getChatRoomMember(user);
@ -1493,10 +1550,12 @@ public void onUserQuit(QuitMessage msg)
* @param msg nick change message
*/
@Override
public void onNickChange(NickMessage msg)
public void onNickChange(final NickMessage msg)
{
if (msg == null)
{
return;
}
String oldNick = msg.getSource().getNick();
String newNick = msg.getNewNick();
@ -1523,10 +1582,12 @@ public void onNickChange(NickMessage msg)
* @param msg channel message
*/
@Override
public void onChannelMessage(ChannelPrivMsg msg)
public void onChannelMessage(final ChannelPrivMsg msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
String text = Utils.formatMessage(Utils.parse(msg.getText()));
MessageIrcImpl message =
@ -1545,10 +1606,12 @@ public void onChannelMessage(ChannelPrivMsg msg)
* @param msg channel action message
*/
@Override
public void onChannelAction(ChannelActionMsg msg)
public void onChannelAction(final ChannelActionMsg msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
String userNick = msg.getSource().getNick();
ChatRoomMemberIrcImpl member =
@ -1568,10 +1631,12 @@ public void onChannelAction(ChannelActionMsg msg)
* @param msg channel notice message
*/
@Override
public void onChannelNotice(ChannelNotice msg)
public void onChannelNotice(final ChannelNotice msg)
{
if (!isThisChatRoom(msg.getChannelName()))
{
return;
}
String userNick = msg.getSource().getNick();
ChatRoomMemberIrcImpl member =
@ -1603,7 +1668,7 @@ private void leaveChatRoom()
*
* @param msg raw mode message
*/
private void processModeMessage(ChannelModeMessage msg)
private void processModeMessage(final ChannelModeMessage msg)
{
ChatRoomMemberIrcImpl sourceMember = extractChatRoomMember(msg);
@ -1754,7 +1819,7 @@ sourceMember, new Date(),
* @return returns member instance
*/
private ChatRoomMemberIrcImpl extractChatRoomMember(
ChannelModeMessage msg)
final ChannelModeMessage msg)
{
ChatRoomMemberIrcImpl member;
ISource source = msg.getSource();
@ -1789,7 +1854,7 @@ else if (source instanceof IRCUser)
* @param chatRoomName chat room name
* @return returns true if this listener applies, false otherwise
*/
private boolean isThisChatRoom(String chatRoomName)
private boolean isThisChatRoom(final String chatRoomName)
{
return this.chatroom.getIdentifier().equalsIgnoreCase(chatRoomName);
}
@ -1800,7 +1865,7 @@ private boolean isThisChatRoom(String chatRoomName)
* @param user the source user
* @return returns true if this use, or false otherwise
*/
private boolean isMe(IRCUser user)
private boolean isMe(final IRCUser user)
{
return IrcStack.this.connectionState.getNickname().equals(
user.getNick());
@ -1812,7 +1877,7 @@ private boolean isMe(IRCUser user)
* @param name nick of the user
* @return returns true if so, false otherwise
*/
private boolean isMe(String name)
private boolean isMe(final String name)
{
return IrcStack.this.connectionState.getNickname().equals(name);
}
@ -1822,7 +1887,7 @@ private boolean isMe(String name)
* Special listener that processes LIST replies and signals once the list is
* completely filled.
*/
private static class ChannelListListener
private static final class ChannelListListener
extends VariousMessageListenerAdapter
{
/**
@ -1840,12 +1905,14 @@ private static class ChannelListListener
* @param api irc-api library instance
* @param list signal for sync signaling
*/
private ChannelListListener(IRCApi api,
Result<List<String>, Exception> list)
private ChannelListListener(final IRCApi api,
final Result<List<String>, Exception> list)
{
if (api == null)
{
throw new IllegalArgumentException(
"IRC api instance cannot be null");
}
this.api = api;
this.signal = list;
}
@ -1857,12 +1924,16 @@ private ChannelListListener(IRCApi api,
* Clears the list upon starting. All received channels are added to the
* list. Upon receiving RPL_LISTEND finalize the list and signal the
* waiting thread that it can continue processing the list.
*
* @param msg The numeric server message.
*/
@Override
public void onServerNumericMessage(ServerNumericMessage msg)
public void onServerNumericMessage(final ServerNumericMessage msg)
{
if (this.signal.isDone())
{
return;
}
switch (msg.getNumericCode())
{
@ -1904,11 +1975,13 @@ public void onServerNumericMessage(ServerNumericMessage msg)
* @param text raw server response
* @return returns the channel name
*/
private String parse(String text)
private String parse(final String text)
{
int endOfChannelName = text.indexOf(' ');
if (endOfChannelName == -1)
{
return null;
}
// Create a new string to make sure that the original (larger)
// strings can be GC'ed.
return new String(text.substring(0, endOfChannelName));
@ -1918,7 +1991,7 @@ private String parse(String text)
/**
* Container for storing server parameters.
*/
private static class ServerParameters
private static final class ServerParameters
implements IServerParameters
{
@ -1954,8 +2027,8 @@ private static class ServerParameters
* @param ident ident
* @param server IRC server instance
*/
private ServerParameters(String nickName, String realName,
String ident, IRCServer server)
private ServerParameters(final String nickName, final String realName,
final String ident, final IRCServer server)
{
this.nick = checkNick(nickName);
this.alternativeNicks.add(nickName + "_");
@ -1987,7 +2060,7 @@ public String getNickname()
*
* @param nick nick name
*/
public void setNickname(String nick)
public void setNickname(final String nick)
{
this.nick = checkNick(nick);
}
@ -1997,19 +2070,20 @@ public void setNickname(String nick)
*
* @param nick nick name
* @return returns nick name
* @throws IllegalArgumentException throws
* <tt>IllegalArgumentException</tt> if an invalid nick name
* is provided.
*/
private String checkNick(String nick)
private String checkNick(final String nick)
{
if (nick == null)
{
throw new IllegalArgumentException(
"a nick name must be provided");
}
if (nick.startsWith("#") || nick.startsWith("&"))
{
throw new IllegalArgumentException(
"the nick name must not start with '#' or '&' "
+ "since this is reserved for IRC channels");
}
return nick;
}
@ -2036,7 +2110,7 @@ public String getIdent()
}
/**
* Get real name
* Get real name.
*
* @return returns real name
*/
@ -2047,7 +2121,7 @@ public String getRealname()
}
/**
* Get server
* Get server.
*
* @return returns server instance
*/
@ -2062,11 +2136,12 @@ public IRCServer getServer()
*
* @param server IRC server instance
*/
public void setServer(IRCServer server)
public void setServer(final IRCServer server)
{
if (server == null)
{
throw new IllegalArgumentException("server cannot be null");
}
this.server = server;
}
}
@ -2077,7 +2152,7 @@ public void setServer(IRCServer server)
*
* @param <T> The type of instance to store in the container
*/
private static class Container<T>
private static final class Container<T>
{
/**
* The stored instance. (Can be null)
@ -2094,7 +2169,7 @@ private static class Container<T>
*
* @param instance the instance to set
*/
private Container(T instance)
private Container(final T instance)
{
this.instance = instance;
this.time = System.nanoTime();
@ -2107,7 +2182,7 @@ private Container(T instance)
* @param bound maximum time difference that is allowed.
* @return returns instance if within bounds, or null otherwise
*/
public T get(long bound)
public T get(final long bound)
{
if (System.nanoTime() - this.time > bound)
{
@ -2117,11 +2192,11 @@ public T get(long bound)
}
/**
* Set an instance
* Set an instance.
*
* @param instance the instance
*/
public void set(T instance)
public void set(final T instance)
{
this.instance = instance;
this.time = System.nanoTime();

@ -15,10 +15,15 @@
public final class Utils
{
/**
* Logger
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(Utils.class);
/**
* Index indicating the end of the color code.
*/
private static final int INDEX_END_COLOR_CODE = 3;
/**
* Private constructor since we do not need to construct anything.
*/
@ -29,17 +34,19 @@ private Utils()
/**
* Parse IRC text message and process possible control codes.
*
* TODO Support for color 99 (Transparent)
* TODO Support for wrapping around after color 15?
* TODO Support for color 99 (Transparent) TODO Support for wrapping around
* after color 15?
*
* @param text the message
* @return returns the processed message or null if text message was null,
* since there is nothing to modify there
*/
public static String parse(String text)
public static String parse(final String text)
{
if (text == null)
{
return null;
}
FormattedTextBuilder builder = new FormattedTextBuilder();
for (int i = 0; i < text.length(); i++)
@ -86,9 +93,11 @@ public static String parse(String text)
foreground = parseForegroundColor(text.substring(i + 1));
i += 2;
// FIXME IAE thrown in case of missing background color.
// This should be ignored. It is no error.
// parse background color code
background = parseBackgroundColor(text.substring(i + 1));
i += 3;
i += INDEX_END_COLOR_CODE;
}
catch (IllegalArgumentException e)
{
@ -129,7 +138,7 @@ public static String parse(String text)
* @param text the text starting with the background color (separator)
* @return returns the background color
*/
private static Color parseBackgroundColor(String text)
private static Color parseBackgroundColor(final String text)
{
try
{
@ -154,13 +163,15 @@ private static Color parseBackgroundColor(String text)
{
// No background color defined, ignoring ...
throw new IllegalArgumentException(
"value isn't a background color code: " + text.substring(1, 3));
"value isn't a background color code: "
+ text.substring(1, INDEX_END_COLOR_CODE));
}
catch (ArrayIndexOutOfBoundsException e)
{
LOGGER.info("Specified IRC color is not a known color code.", e);
throw new IllegalArgumentException("background color value "
+ text.substring(1, 3) + " is not a known color");
+ text.substring(1, INDEX_END_COLOR_CODE)
+ " is not a known color");
}
}
@ -170,7 +181,7 @@ private static Color parseBackgroundColor(String text)
* @param text the text to parse, starting with color code
* @return returns Color instance
*/
private static Color parseForegroundColor(String text)
private static Color parseForegroundColor(final String text)
{
try
{
@ -186,6 +197,8 @@ private static Color parseForegroundColor(String text)
}
catch (NumberFormatException e)
{
// FIXME correctly print out color code (as a number or hex number)
// FIXME wrap around color codes?
// Invalid text color value
LOGGER.trace("Invalid foreground color code encountered.");
throw new IllegalArgumentException(
@ -199,17 +212,37 @@ private static Color parseForegroundColor(String text)
}
}
public static String formatMessage(String message)
/**
* Format message as normal HTML-formatted message.
*
* @param message original IRC message
* @return returns HTML-formatted normal message
*/
public static String formatMessage(final String message)
{
return message;
}
public static String formatNotice(String message, String user)
/**
* Format message as HTML-formatted notice.
*
* @param message original IRC message
* @param user user nick name
* @return returns HTML-formatted notice
*/
public static String formatNotice(final String message, final String user)
{
return "<i>" + user + "</i>: " + message;
}
public static String formatAction(String message, String user)
/**
* Format message as HTML-formatted action.
*
* @param message original IRC message
* @param user user nick name
* @return returns HTML-formatted action
*/
public static String formatAction(final String message, final String user)
{
return "<b>*" + user + "</b> " + message;
}

Loading…
Cancel
Save