net.sourceforge.domian.repository
Class HashSetRepository<T extends Entity>

java.lang.Object
  extended by net.sourceforge.domian.repository.AbstractRepository<T>
      extended by net.sourceforge.domian.repository.AbstractDomianCoreRepository<T>
          extended by net.sourceforge.domian.repository.HashSetRepository<T>
All Implemented Interfaces:
Repository<T>, VolatileRepository<T>

public class HashSetRepository<T extends Entity>
extends AbstractDomianCoreRepository<T>
implements VolatileRepository<T>

Volatile repository for non-concurrent environments.

This repository is suitable for standalone single-threaded applications with no need for persistent objects, e.g. testing.

Another usage example is local selection/projection of a set of objects using a specification. To be able to use the specification, just create a HashSetRepository, populate it with the objects to select from using the putAll(Collection) method, and then invoke the findAllEntitiesSpecifiedBy(Specification) method. Indeed, there is a convenience constructor made for this particular use case.

This repository is backed by an unsynchronized HashSet. (Another way of putting it is that this class is just a Repository-wrapped Collection, or a Specification-activated Collection...)

Resource usage 
StoringO(1)
CountingO(N)
FindingO(N)
RemovingO(N)

Since:
0.4
Author:
Eirik Torske

Nested Class Summary
protected static class HashSetRepository.HashSetRepositoryIterator<V extends Entity,T extends Entity>
          Inner iterator class for HashSetRepository.
 
Field Summary
protected  java.util.Set<T> db
           
 
Fields inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
DEFAULT_DOMIAN_ROOT_DIR_NAME, DEFAULT_DOMIAN_ROOT_PATH, log, synchronizer
 
Fields inherited from class net.sourceforge.domian.repository.AbstractRepository
supportsRecursiveIndexing, usesNativePartitioningSupport
 
Constructor Summary
HashSetRepository()
           
HashSetRepository(java.util.Collection<T> initialEntities)
          Convenient constructor for the specifications-based-compact-sorting use case.
 
Method Summary
 java.lang.Long countAllEntities()
          Extra method

Counts all entities in repository rather fast.

<V extends T>
java.util.Collection<V>
findAllEntitiesSpecifiedBy(Specification<V> specification)
           
<V extends T>
java.util.Iterator<V>
iterateAllEntitiesSpecifiedBy(Specification<V> specification)
           
<V extends T>
void
put(V entity)
           
 void putAll(java.util.Collection<? extends T> collectionOfEntities)
           
<V extends T>
java.lang.Boolean
remove(V entity)
           
 void removeAllEntities()
          Extra method

Purges all entities in repository without no further ado.

<V extends T>
java.lang.Long
removeAllEntitiesSpecifiedBy(Specification<V> specification)
           
<V extends T>
void
update(V entity)
           
 
Methods inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
createUniqueSpecificationFor, getSynchronizer, makePartition, onMakePartition, setSynchronizer
 
Methods inherited from class net.sourceforge.domian.repository.AbstractRepository
contains, count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findSingle, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, iterate, iterateAll, remove, removeAll, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.domian.repository.Repository
count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findSingle, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, iterate, iterateAll, makePartition, remove, removeAll, update
 

Field Detail

db

protected java.util.Set<T extends Entity> db
Constructor Detail

HashSetRepository

public HashSetRepository()

HashSetRepository

public HashSetRepository(java.util.Collection<T> initialEntities)
Convenient constructor for the specifications-based-compact-sorting use case.

Method Detail

countAllEntities

public java.lang.Long countAllEntities()
Extra method

Counts all entities in repository rather fast.


iterateAllEntitiesSpecifiedBy

public <V extends T> java.util.Iterator<V> iterateAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
iterateAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

findAllEntitiesSpecifiedBy

public <V extends T> java.util.Collection<V> findAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
findAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

put

public <V extends T> void put(V entity)
Specified by:
put in interface Repository<T extends Entity>

putAll

public void putAll(java.util.Collection<? extends T> collectionOfEntities)
Specified by:
putAll in interface Repository<T extends Entity>
Overrides:
putAll in class AbstractRepository<T extends Entity>

update

public <V extends T> void update(V entity)
Specified by:
update in interface Repository<T extends Entity>

removeAllEntitiesSpecifiedBy

public <V extends T> java.lang.Long removeAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
removeAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

removeAllEntities

public void removeAllEntities()
Extra method

Purges all entities in repository without no further ado.


remove

public <V extends T> java.lang.Boolean remove(V entity)
Specified by:
remove in interface Repository<T extends Entity>


Copyright © 2006-2010. All Rights Reserved.