public final class ServerUtil extends Object
Class providing static utility methods to help in creating and testing
the ServerModel
.
Modifier and Type | Method and Description |
---|---|
static String |
generateNamesPayload(String owner,
Collection<String> nicks)
Generates a correct payload for a
NAMES response for some
channel given the owner nick for that channel and a collection of all
users on that channel, including the owner. |
static boolean |
isValidNickname(String nick)
Determines if a given nickname is valid (contains 1 or more alphanumeric
characters).
|
static Command |
makeConnect()
Convenience method to generate a
CONNECT Command . |
static Command |
makeCreate(String channelName,
boolean inviteOnly)
Convenience method to generate a
CREATE Command . |
static Command |
makeInvite(String channelName,
String invitee)
Convenience method to generate an
INVITE Command . |
static Command |
makeJoin(String channelName)
Convenience method to generate a
JOIN Command . |
static Command |
makeKick(String channelName,
String target,
String payload)
Convenience method to generate a
KICK Command . |
static Command |
makeLeave(String channelName,
String message)
Convenience method to generate a
LEAVE Command . |
static Command |
makeMesg(String channelName,
String payload)
Convenience method to generate a
MESG Command . |
static Command |
makeNames(String channelName,
String payload)
Convenience method to generate a
NAMES Command . |
static Command |
makeNick(String newNick)
Convenience method to generate a
NICK Command . |
static Command |
makeQuit()
Convenience method to generate a
QUIT Command . |
public static Command makeConnect()
CONNECT
Command
.CONNECT
Command
public static Command makeNick(String newNick)
NICK
Command
.newNick
- the sender's new desired nicknameNICK
Command
with the specified componentpublic static Command makeCreate(String channelName, boolean inviteOnly)
CREATE
Command
.channelName
- the name of the channel to be createdinviteOnly
- true
if the channel should be invite-only, and false
otherwiseCREATE
Command
with the specified
componentspublic static Command makeJoin(String channelName)
JOIN
Command
.channelName
- the name of the channel to be joinedJOIN
Command
with the specified componentpublic static Command makeNames(String channelName, String payload)
NAMES
Command
.channelName
- the name of the channel whose member names were requestedpayload
- the payload representing the names of the channel users. This
should follow the payload format specified in the assignment
instructionsNAMES
Command
with the specified componentspublic static Command makeLeave(String channelName, String message)
LEAVE
Command
.channelName
- the name of the channel to leavemessage
- the (optional) leave messageLEAVE
Command
with the specified componentspublic static Command makeMesg(String channelName, String payload)
MESG
Command
.channelName
- the name of the channel on which to send the messagepayload
- the payload representing the message sent to the channelMESG
Command
with the specified componentspublic static Command makeKick(String channelName, String target, String payload)
KICK
Command
.channelName
- the name of the channel from which to kick the targettarget
- the nick of the user to kickpayload
- the (optional) kick messageKICK
Command
with the specified componentspublic static Command makeInvite(String channelName, String invitee)
INVITE
Command
.channelName
- the name of the channel to which the target is invitedinvitee
- the nick of the user to inviteINVITE
Command
with the specified
componentspublic static Command makeQuit()
QUIT
Command
.QUIT
Command
public static String generateNamesPayload(String owner, Collection<String> nicks)
NAMES
response for some
channel given the owner nick for that channel and a collection of all
users on that channel, including the owner.owner
- the channel owner's nicknicks
- a collection of nicks for users of the channel, including the
ownerNAMES
payload containing the nicks specifiedIllegalArgumentException
- if owner
or nicks
is null
, or of nicks
does not contain owner
public static boolean isValidNickname(String nick)
nick
- the string of the nickname to determine if it is validtrue
if the string is a valid nickname