[Minor] Code cleanup
This commit is contained in:
parent
7ffaab1bb8
commit
672da1b132
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.agent.impl;
|
package li.strolch.agent.impl;
|
||||||
|
|
||||||
import static java.util.function.Function.identity;
|
|
||||||
import static li.strolch.model.StrolchModelConstants.TEMPLATE;
|
import static li.strolch.model.StrolchModelConstants.TEMPLATE;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -44,7 +43,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(TransientElementMap.class);
|
protected static final Logger logger = LoggerFactory.getLogger(TransientElementMap.class);
|
||||||
|
|
||||||
private Map<String, Map<String, T>> elementMap;
|
private final Map<String, Map<String, T>> elementMap;
|
||||||
|
|
||||||
public TransientElementMap() {
|
public TransientElementMap() {
|
||||||
this.elementMap = new HashMap<>();
|
this.elementMap = new HashMap<>();
|
||||||
|
@ -63,8 +62,8 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized long querySize(StrolchTransaction tx) {
|
public synchronized long querySize(StrolchTransaction tx) {
|
||||||
return this.elementMap.entrySet().stream() //
|
return this.elementMap.values().stream() //
|
||||||
.map(e -> e.getValue().entrySet().size()) //
|
.map(map -> map.entrySet().size()) //
|
||||||
.mapToInt(Integer::valueOf) //
|
.mapToInt(Integer::valueOf) //
|
||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
|
@ -227,10 +226,8 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Set<String> getAllKeys(StrolchTransaction tx) {
|
public synchronized Set<String> getAllKeys(StrolchTransaction tx) {
|
||||||
return this.elementMap.entrySet().stream() //
|
return this.elementMap.values().stream() //
|
||||||
.map(e -> e.getValue().entrySet().stream() //
|
.flatMap(map -> map.keySet().stream()) //
|
||||||
.map(Map.Entry::getKey)) //
|
|
||||||
.flatMap(identity()) //
|
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,9 +237,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
||||||
if (byType == null)
|
if (byType == null)
|
||||||
return new HashSet<>(0);
|
return new HashSet<>(0);
|
||||||
|
|
||||||
return byType.entrySet().stream() //
|
return new HashSet<>(byType.keySet());
|
||||||
.map(Map.Entry::getKey) //
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1375,11 +1375,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
changedR = this.objectFilter.getAdded(Resource.class, Tags.RESOURCE);
|
changedR = this.objectFilter.getAdded(Resource.class, Tags.RESOURCE);
|
||||||
if (changedR.size() == 1) {
|
if (changedR.size() == 1) {
|
||||||
AddResourceCommand cmd = new AddResourceCommand(this);
|
AddResourceCommand cmd = new AddResourceCommand(this);
|
||||||
cmd.setResource((Resource) changedR.get(0));
|
cmd.setResource(changedR.get(0));
|
||||||
addCommand(cmd);
|
addCommand(cmd);
|
||||||
} else if (changedR.size() > 1) {
|
} else if (changedR.size() > 1) {
|
||||||
AddResourcesCommand cmd = new AddResourcesCommand(this);
|
AddResourcesCommand cmd = new AddResourcesCommand(this);
|
||||||
changedR.stream().map(e -> (Resource) e).forEach(cmd::addResource);
|
cmd.setResources(changedR);
|
||||||
addCommand(cmd);
|
addCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue