org.entityfs.util
Class ManualEntityListable

java.lang.Object
  extended by org.entityfs.lock.AbstractLockable
      extended by org.entityfs.util.ManualEntityListable
All Implemented Interfaces:
Iterable<EntityView>, EntityListable, Lockable, ReadLockable, ReadWriteLockable, WriteLockable

public class ManualEntityListable
extends AbstractLockable
implements EntityListable

This is an EntityListable consisting of manually added entity views. Different views of the same entity may be added.

If an entity that is added to a ManualEntityListable is deleted but not removed from the listable, the listable will continue to return the, now invalid, entity object.

This can optionally be created to be lockable. Locking settings can be inherited from a FileSystem instance or provided manually.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
ManualEntityListable()
          This creates a ManualEntityRepository that does not do any locking.
ManualEntityListable(EntityLockAdapterFactory laf, LockAcquiringStrategy las)
          Create a ManualEntityRepository.
ManualEntityListable(FileSystem fs)
          This creates a ManualEntityRepository that uses the same locking settings as the provided file system.
 
Method Summary
 ManualEntityListable add(EntityView ev)
          Add the entity to the listable.
 ManualEntityListable addAll(Collection<? extends EntityView> c)
          Add a collection of entities to the listable.
 boolean isEmpty()
          Is the listable empty? If a directory view is empty, the viewed directory may still contain entities that are hidden by the view's filter.
 Iterator<EntityView> iterator()
           
 Set<EntityView> listEntities()
          Return all entities that are visible in this directory.
 EntityView remove(EntityView ev)
          Remove the entity from the listable, if it exists here.
 Collection<EntityView> removeAll(Collection<? extends EntityView> c)
          Remove a collection of entities from the listable, if they exist here.
 
Methods inherited from class org.entityfs.lock.AbstractLockable
assertIsReadLocked, assertIsWriteLocked, getLockAcquiringStrategy, getLockAdapter, getLocked, getLogAdapter, getReadLock, getWriteLock, isReadLockedByCurrentThread, isWriteLockedByCurrentThread, lock, lockForReading, lockForWriting, logLockStack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 

Constructor Detail

ManualEntityListable

public ManualEntityListable()
This creates a ManualEntityRepository that does not do any locking.


ManualEntityListable

public ManualEntityListable(FileSystem fs)
This creates a ManualEntityRepository that uses the same locking settings as the provided file system.

Parameters:
fs - The file system to inherit locking settings from.

ManualEntityListable

public ManualEntityListable(EntityLockAdapterFactory laf,
                            LockAcquiringStrategy las)
Create a ManualEntityRepository.

Parameters:
laf - A lock adapter factory.
las - A lock acquiring strategy.
Method Detail

add

public ManualEntityListable add(EntityView ev)
Add the entity to the listable.

Parameters:
ev - The entity to add.
Returns:
this.
Locks_required:
A write lock.

addAll

public ManualEntityListable addAll(Collection<? extends EntityView> c)
Add a collection of entities to the listable.

Parameters:
c - A collection of entities.
Returns:
this.
Locks_required:
A write lock.

remove

public EntityView remove(EntityView ev)
Remove the entity from the listable, if it exists here.

Parameters:
ev - The entity to remove. If this does not exist in the listable, nothing will be removed.
Returns:
The removed entity, if one was removed. If no entity was removed, this method returns null.

removeAll

public Collection<EntityView> removeAll(Collection<? extends EntityView> c)
Remove a collection of entities from the listable, if they exist here.

Parameters:
c - The collection of entities to remove. Only the entities existing in the listable will be removed (duh).
Returns:
A collection of all removed entities.

isEmpty

public boolean isEmpty()
Description copied from interface: EntityListable
Is the listable empty? If a directory view is empty, the viewed directory may still contain entities that are hidden by the view's filter.

Specified by:
isEmpty in interface EntityListable
Returns:
true if the directory view is empty.

iterator

public Iterator<EntityView> iterator()
Specified by:
iterator in interface Iterable<EntityView>

listEntities

public Set<EntityView> listEntities()
Description copied from interface: EntityListable
Return all entities that are visible in this directory. The result is not sorted in any way.

If this is called on a directory view, all returned ViewCapable entities inherit the view's filters.

Specified by:
listEntities in interface EntityListable
Returns:
A Set of entity views. If this is called on a directory entity object, a set of entity objects (not views) are returned. The set may be empty, but never null.