01: /*
02: * $Id: CallExceptionList.java,v 1.21 2007/05/21 08:34:42 agoubard Exp $
03: *
04: * Copyright 2003-2007 Orange Nederland Breedband B.V.
05: * See the COPYRIGHT file for redistribution and use restrictions.
06: */
07: package org.xins.common.service;
08:
09: import java.util.ArrayList;
10: import java.util.List;
11:
12: /**
13: * List of call exceptions. See class {@link CallException}.
14: *
15: * @version $Revision: 1.21 $ $Date: 2007/05/21 08:34:42 $
16: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
17: *
18: * @since XINS 1.0.0
19: */
20: public final class CallExceptionList {
21:
22: /**
23: * The underlying collection to store the <code>CallException</code>
24: * objects in.
25: */
26: private final List _exceptions;
27:
28: /**
29: * Constructs a new <code>CallExceptionList</code> object.
30: */
31: public CallExceptionList() {
32:
33: _exceptions = new ArrayList();
34: }
35:
36: /**
37: * Adds a <code>CallException</code> to this list.
38: *
39: * @param exception
40: * the {@link CallException} to add, cannot be <code>null</code>.
41: */
42: void add(CallException exception) {
43: _exceptions.add(exception);
44: }
45:
46: /**
47: * Counts the number of elements.
48: *
49: * @return
50: * the number of {@link CallException}s, always >= 0.
51: */
52: public int size() {
53: return (_exceptions == null) ? 0 : _exceptions.size();
54: }
55:
56: /**
57: * Retrieves a <code>CallException</code> by index.
58: *
59: * @param index
60: * the element index, must be >= 0 and < {@link #size()}.
61: *
62: * @return
63: * the {@link CallException} element at the specified index, never
64: * <code>null</code>.
65: *
66: * @throws IndexOutOfBoundsException
67: * if <code>index < 0 || index >= {@link #size()}</code>.
68: */
69: public CallException get(int index)
70: throws IndexOutOfBoundsException {
71: return (CallException) _exceptions.get(index);
72: }
73:
74: /**
75: * Retrieves the last (most recent) <code>CallException</code>.
76: *
77: * @return
78: * the {@link CallException} element at the highest index, or
79: * <code>null</code> if this list is empty.
80: *
81: * @since XINS 1.1.0
82: */
83: public CallException last() {
84: if (size() == 0) {
85: return null;
86: } else {
87: return get(size() - 1);
88: }
89: }
90: }
|