Package adams.multiprocess
Class JobList<T extends Job>
- java.lang.Object
-
- adams.multiprocess.JobList<T>
-
- Type Parameters:
T
- the type of job to use
- All Implemented Interfaces:
CleanUpHandler
,JobCompleteListener
,Serializable
,Iterable<T>
,Collection<T>
,List<T>
public class JobList<T extends Job> extends Object implements List<T>, JobCompleteListener, CleanUpHandler
A container for jobs to execute. A listener can be added which listens for all jobs to be finished.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_Finished
indicates whether all jobs have finished.protected List<T>
m_Jobs
the jobs.protected HashSet<JobListCompleteListener>
m_Listeners
the listeners listening for all jobs to be completed.protected boolean
m_Locked
indicates whether a queue has been added to a JobRunner and can no longer be modified.
-
Constructor Summary
Constructors Constructor Description JobList()
Initializes the queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, T element)
Inserts the specified element at the specified position in this list.boolean
add(T e)
Ensures that this collection contains the specified element.boolean
addAll(int index, Collection<? extends T> c)
Inserts all of the elements in the specified collection into this list at the specified position.boolean
addAll(Collection<? extends T> c)
Adds all the elements in the specified collection to this collection.void
addJobListCompleteListener(JobListCompleteListener l)
Adds the listener to the internal list.void
cleanUp()
Cleans up data structures, frees up memory.void
clear()
Removes all the elements from this collection.boolean
contains(Object o)
Returns true if this collection contains the specified element.boolean
containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.boolean
equals(Object obj)
Compares the specified object with this collection for equality.T
get(int index)
Returns the element at the specified position in this list.int
hashCode()
Returns the hash code value for this collection (just the hash code of the underlying job vector).int
indexOf(Object o)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.boolean
isEmpty()
Returns true if this collection contains no elements.boolean
isFinished()
Returns whether all jobs in the list have been finished.boolean
isLocked()
Returns whether the queue has been locked due to being processed in a JobRunner or not.Iterator<T>
iterator()
Returns an iterator over the elements in this collection.void
jobCompleted(JobCompleteEvent e)
Post process job.int
lastIndexOf(Object o)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.ListIterator<T>
listIterator()
Returns a list iterator of the elements in this list (in proper sequence).ListIterator<T>
listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.protected void
notifyJobListCompleteListeners(JobListCompleteEvent e)
Notifies all JobListComplete listeners.T
remove(int index)
Removes the element at the specified position in this list.boolean
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present.boolean
removeAll(Collection<?> c)
Removes all this collection's elements that are also contained in the specified collection.void
removeJobListCompleteListener(JobListCompleteListener l)
Removes the listener from the internal list.boolean
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection.T
set(int index, T element)
Replaces the element at the specified position in this list with the specified element.int
size()
Returns the number of elements in this collection.List<T>
subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.Object[]
toArray()
Returns an array containing all of the elements in this collection.<T> T[]
toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Field Detail
-
m_Listeners
protected HashSet<JobListCompleteListener> m_Listeners
the listeners listening for all jobs to be completed.
-
m_Locked
protected boolean m_Locked
indicates whether a queue has been added to a JobRunner and can no longer be modified.
-
m_Finished
protected boolean m_Finished
indicates whether all jobs have finished.
-
-
Method Detail
-
add
public boolean add(T e)
Ensures that this collection contains the specified element.
-
addAll
public boolean addAll(Collection<? extends T> c)
Adds all the elements in the specified collection to this collection.
-
add
public void add(int index, T element)
Inserts the specified element at the specified position in this list.
-
addAll
public boolean addAll(int index, Collection<? extends T> c)
Inserts all of the elements in the specified collection into this list at the specified position.
-
clear
public void clear()
Removes all the elements from this collection.
-
contains
public boolean contains(Object o)
Returns true if this collection contains the specified element.
-
containsAll
public boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAll
in interfaceCollection<T extends Job>
- Specified by:
containsAll
in interfaceList<T extends Job>
- Parameters:
c
- the collection to check against- Returns:
- true if all elements are also in this collection
-
equals
public boolean equals(Object obj)
Compares the specified object with this collection for equality.
-
hashCode
public int hashCode()
Returns the hash code value for this collection (just the hash code of the underlying job vector).
-
get
public T get(int index)
Returns the element at the specified position in this list.
-
indexOf
public int indexOf(Object o)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
-
isEmpty
public boolean isEmpty()
Returns true if this collection contains no elements.
-
lastIndexOf
public int lastIndexOf(Object o)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.- Specified by:
lastIndexOf
in interfaceList<T extends Job>
- Parameters:
o
- the job to look for- Returns:
- the index or -1 if not found
-
listIterator
public ListIterator<T> listIterator()
Returns a list iterator of the elements in this list (in proper sequence).- Specified by:
listIterator
in interfaceList<T extends Job>
- Returns:
- the iterator
-
listIterator
public ListIterator<T> listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.- Specified by:
listIterator
in interfaceList<T extends Job>
- Parameters:
index
- the index to start the iterator- Returns:
- the iterator
-
remove
public boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present.
-
remove
public T remove(int index)
Removes the element at the specified position in this list.
-
removeAll
public boolean removeAll(Collection<?> c)
Removes all this collection's elements that are also contained in the specified collection.
-
retainAll
public boolean retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection.
-
set
public T set(int index, T element)
Replaces the element at the specified position in this list with the specified element.
-
subList
public List<T> subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
-
size
public int size()
Returns the number of elements in this collection.
-
toArray
public Object[] toArray()
Returns an array containing all of the elements in this collection.
-
toArray
public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
-
isLocked
public boolean isLocked()
Returns whether the queue has been locked due to being processed in a JobRunner or not.- Returns:
- true if queue is being processed and therefore locked
-
addJobListCompleteListener
public void addJobListCompleteListener(JobListCompleteListener l)
Adds the listener to the internal list.- Parameters:
l
- the listener to add
-
removeJobListCompleteListener
public void removeJobListCompleteListener(JobListCompleteListener l)
Removes the listener from the internal list.- Parameters:
l
- the listener to remove
-
notifyJobListCompleteListeners
protected void notifyJobListCompleteListeners(JobListCompleteEvent e)
Notifies all JobListComplete listeners.- Parameters:
e
- the event to send
-
isFinished
public boolean isFinished()
Returns whether all jobs in the list have been finished.- Returns:
- true if all jobs have finished
-
jobCompleted
public void jobCompleted(JobCompleteEvent e)
Post process job. If all jobs got completed, the list of JobListCompleteListener will be notified.- Specified by:
jobCompleted
in interfaceJobCompleteListener
- Parameters:
e
- the event
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
-
-