de.infinityloop.util.log
Class NotificationCollector

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by de.infinityloop.util.log.NotificationCollector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class NotificationCollector
extends java.util.ArrayList

A NotificationCollector is used for globally collecting notifications, errors, warnings over the app's run to be able to identify them later in some collected form for evaluation.

Author:
chris
See Also:
Serialized Form

Field Summary
static int DEBUG
           
static int ERROR
           
static int FATAL
           
static int INFO
           
static int WARN
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
NotificationCollector()
          Constructor
 
Method Summary
 void add(int type, int code, java.lang.String message, java.lang.Object[] params, java.lang.Throwable t)
          Add a log message
 void clear()
          Clears all collected notifications.
 int countType(int type)
          Counts the number of messages in this collection of the respective type
 int getCode(int i)
           
 java.lang.Throwable getEmbeddedException(int i)
           
 java.lang.String getMessage(int i)
           
 java.util.ArrayList getNotifications()
          Returns the collected notifications
 int getType(int i)
           
 java.lang.Object getUserRef()
          Retrieves an earlier set user data object
 void setThreshold(int level)
          Sets this notification collector's filter threshold to the specified value.
 void setUserRef(java.lang.Object ref)
          Sets an arbitrary object to e.g. store associated user data
 java.lang.String toString()
          human readable representation of the collected notifications
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

WARN

public static final int WARN
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

FATAL

public static final int FATAL
See Also:
Constant Field Values

DEBUG

public static final int DEBUG
See Also:
Constant Field Values

INFO

public static final int INFO
See Also:
Constant Field Values
Constructor Detail

NotificationCollector

public NotificationCollector()
Constructor

Method Detail

add

public void add(int type,
                int code,
                java.lang.String message,
                java.lang.Object[] params,
                java.lang.Throwable t)
Add a log message

Parameters:
type - one of the constants DEBUG, INFO, WARN, ERROR, FATAL
code - the errorcode
message - the plain text message
t - an associated exception

getNotifications

public java.util.ArrayList getNotifications()
Returns the collected notifications

Returns:
the ArrayList of collected notifications

clear

public void clear()
Clears all collected notifications.

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.ArrayList

setThreshold

public void setThreshold(int level)
Sets this notification collector's filter threshold to the specified value. Messages are recorded when the incoming message has a level greater than or equal to this level.

Parameters:
level - the threshold level

setUserRef

public void setUserRef(java.lang.Object ref)
Sets an arbitrary object to e.g. store associated user data

Parameters:
ref - the object to set

getUserRef

public java.lang.Object getUserRef()
Retrieves an earlier set user data object

Returns:
the object earlier stored

getEmbeddedException

public java.lang.Throwable getEmbeddedException(int i)
                                         throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the embedded exception at index i or null if none was specified
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getCode

public int getCode(int i)
            throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the code at index i
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getMessage

public java.lang.String getMessage(int i)
                            throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the message at index i
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

getType

public int getType(int i)
            throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - index in list of entries
Returns:
the type at index i
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the index is out of bounds

countType

public int countType(int type)
Counts the number of messages in this collection of the respective type

Parameters:
type - one of the types
Returns:
the numebr of entries of this type

toString

public java.lang.String toString()
human readable representation of the collected notifications

Overrides:
toString in class java.util.AbstractCollection