package org.dyndns.fishyu.messenger;
//
public class Channel{
	private String users[] = new String[ 21 ];
	private String contents;
	private boolean open = false;
	private boolean read = true;
	
	private final String s = " ";
	public Channel()
	{
		for (int i = 0; i < users.length; i++ )
		{
			users[ i ] = s;
		}
		
	    contents = "";
    }

	public void setOpen( boolean status )
	{
		open = status;
	}
	
	public void setRead( boolean status )
	{
		read = status;
	}
	
	public void addUser( String newUser )
	{
		for (int i = 0; i < users.length; i++ )
		{
			if ( users[ i ].equals( newUser) ) 
				break;
			else if ( users[ i ].equals( s ) )
			{
			    users[ i ] = newUser;
			    break;
	    	}
	    }
    }
    
    public void delUser( String target )
    {
    	int i;
		for ( i = 0; i < users.length; i++ )
		{
			if ( users[ i ].equals( target ) )
			{
			    users[ i ] = s;
			    break;
	    	}
	    }
	    
	    // trim array
	    for (int j = i + 1; j < users.length; i++, j++ )
		{ 
	        users[ i ] = users [ j ];
	    }
	     
	 }
    	
	
	public void appendContents( String append )
	{
		contents += append + "\n";
	}
	
		public void clearContents()
	{
		contents = "";
	}
		
	public String getUsers( int NO )
	{
		return users[ NO ];
	}
	
	public String getContents()
	{
		return contents;
	}
	
	public boolean isOpen()
	{
		return open;
	}
	
	public boolean isRead()
	{
		return read;
	}
	
	public void setEmpty()
	{
		for( int i = 0; i < users.length; i++ )
		    users[ i ] = s;
    }	  
	
}