KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > mcast > RespList


1 package org.sapia.ubik.mcast;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6
7 /**
8  * Models a list of <code>Response</code> objects.
9  *
10  * @author Yanick Duchesne
11  * <dl>
12  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
13  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
14  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
15  * </dl>
16  */

17 public class RespList {
18   private List JavaDoc _resps;
19
20   /**
21    * Constructor for RespList.
22    */

23   public RespList(int capacity) {
24     _resps = new ArrayList JavaDoc(capacity);
25   }
26
27   /**
28    * Adds the given response to this instance.
29    *
30    * @param a <code>Response</code> object.
31    */

32   public void addResponse(Response resp) {
33     _resps.add(resp);
34   }
35
36   /**
37    * Returns the <code>Response</code> object at
38    * the given index.
39    *
40    * @param a <code>Response</code> object.
41    */

42   public Response get(int index) {
43     return (Response) _resps.get(index);
44   }
45
46   /**
47    * Returns <code>true</code> if this instance contains a
48    * <code>Response</code> object that represents an error
49    * that occurred on the remote side.
50    *
51    * @return <code>true</code> if this instance contains a
52    * <code>Response</code> object that holds a <code>Throwable</code>
53    */

54   public boolean containsError() {
55     Response r;
56
57     for (int i = 0; i < _resps.size(); i++) {
58       r = (Response) _resps.get(i);
59
60       if (r.isError()) {
61         return true;
62       }
63     }
64
65     return false;
66   }
67
68   /**
69    * Returns <code>true</code> if this instance contains
70    * a <code>Response</code> object whose status is "suspect" -
71    * meaning that the corresponding node is probably down.
72    *
73    * @return <code>true</code> if this instance contains
74    * a <code>Response</code> whose corresponding node is probably
75    * down.
76    */

77   public boolean containsSuspect() {
78     Response r;
79
80     for (int i = 0; i < _resps.size(); i++) {
81       r = (Response) _resps.get(i);
82
83       if (r.isError()) {
84         return true;
85       }
86     }
87
88     return false;
89   }
90
91   /**
92    * Returns the number of responses within this instance.
93    *
94    * @return the number of responses within this instance.
95    */

96   public int count() {
97     return _resps.size();
98   }
99 }
100
Popular Tags