2012-03-05 7 views
0

私はNotificationEventのインスタンスを持っています。このインスタンスが作成されるたびにキューにこのインスタンスを追加しました。キューの名前はNotificationQueueでなければなりません。 NotificationEventのjavaBeansでキューを実装する方法

構造は、このようなものです:

public class NotificationEvent { 

    private String sender; 
    private String receiver; 
    private String message; 

    /** 
    * @return the sender 
    */ 
    public String getSender() { 
     return sender; 
    } 

    /** 
    * @param sender the sender to set 
    */ 
    public void setSender(String sender) { 
     this.sender = sender; 
    } 

    /** 
    * @return the receiver 
    */ 
    public String getReceiver() { 
     return receiver; 
    } 

    /** 
    * @param receiver the receiver to set 
    */ 
    public void setReceiver(String receiver) { 
     this.receiver = receiver; 
    } 

    /** 
    * @return the message 
    */ 
    public String getMessage() { 
     return message; 
    } 

    /** 
    * @param message the message to set 
    */ 
    public void setMessage(String message) { 
     this.message = message; 
    } 

NotificationQueueのに必要な構造がどうあるべきか?

答えて

0

私は再び車輪を再発明しないことをお勧めします。すでにJava実行時ライブラリにあるインタフェースQueueは、キューが持つべき操作を定義します。ここにはbrief tutorial for the Queue interfaceQueue JavaDocがあります。まあ、こちらもexample of using Queue implementationsです。

あなたは、このような通知キューオブジェクトを作成することができます:あなたはキューのために、独自の型を有することを主張場合

Queue<NotificationEvent> eventQueue = new LinkedList<NotificationEvent>; 

かを、:

public class extends LinkedList<NotificationEvent> { 
    /** 
    * Constructs an empty list. 
    */ 
    public NotificationQueue() { 
    } 

    /** 
    * Constructs a list containing the elements of the specified collection, 
    * in the order they are returned by the 
    * collection's iterator. 
    * @param c the collection whose elements are to be placed into this list 
    * @throws NullPointerException if the specified collection is null 
    */ 
    public NotificationQueue(Collection<? extends NotificationEvent> c) { 
     super(c); 
    } 
} 

... 

NotificationQueue eventQueue == new NotificationQueue(); 

注:
LinkedListではありませんQueueインタフェースの使用可能な実装のみ。Java実行時ライブラリで既に使用可能な他の実装についてはQueue JavaDocを参照してください。もちろん、独自のQueueインターフェイスの実装を記述することもできます。

関連する問題