package heufybot.core;

import java.util.HashMap;
import java.util.Set;

public class Channel
{
	private String name;
	private String modes;
	private HashMap<User, String> usersInChannel;
	
	public Channel(String name)
	{
		this.name = name;
	}
	
	public String getName()
	{
		return name;
	}
	
	public String getModes()
	{
		return modes;
	}
	
	public void parseModeChange(String modeChange)
	{
		if(modeChange.startsWith("+"))
		{
			modes += modeChange.substring(1);
		}
		else
		{
			char[] changedModes = modeChange.substring(1).toCharArray();
			for(int i = 0; i < changedModes.length; i++)
			{
				modes.replaceFirst("" + changedModes[i], "");
			}
		}
	}
	
	public void parseModeChangeOnUser(User user, String modeChange)
	{
		String modesOnUser = usersInChannel.get(user);
		
		if(modeChange.startsWith("+"))
		{
			modesOnUser += modeChange.substring(1);
		}
		else
		{	
			char[] changedModes = modeChange.substring(1).toCharArray();
			for(int i = 0; i < changedModes.length; i++)
			{
				modesOnUser.replaceFirst("" + changedModes[i], "");
			}
		}
		
		usersInChannel.put(user, modesOnUser);
	}
	
	public void addUser(User user, String modes)
	{
		usersInChannel.put(user, modes);
	}
	
	public void removeUser(User user)
	{
		usersInChannel.remove(user);
	}
	
	public String getModesOnUser(User user)
	{
		return usersInChannel.get(user);
	}
	
	public User[] getUsers()
	{
		Set<User> userSet = usersInChannel.keySet();
		User[] userArray = new User[userSet.size()];
		return userSet.toArray(userArray);
	}
	
	public User getUser(String nickname)
	{
		for(User user : usersInChannel.keySet())
		{
			if(user.getNickname().equalsIgnoreCase(nickname))
			{
				return user;
			}
		}
		return null;
	}
}
@@ -181,16 +181,101 @@
 hannel;%0A
+%09private String topic;%0A%09private String topicSetter;%0A%09private long topicSetTimestamp;%0A
 %09%0A%09publi
@@ -419,24 +419,90 @@
 modes;%0A%09%7D%0A%09%0A
+%09public void setModes(String modes)%0A%09%7B%0A%09%09this.modes = modes;%0A%09%7D%0A%09%0A
 %09public void
@@ -1858,10 +1858,461 @@
 null;%0A%09%7D
+%0A%0A%09public String getTopic()%0A%09%7B%0A%09%09return topic;%0A%09%7D%0A%0A%09public void setTopic(String topic) %0A%09%7B%0A%09%09this.topic = topic;%0A%09%7D%0A%0A%09public String getTopicSetter() %0A%09%7B%0A%09%09return topicSetter;%0A%09%7D%0A%0A%09public void setTopicSetter(String topicSetter) %0A%09%7B%0A%09%09this.topicSetter = topicSetter;%0A%09%7D%0A%0A%09public long getTopicSetTimestamp() %0A%09%7B%0A%09%09return topicSetTimestamp;%0A%09%7D%0A%0A%09public void setTopicSetTimestamp(long topicSetTimestamp) %0A%09%7B%0A%09%09this.topicSetTimestamp = topicSetTimestamp;%0A%09%7D
 %0A%7D

Add topic stuff to Channel