com.objectplanet.survey.event
Class ListenerArrayList

java.lang.Object
  extended by com.objectplanet.survey.event.ListenerArrayList

public class ListenerArrayList
extends java.lang.Object

A wrapper for ArrayList that provides synchronized access, with high performance toArray(). The list is tailor made for listener lists. The first get method call after a set() or add() call will have poor performance, because an array will be copied from the arrayList. When looping through the list, it is recommended to use toArray[]. This is very fast, since it will use a pre-created array (which is a copy of the list). This will not be affected by changes in the ArrayList while looping through it, because it is a copy of the ArrayList. This class only has a small subset of the methods in java.util.Arraylist

Author:
Torgeir Lund
Created:
November 24 2005

Constructor Summary
ListenerArrayList()
          Creates an empty SynchronizedArrayList, with default capacity as in java.util.ArrayList
 
Method Summary
 void add(int index, java.lang.Object object)
          Adds an element at the specified position in the list
 void add(java.lang.Object object)
          Adds an element at the end of the list
 void ensureListSize(int size)
          Make sure the list is at least the specified size.
 java.lang.Object get(int index)
          Gets an object in the list, at the specified position
 void remove(java.lang.Object object)
          Removes an item from the list
 void set(int index, java.lang.Object object)
          Set an element in the list at the specified index.
 int size()
          Gets the size of the list
 void sort()
          Sorts the arraylist.
 IEventListener[] toArray()
          Gets an array with all objects in the list.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerArrayList

public ListenerArrayList()
Creates an empty SynchronizedArrayList, with default capacity as in java.util.ArrayList

Method Detail

get

public java.lang.Object get(int index)
Gets an object in the list, at the specified position

Parameters:
index - The position of the object to retrieve
Returns:
The object to retrieve

add

public void add(java.lang.Object object)
Adds an element at the end of the list

Parameters:
object - The element to add

add

public void add(int index,
                java.lang.Object object)
Adds an element at the specified position in the list

Parameters:
object - The element to add

set

public void set(int index,
                java.lang.Object object)
Set an element in the list at the specified index.

Parameters:
index - The position of the object to set
object - The object to set at the specified position

size

public int size()
Gets the size of the list

Returns:
The size

toArray

public IEventListener[] toArray()
Gets an array with all objects in the list. The array is a copy of the List, so it is safe to use in a multithreaded environment.

Returns:
The list of objects as an array

ensureListSize

public void ensureListSize(int size)
Make sure the list is at least the specified size. If it needs to be expanded, insert null values in the new range.

Parameters:
size - The list will be set to this size if it is not at least this size already.

remove

public void remove(java.lang.Object object)
Removes an item from the list

Parameters:
object - The object to remove

sort

public void sort()
Sorts the arraylist. Requires that all items in the list impelements the Comparable interface.


Copyright ? ObjectPlanet Inc. All Rights Reserved.

Built on December 20 2016