net.jackofalltrades.irc
Class IrcPrefix

java.lang.Object
  extended bynet.jackofalltrades.irc.IrcPrefix

public class IrcPrefix
extends java.lang.Object

Represents the prefix of an IRC command. Prefixes are used by the IRC server to indicate whom sent the message. A prefix is in the format of nickname[[!identName]@hostname] (brackets indicate optional data), or a hostname.

According to RFC 2812, a nickname and hostname could possibly match in format. However, ONLY hostnames may contain the period (".") character. If the prefix fails a check for nickname!identname@hostname and nickname@hostname, then a check for periods is executed. If the period check fails, then a domain name resolution is executed, and if this fails, the prefix is considered a nickname.

Prefixes are cached internally, so once an IrcPrefix is created, it not be created again. This allows for equality checking using the "==" operator, and also saves on domain name resolution checks.

Since:
0.5-alpha
Version:
1.0
Author:
Bradley M. Handy

Method Summary
 java.lang.String getHostname()
          Returns the hostname portion of the prefix.
 java.lang.String getIdentName()
          Returns the username given by the user's ident server.
static IrcPrefix getInstance(java.lang.String prefix)
          Returns an IrcPrefix representing the passed in string.
static IrcPrefix getInstance(java.lang.String nickname, java.lang.String hostname)
          Returns an representing the specified nickname and hostname.
static IrcPrefix getInstance(java.lang.String nickname, java.lang.String identName, java.lang.String hostname)
          Returns an representing the specified nickname, identName, and hostname.
 java.lang.String getNickname()
          Returns the nickname portion of the command prefix.
 boolean isServer()
          Returns true if the prefix is a hostname, false otherwise.
static void removeInstance(java.lang.String prefix)
          Removes an IrcPrefix from the cache.
 java.lang.String toString()
          Returns a representation of the current object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getNickname

public java.lang.String getNickname()
Returns the nickname portion of the command prefix.

Returns:
the nickname, or null if the prefix is a hostname.

getIdentName

public java.lang.String getIdentName()
Returns the username given by the user's ident server.

Returns:
the ident username, or null if the ident name is not included in the prefix.

getHostname

public java.lang.String getHostname()
Returns the hostname portion of the prefix.

Returns:
the hostname, or null if the prefix is a nickname.

isServer

public boolean isServer()
Returns true if the prefix is a hostname, false otherwise.


toString

public java.lang.String toString()
Returns a representation of the current object. The prefix is returned as nickname[[!identName]@hostname] (the brackets indicate a section is optional).


getInstance

public static IrcPrefix getInstance(java.lang.String prefix)
Returns an IrcPrefix representing the passed in string.

Parameters:
prefix - either a single nickname, or full prefix.
Returns:
an IrcPrefix object, if prefix is properly formatter, or null, if the prefix is not valid.

getInstance

public static IrcPrefix getInstance(java.lang.String nickname,
                                    java.lang.String hostname)
Returns an representing the specified nickname and hostname.

Parameters:
nickname - an IRC nickname.
hostname - a hostname.
Throws:
java.lang.IllegalArgumentException - if nickname, or hostname, are null, or blank.

getInstance

public static IrcPrefix getInstance(java.lang.String nickname,
                                    java.lang.String identName,
                                    java.lang.String hostname)
Returns an representing the specified nickname, identName, and hostname.

Parameters:
nickname - an IRC nickname.
identName - a name returned from an ident server.
hostname - a hostname.
Throws:
java.lang.IllegalArgumentException - if nickname, or hostname, are null, or blank.

removeInstance

public static void removeInstance(java.lang.String prefix)
Removes an IrcPrefix from the cache.

Parameters:
prefix - the prefix to remove.


Copyright © 2002-2003 Jack-of-all-trades Programming Services. All Rights Reserved.