com.jdroid.java.repository
Class InMemoryRepository<T extends Identifiable>

java.lang.Object
  extended by com.jdroid.java.repository.InMemoryRepository<T>
Type Parameters:
T -
All Implemented Interfaces:
Repository<T>

public class InMemoryRepository<T extends Identifiable>
extends Object
implements Repository<T>


Constructor Summary
InMemoryRepository()
           
 
Method Summary
 void add(T item)
          Adds an Identifiable to the repository.
 void addAll(Collection<T> items)
          Adds a collection of Identifiables to the repository.
 List<T> findByField(String fieldName, Collection<? extends Object> values)
           
 T get(Long id)
          Retrieves an Identifiable from the repository according to an id or null in case no Identifiable with the given id is not found
 List<T> getAll()
          Obtains a list containing all the Identifiables in the repository
 List<T> getAll(List<Long> ids)
           
 Long getSize()
           
 T getUniqueInstance()
           
 Boolean isEmpty()
           
 void remove(Long id)
          Removes the Identifiable with the id
 void remove(T item)
          Removes an Identifiable from the repository.
 void removeAll()
          Removes all the Identifiables that the repository has.
 void removeAll(Collection<T> items)
           
 void replaceAll(Collection<T> items)
          Replaces all the Identifiables in the repository by new ones.
 void update(T item)
          Update an Identifiable on the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryRepository

public InMemoryRepository()
Method Detail

add

public void add(T item)
Description copied from interface: Repository
Adds an Identifiable to the repository.

Specified by:
add in interface Repository<T extends Identifiable>
Parameters:
item - The Identifiable to add.
See Also:
Repository.add(com.jdroid.java.domain.Identifiable)

addAll

public void addAll(Collection<T> items)
Description copied from interface: Repository
Adds a collection of Identifiables to the repository.

Specified by:
addAll in interface Repository<T extends Identifiable>
Parameters:
items - The Identifiables to add.
See Also:
Repository.addAll(java.util.Collection)

update

public void update(T item)
Description copied from interface: Repository
Update an Identifiable on the repository.

Specified by:
update in interface Repository<T extends Identifiable>
Parameters:
item - The Identifiable to update.
See Also:
Repository.update(com.jdroid.java.domain.Identifiable)

remove

public void remove(T item)
Description copied from interface: Repository
Removes an Identifiable from the repository.

Specified by:
remove in interface Repository<T extends Identifiable>
Parameters:
item - The Identifiable to remove
See Also:
Repository.remove(com.jdroid.java.domain.Identifiable)

removeAll

public void removeAll(Collection<T> items)
Specified by:
removeAll in interface Repository<T extends Identifiable>
See Also:
Repository.removeAll(java.util.Collection)

replaceAll

public void replaceAll(Collection<T> items)
Description copied from interface: Repository
Replaces all the Identifiables in the repository by new ones.

Specified by:
replaceAll in interface Repository<T extends Identifiable>
Parameters:
items - The new Identifiables to replace the old ones.
See Also:
Repository.replaceAll(java.util.Collection)

getAll

public List<T> getAll()
Description copied from interface: Repository
Obtains a list containing all the Identifiables in the repository

Specified by:
getAll in interface Repository<T extends Identifiable>
Returns:
the list of Identifiables
See Also:
Repository.getAll()

get

public T get(Long id)
Description copied from interface: Repository
Retrieves an Identifiable from the repository according to an id or null in case no Identifiable with the given id is not found

Specified by:
get in interface Repository<T extends Identifiable>
Parameters:
id - the id for the Identifiable to retrieve
Returns:
the Identifiable retrieved.
See Also:
Repository.get(java.lang.Long)

removeAll

public void removeAll()
Description copied from interface: Repository
Removes all the Identifiables that the repository has.

Specified by:
removeAll in interface Repository<T extends Identifiable>
See Also:
Repository.removeAll()

remove

public void remove(Long id)
Description copied from interface: Repository
Removes the Identifiable with the id

Specified by:
remove in interface Repository<T extends Identifiable>
Parameters:
id - The Identifiable id to be removed
See Also:
Repository.remove(java.lang.Long)

isEmpty

public Boolean isEmpty()
Specified by:
isEmpty in interface Repository<T extends Identifiable>
Returns:
If the repository has data or not
See Also:
Repository.isEmpty()

getSize

public Long getSize()
Specified by:
getSize in interface Repository<T extends Identifiable>
See Also:
Repository.getSize()

findByField

public List<T> findByField(String fieldName,
                           Collection<? extends Object> values)
Specified by:
findByField in interface Repository<T extends Identifiable>
Returns:
items the items with the fieldName that match with values.
See Also:
Repository.findByField(java.lang.String, java.util.Collection)

getAll

public List<T> getAll(List<Long> ids)
Specified by:
getAll in interface Repository<T extends Identifiable>
Returns:
All the items with the ids
See Also:
Repository.getAll(java.util.List)

getUniqueInstance

public T getUniqueInstance()
Specified by:
getUniqueInstance in interface Repository<T extends Identifiable>
Returns:
The unique instance
See Also:
Repository.getUniqueInstance()


Copyright © 2014. All rights reserved.