3 import java.util.ArrayList;
6 * Class which contains and manages a messages list.
7 * @author Sébastien Miquée
10 public class MessageList
12 /** Local variables **/
13 private ArrayList<Message> tab[] ;
17 * Empty constructor for stub generation.
25 * @param nb : size of the list.
27 @SuppressWarnings( "unchecked" )
28 public MessageList( Integer nb )
30 taille = nb.intValue() ;
32 tab = new ArrayList[ taille ] ;
33 for( int i = 0 ; i < taille ; i++ )
35 tab[i] = new ArrayList<Message>() ;
40 * Search and returns, if it exists, a Message in the list _noList
41 * with the tag _tag. Returns null if there is no Message.
42 * @param _noList : index of the list.
43 * @param _tag : the tag of the Message.
44 * @return : the Message.
46 public synchronized Message searchMsg( int _noList, int _tag )
48 if( _noList >= 0 && _noList < taille )
50 int pos = searchPos( _noList, _tag ) ;
54 return tab[ _noList ].remove( pos ) ;
62 * Add a Message _mes in the list of index _noList.
63 * @param _noList : index of the list.
64 * @param _mes : Message to add.
66 public synchronized void addMessage( int _noList, Message _mes )
68 if( _noList >= 0 && _noList < taille )
70 int _t = _mes.getTag() ;
71 /** Search if message exists **/
72 int pos = searchPos( _noList, _t ) ;
76 tab[ _noList ].set( pos, _mes ) ;
78 /** Add the message **/
79 tab[ _noList ].add( _mes ) ;
86 * Search the position of a Message with a specific tag _tag.
87 * If it doesn't exist, -1 will be returned.
88 * @param id : index of the sender.
89 * @param tag : tag of the Message.
90 * @return : the position in the list.
92 private int searchPos( int _id, int _tag )
94 int t = tab[ _id ].size() ;
96 for( int i = 0 ; i < t ; i++ )
99 if( tab[ _id ].get( i ).getTag() == _tag )
103 } catch( Exception e ) {
112 /** La programmation est un art, respectons ceux qui la pratiquent !! **/