1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Channel now inherits from Conversation

This commit is contained in:
Sebastian Kaspari 2010-03-10 09:32:20 +01:00
parent 64c7ad2f45
commit 1c128cc682
2 changed files with 112 additions and 70 deletions

View File

@ -20,21 +20,14 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.model;
import java.util.LinkedList;
/**
* An IRC channel
* An IRC channel (extends Conversation)
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class Channel
public class Channel extends Conversation
{
private static final int BUFFER_SIZE = 30;
private String name;
private String topic;
private LinkedList<Message> buffer = new LinkedList<Message>();
private LinkedList<Message> history = new LinkedList<Message>();
/**
* Create a new channel object
@ -43,69 +36,10 @@ public class Channel
*/
public Channel(String name)
{
this.name = name;
super(name);
this.topic = "";
}
/**
* Get name of channel
*/
public String getName()
{
return name;
}
/**
* Add a message to the channel
*/
public void addMessage(Message message)
{
buffer.addFirst(message);
history.addLast(message);
if (history.size() > BUFFER_SIZE) {
history.removeFirst();
}
}
/**
* Get channel history
*
* @return
*/
public LinkedList<Message> getHistory()
{
return history;
}
/**
* Get last buffered message
*
* @return
*/
public Message pollBufferedMessage()
{
Message message = buffer.getLast();
buffer.removeLast();
return message;
}
/**
* Does the channel have buffered messages?
*/
public boolean hasBufferedMessages()
{
return buffer.size() > 0;
}
/**
* Clear the message buffer
*/
public void clearBuffer()
{
buffer.clear();
}
/**
* Set the channel's topic
*

View File

@ -0,0 +1,108 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009 Sebastian Kaspari
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.model;
import java.util.LinkedList;
/**
* Base class for conversations
*
* A conversation can be a channel, a query or server messages
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public abstract class Conversation
{
private static final int HISTORY_SIZE = 30;
private LinkedList<Message> buffer = new LinkedList<Message>();
private LinkedList<Message> history = new LinkedList<Message>();
private String name;
/**
* Create a new conversation with the given name
*
* @param name The name of the conversation (channel, user)
*/
public Conversation(String name)
{
this.name = name;
}
/**
* Get name of the conversation (channel, user)
*/
public String getName()
{
return name;
}
/**
* Add a message to the channel
*/
public void addMessage(Message message)
{
buffer.addFirst(message);
history.addLast(message);
if (history.size() > HISTORY_SIZE) {
history.removeFirst();
}
}
/**
* Get channel history
*
* @return
*/
public LinkedList<Message> getHistory()
{
return history;
}
/**
* Get last buffered message
*
* @return
*/
public Message pollBufferedMessage()
{
Message message = buffer.getLast();
buffer.removeLast();
return message;
}
/**
* Does the channel have buffered messages?
*/
public boolean hasBufferedMessages()
{
return buffer.size() > 0;
}
/**
* Clear the message buffer
*/
public void clearBuffer()
{
buffer.clear();
}
}