[New] Implemented StrolchDao.hasElement()
This commit is contained in:
parent
62265da046
commit
bf4c23e241
|
@ -25,8 +25,7 @@ public abstract class TransactionalElementMap<T extends StrolchElement> implemen
|
|||
|
||||
@Override
|
||||
public boolean hasElement(StrolchTransaction tx, String type, String id) {
|
||||
// TODO change to dao.hasElement(type, id)
|
||||
return getDao(tx).queryKeySet(type).contains(id);
|
||||
return getDao(tx).hasElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,7 @@ public interface StrolchDao<T extends StrolchElement> {
|
|||
|
||||
public Set<String> queryKeySet();
|
||||
|
||||
// TODO add method hasElement(String type, String id)
|
||||
public boolean hasElement(String type, String id);
|
||||
|
||||
public long querySize();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package li.strolch.persistence.inmemory;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -21,6 +20,14 @@ public class InMemoryDao<T extends StrolchElement> implements StrolchDao<T> {
|
|||
this.elementMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElement(String type, String id) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return false;
|
||||
return byType.containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize() {
|
||||
long size = 0;
|
||||
|
@ -57,7 +64,7 @@ public class InMemoryDao<T extends StrolchElement> implements StrolchDao<T> {
|
|||
public Set<String> queryKeySet(String type) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return Collections.emptySet();
|
||||
return new HashSet<>(0);
|
||||
return new HashSet<>(byType.keySet());
|
||||
}
|
||||
|
||||
|
@ -91,7 +98,7 @@ public class InMemoryDao<T extends StrolchElement> implements StrolchDao<T> {
|
|||
public List<T> queryAll(String type) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return Collections.emptyList();
|
||||
return new ArrayList<>(0);
|
||||
return new ArrayList<>(byType.values());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue