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