summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/commands/NamesCommand.java
blob: 6f0a9ed5dabd3742802ad75b5c71c22d655601a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package f00f.net.irc.martyr.commands;

import f00f.net.irc.martyr.OutCommand;

import java.util.List;
import java.util.ArrayList;

/**
 * Defines the NAMES command, which is used to get the members of certain channels, or all of them.
 *
 * @author Daniel Henninger
 */
public class NamesCommand implements OutCommand
{

    /* List of channels we will request membership of. */
    List<String> channels = new ArrayList<String>();

    /**
     * No parameter passed to the NAMES command represents a request for all channels.
     */
    public NamesCommand()
    {
        // Nothing to do
    }

    /**
     * Request the membership of a single channel.
     *
     * @param channel Channel you want to request membership of.
     */
    public NamesCommand(String channel)
    {
        this.channels.add(channel);
    }

    /**
     * Request the membership of multiple channels.
     *
     * @param channels List of channels you want to retrieve the membership list of.
     */
    public NamesCommand(List<String> channels)
    {
        this.channels.addAll(channels);
    }

    /**
     * @see f00f.net.irc.martyr.OutCommand#render()
     */
    public String render()
    {
        String ret = getIrcIdentifier();
        if (channels.size() > 0) {
            ret = ret + " ";
            Boolean isFirst = true;
            for (String channel : channels) {
                if (isFirst) {
                    ret = ret + channel;
                    isFirst = false;
                }
                else {
                    ret = ret + "," + channel;
                }
            }
        }
        return ret;
    }

    /**
     * @see f00f.net.irc.martyr.Command#getIrcIdentifier()
     */
    public String getIrcIdentifier()
    {
        return "NAMES";
    }

}