org.omnaest.utils.structure.collection.list.decorator
Class LockingListDecorator<E>

java.lang.Object
  extended by org.omnaest.utils.structure.collection.list.decorator.ListDecorator<E>
      extended by org.omnaest.utils.structure.collection.list.decorator.LockingListDecorator<E>
Type Parameters:
E -
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>

public class LockingListDecorator<E>
extends ListDecorator<E>

A ListDecorator which uses a given Lock instance to synchronize all of its methods. The iterator() and listIterator() will return a locked Iterator which uses the same Lock instance. The subList(int, int) will return a new locked List with the given Lock, too.

Author:
Omnaest
See Also:
Serialized Form

Field Summary
protected  Lock lock
           
 
Fields inherited from class org.omnaest.utils.structure.collection.list.decorator.ListDecorator
list
 
Constructor Summary
LockingListDecorator(List<E> list)
          Uses a new ReentrantLock instance as Lock
LockingListDecorator(List<E> list, Lock lock)
           
 
Method Summary
 boolean add(E e)
           
 void add(int index, E element)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 E get(int index)
           
 int hashCode()
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 E remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 E set(int index, E element)
           
 int size()
           
 List<E> subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
           
 
Methods inherited from class org.omnaest.utils.structure.collection.list.decorator.ListDecorator
getList, setList
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lock

protected final Lock lock
Constructor Detail

LockingListDecorator

public LockingListDecorator(List<E> list,
                            Lock lock)
Parameters:
list -
lock -
See Also:
LockingListDecorator

LockingListDecorator

public LockingListDecorator(List<E> list)
Uses a new ReentrantLock instance as Lock

Parameters:
list -
See Also:
LockingListDecorator
Method Detail

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Overrides:
size in class ListDecorator<E>
See Also:
List.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface List<E>
Overrides:
isEmpty in class ListDecorator<E>
See Also:
List.isEmpty()

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>
Overrides:
contains in class ListDecorator<E>
See Also:
List.contains(java.lang.Object)

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface List<E>
Overrides:
iterator in class ListDecorator<E>
See Also:
List.iterator()

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class ListDecorator<E>
See Also:
List.toArray()

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class ListDecorator<E>
See Also:
java.util.List#toArray(T[])

add

public boolean add(E e)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class ListDecorator<E>
See Also:
List.add(java.lang.Object)

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class ListDecorator<E>
See Also:
List.remove(java.lang.Object)

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface List<E>
Overrides:
containsAll in class ListDecorator<E>
See Also:
List.containsAll(java.util.Collection)

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ListDecorator<E>
See Also:
List.addAll(java.util.Collection)

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>
Overrides:
removeAll in class ListDecorator<E>
See Also:
List.removeAll(java.util.Collection)

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface List<E>
Overrides:
retainAll in class ListDecorator<E>
See Also:
List.retainAll(java.util.Collection)

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class ListDecorator<E>
See Also:
List.clear()

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Specified by:
equals in interface List<E>
Overrides:
equals in class ListDecorator<E>
See Also:
List.equals(java.lang.Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface List<E>
Overrides:
hashCode in class ListDecorator<E>
See Also:
List.hashCode()

toString

public String toString()
Overrides:
toString in class ListDecorator<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ListDecorator<E>
See Also:
List.addAll(int, java.util.Collection)

get

public E get(int index)
Specified by:
get in interface List<E>
Overrides:
get in class ListDecorator<E>
See Also:
List.get(int)

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>
Overrides:
set in class ListDecorator<E>
See Also:
List.set(int, java.lang.Object)

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>
Overrides:
add in class ListDecorator<E>
See Also:
List.add(int, java.lang.Object)

remove

public E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class ListDecorator<E>
See Also:
List.remove(int)

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<E>
Overrides:
indexOf in class ListDecorator<E>
See Also:
List.indexOf(java.lang.Object)

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<E>
Overrides:
lastIndexOf in class ListDecorator<E>
See Also:
List.lastIndexOf(java.lang.Object)

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>
Overrides:
listIterator in class ListDecorator<E>
See Also:
List.listIterator()

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E>
Overrides:
listIterator in class ListDecorator<E>
See Also:
List.listIterator(int)

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List<E>
Overrides:
subList in class ListDecorator<E>
See Also:
List.subList(int, int)


Copyright © 2013. All Rights Reserved.