org.ws4d.java.structures
Class LockedStructure

java.lang.Object
  extended by org.ws4d.java.structures.DataStructure
      extended by org.ws4d.java.structures.LockedStructure
All Implemented Interfaces:
Lockable

public class LockedStructure
extends DataStructure
implements Lockable

Class encapsulates data structure, method invocations are synchronized by a Lockable object.


Constructor Summary
LockedStructure(DataStructure data)
          Constructor.
LockedStructure(DataStructure data, Lockable lock)
          Constructor.
 
Method Summary
 boolean add(java.lang.Object obj)
          Adds a new object to this data structure.
 boolean addAll(DataStructure data)
          Adds all objects contained within data to this instance.
 void clear()
          Clears this data structure by removing all content from it.
 boolean contains(java.lang.Object obj)
          Checks whether obj (or another instance equal to obj in terms of java.lang.Object.equals(Object) ) is already present within this data structure instance and returns true only if this is the case.
 boolean containsAll(DataStructure data)
          Checks whether all items within data are present within this data structure instance and returns true only if this is the case.
 boolean equals(java.lang.Object o)
           
 void exclusiveLock()
          Acquires an exclusive lock.
 int hashCode()
           
 boolean isEmpty()
          Checks whether this instance is empty or not.
 Iterator iterator()
          Manual synchronization of iterator necessary.
 boolean releaseExclusiveLock()
          Releases an exclusive lock of the current thread.
 void releaseSharedLock()
          Releases a shared lock of the current thread.
 boolean remove(java.lang.Object obj)
          Removes obj from this data structure.
 void sharedLock()
          Acquires a shared lock.
 int size()
          Returns the current size of the data structure.
 java.lang.Object[] toArray()
          Returns an array containing all items stored within this data structure.
 java.lang.Object[] toArray(java.lang.Object[] object)
          Stores all contained items into the passed-in array objects.
 java.lang.String toString()
           
 boolean tryExclusiveLock()
          Try to get an exclusive lock immediately.
 boolean trySharedLock()
          Tries to get a shared lock immediately.
 
Methods inherited from class org.ws4d.java.structures.DataStructure
getClassShortName
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockedStructure

public LockedStructure(DataStructure data,
                       Lockable lock)
Constructor.

Parameters:
data - data structure which will be encapsulated by this.
lock - Lock for access synchronization.

LockedStructure

public LockedStructure(DataStructure data)
Constructor.

Parameters:
data - data structure which will be encapsulated by this.
Method Detail

sharedLock

public void sharedLock()
Description copied from interface: Lockable
Acquires a shared lock. If the lock cannot be allocated immediately, the thread is blocked until allocation is possible.

Specified by:
sharedLock in interface Lockable

exclusiveLock

public void exclusiveLock()
Description copied from interface: Lockable
Acquires an exclusive lock. If the lock cannot be allocated immediately, the thread is blocked until allocation is possible.

Specified by:
exclusiveLock in interface Lockable

releaseSharedLock

public void releaseSharedLock()
Description copied from interface: Lockable
Releases a shared lock of the current thread.

Specified by:
releaseSharedLock in interface Lockable

releaseExclusiveLock

public boolean releaseExclusiveLock()
Description copied from interface: Lockable
Releases an exclusive lock of the current thread.

Specified by:
releaseExclusiveLock in interface Lockable
Returns:
true = if last exclusive lock of this thread is released.

tryExclusiveLock

public boolean tryExclusiveLock()
Description copied from interface: Lockable
Try to get an exclusive lock immediately.

Specified by:
tryExclusiveLock in interface Lockable
Returns:
true if the lock has been allocated, false otherwise

trySharedLock

public boolean trySharedLock()
Description copied from interface: Lockable
Tries to get a shared lock immediately.

Specified by:
trySharedLock in interface Lockable
Returns:
true if the lock has been allocated, false otherwise

iterator

public Iterator iterator()
Manual synchronization of iterator necessary.

Specified by:
iterator in class DataStructure
Returns:
an iterator over all stored objects

size

public int size()
Description copied from class: DataStructure
Returns the current size of the data structure.

Specified by:
size in class DataStructure
Returns:
the size of this data structure

contains

public boolean contains(java.lang.Object obj)
Description copied from class: DataStructure
Checks whether obj (or another instance equal to obj in terms of java.lang.Object.equals(Object) ) is already present within this data structure instance and returns true only if this is the case.

Overrides:
contains in class DataStructure
Parameters:
obj - the object to check the presence of
Returns:
true if obj is contained by this instance, false if not

remove

public boolean remove(java.lang.Object obj)
Description copied from class: DataStructure
Removes obj from this data structure. Returns true if obj was actually present and thus it was really removed (i.e. this instance was modified by the method call).

Overrides:
remove in class DataStructure
Parameters:
obj - the object to remove
Returns:
true only if obj was actually removed

clear

public void clear()
Description copied from class: DataStructure
Clears this data structure by removing all content from it.

Overrides:
clear in class DataStructure

add

public boolean add(java.lang.Object obj)
Description copied from class: DataStructure
Adds a new object to this data structure.

Overrides:
add in class DataStructure
Parameters:
obj - the object to add
Returns:
true if the object was actually added, false in any other case (e.g. adding an object to a set which already contains the same object in terms of java.lang.Object.equals(Object))

addAll

public boolean addAll(DataStructure data)
Description copied from class: DataStructure
Adds all objects contained within data to this instance.

Overrides:
addAll in class DataStructure
Parameters:
data - the objects to add
Returns:
true if at least one object from data was actually added, i.e. a modification was made to this instance, false in any other case (e.g. adding objects to a set which already contains them in terms of java.lang.Object.equals(Object))

containsAll

public boolean containsAll(DataStructure data)
Description copied from class: DataStructure
Checks whether all items within data are present within this data structure instance and returns true only if this is the case.

Overrides:
containsAll in class DataStructure
Parameters:
data - the items to check the presence of
Returns:
true if all objects within data are contained by this instance, false if at least one of them is not

isEmpty

public boolean isEmpty()
Description copied from class: DataStructure
Checks whether this instance is empty or not.

Overrides:
isEmpty in class DataStructure
Returns:
true if this data structure is empty, false otherwise

toArray

public java.lang.Object[] toArray()
Description copied from class: DataStructure
Returns an array containing all items stored within this data structure. The array will be of length DataStructure.size(), i.e. for an empty data structure an array of length zero is returned (rather than null).

Overrides:
toArray in class DataStructure
Returns:
an array of all objects contained within this data structure instance; this method never returns null

toArray

public java.lang.Object[] toArray(java.lang.Object[] object)
Description copied from class: DataStructure
Stores all contained items into the passed-in array objects. Returns the same array.

The array is expected not to be null and to be of exactly DataStructure.size() length. Otherwise, either a java.lang.NullPointerException or an java.lang.IllegalArgumentException will be thrown.

Overrides:
toArray in class DataStructure
Parameters:
object - the array to store this data structure's content to
Returns:
the same array as the one passed in (objects), however after having been filled with all objects contained within this data structure instance

hashCode

public int hashCode()
Overrides:
hashCode in class DataStructure

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class DataStructure