[New] Added stream to MapOf... collections

This commit is contained in:
Robert von Burg 2020-07-02 15:52:17 +02:00
parent e66b1bdc6b
commit 17cd3e43c7
14 changed files with 87 additions and 25 deletions

View File

@ -18,7 +18,7 @@ package li.strolch.rest.endpoint;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
import static li.strolch.rest.StrolchRestfulConstants.DATA;
import static li.strolch.runtime.StrolchConstants.ROLE_STROLCH_ADMIN;
import static li.strolch.model.StrolchModelConstants.ROLE_STROLCH_ADMIN;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;

View File

@ -2,7 +2,7 @@ package li.strolch.execution.command;
import static li.strolch.execution.policy.ConfirmationPolicy.DEFAULT_CONFIRMATION;
import static li.strolch.execution.policy.NoPlanning.DEFAULT_PLANNING;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.PARAM_ORDER;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.PARAM_ORDER;
import li.strolch.execution.policy.ConfirmationPolicy;
import li.strolch.execution.policy.PlanningPolicy;

View File

@ -1,7 +1,7 @@
package li.strolch.execution.policy;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.BAG_OBJECTIVES;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.PARAM_DURATION;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.BAG_OBJECTIVES;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.PARAM_DURATION;
import li.strolch.model.activity.Action;
import li.strolch.model.parameter.DurationParameter;

View File

@ -1,7 +1,7 @@
package li.strolch.execution.policy;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.BAG_OBJECTIVES;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.PARAM_DURATION;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.BAG_OBJECTIVES;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.PARAM_DURATION;
import java.util.concurrent.TimeUnit;

View File

@ -1,7 +1,7 @@
package li.strolch.execution.policy;
import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.*;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.*;
import li.strolch.exception.StrolchModelException;
import li.strolch.model.Resource;

View File

@ -1,6 +1,6 @@
package li.strolch.execution.policy;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.TYPE_RESERVE;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.TYPE_RESERVE;
import java.util.ResourceBundle;

View File

@ -24,7 +24,6 @@ import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.policy.PolicyHandler;
import li.strolch.report.ReportConstants;
import li.strolch.report.ReportElement;
import li.strolch.runtime.StrolchConstants;
import li.strolch.utils.ObjectHelper;
import li.strolch.utils.collections.DateRange;
import li.strolch.utils.collections.MapOfLists;
@ -757,11 +756,11 @@ public class GenericReport extends ReportPolicy {
private Stream<? extends StrolchRootElement> getStreamFor(StringParameter objectTypeP) {
switch (objectTypeP.getInterpretation()) {
case StrolchConstants.INTERPRETATION_RESOURCE_REF:
case INTERPRETATION_RESOURCE_REF:
return tx().streamResources(objectTypeP.getUom());
case StrolchConstants.INTERPRETATION_ORDER_REF:
case INTERPRETATION_ORDER_REF:
return tx().streamOrders(objectTypeP.getUom());
case StrolchConstants.INTERPRETATION_ACTIVITY_REF:
case INTERPRETATION_ACTIVITY_REF:
return tx().streamActivities(objectTypeP.getUom());
default:
throw new IllegalArgumentException("Unhandled element type " + objectTypeP.getInterpretation());

View File

@ -1,7 +1,7 @@
package li.strolch.execution;
import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
import static li.strolch.runtime.StrolchConstants.PolicyConstants.PARAM_RESERVED;
import static li.strolch.model.StrolchModelConstants.PolicyConstants.PARAM_RESERVED;
import static org.junit.Assert.*;
import java.io.File;

View File

@ -26,12 +26,12 @@ import li.strolch.agent.api.StrolchAgent;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.StrolchModelConstants;
import li.strolch.model.activity.Activity;
import li.strolch.model.activity.TimeOrdering;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
import li.strolch.service.api.AbstractService;
import li.strolch.service.api.Service;
import li.strolch.service.api.ServiceArgument;
@ -89,12 +89,12 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
Resource resource3 = ModelGenerator.createResource(resId + "3", resId + "3", type);
StringListParameter resRefsP = new StringListParameter("refP", "Ref P",
Arrays.asList(resource1.getId(), resource2.getId(), resource3.getId()));
resRefsP.setInterpretation(StrolchConstants.INTERPRETATION_RESOURCE_REF);
resRefsP.setInterpretation(StrolchModelConstants.INTERPRETATION_RESOURCE_REF);
resRefsP.setUom(type);
resource.addParameter(BAG_ID, resRefsP);
StringParameter resRefP = new StringParameter("refP", "Ref P", resource.getId());
resRefP.setInterpretation(StrolchConstants.INTERPRETATION_RESOURCE_REF);
resRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_RESOURCE_REF);
resRefP.setUom(type);
resource1.addParameter(BAG_ID, resRefP.getClone());
resource2.addParameter(BAG_ID, resRefP.getClone());
@ -107,12 +107,12 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
Order order3 = ModelGenerator.createOrder(orderId + "3", orderId + "3", type);
StringListParameter orderRefsP = new StringListParameter("refP", "Ref P",
Arrays.asList(order1.getId(), order2.getId(), order3.getId()));
orderRefsP.setInterpretation(StrolchConstants.INTERPRETATION_ORDER_REF);
orderRefsP.setInterpretation(StrolchModelConstants.INTERPRETATION_ORDER_REF);
orderRefsP.setUom(type);
order.addParameter(BAG_ID, orderRefsP);
StringParameter orderRefP = new StringParameter("refP", "Ref P", order.getId());
orderRefP.setInterpretation(StrolchConstants.INTERPRETATION_ORDER_REF);
orderRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_ORDER_REF);
orderRefP.setUom(type);
order1.addParameter(BAG_ID, orderRefP.getClone());
order2.addParameter(BAG_ID, orderRefP.getClone());
@ -128,12 +128,12 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
.createActivity(activityId + "3", activityId + "3", type, TimeOrdering.SERIES);
StringListParameter actRefsP = new StringListParameter("refP", "Ref P",
Arrays.asList(activity1.getId(), activity2.getId(), activity3.getId()));
actRefsP.setInterpretation(StrolchConstants.INTERPRETATION_ACTIVITY_REF);
actRefsP.setInterpretation(StrolchModelConstants.INTERPRETATION_ACTIVITY_REF);
actRefsP.setUom(type);
activity.addParameter(BAG_ID, actRefsP);
StringParameter actRefP = new StringParameter("refP", "Ref P", activity.getId());
actRefP.setInterpretation(StrolchConstants.INTERPRETATION_ACTIVITY_REF);
actRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_ACTIVITY_REF);
actRefP.setUom(type);
activity1.addParameter(BAG_ID, actRefP.getClone());
activity2.addParameter(BAG_ID, actRefP.getClone());
@ -306,7 +306,7 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
Resource resource3 = ModelGenerator.createResource(resId + "3", resId + "3", type);
StringListParameter resRefP = new StringListParameter("refP", "Ref P",
Arrays.asList(resource1.getId(), resource2.getId(), resource3.getId()));
resRefP.setInterpretation(StrolchConstants.INTERPRETATION_RESOURCE_REF);
resRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_RESOURCE_REF);
resRefP.setUom(type);
resource.addParameter(BAG_ID, resRefP);
@ -317,7 +317,7 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
Order order3 = ModelGenerator.createOrder(orderId + "3", orderId + "3", type);
StringListParameter orderRefP = new StringListParameter("refP", "Ref P",
Arrays.asList(order1.getId(), order2.getId(), order3.getId()));
orderRefP.setInterpretation(StrolchConstants.INTERPRETATION_ORDER_REF);
orderRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_ORDER_REF);
orderRefP.setUom(type);
order.addParameter(BAG_ID, orderRefP);
@ -331,7 +331,7 @@ public class TxExtendedTest extends AbstractRealmServiceTest<ServiceArgument, Se
.createActivity(activityId + "3", activityId + "3", type, TimeOrdering.SERIES);
StringListParameter actRefP = new StringListParameter("refP", "Ref P",
Arrays.asList(activity1.getId(), activity2.getId(), activity3.getId()));
actRefP.setInterpretation(StrolchConstants.INTERPRETATION_ACTIVITY_REF);
actRefP.setInterpretation(StrolchModelConstants.INTERPRETATION_ACTIVITY_REF);
actRefP.setUom(type);
activity.addParameter(BAG_ID, actRefP);

View File

@ -20,8 +20,8 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FilenameFilter;
import li.strolch.model.StrolchModelConstants;
import li.strolch.privilege.model.Certificate;
import li.strolch.runtime.StrolchConstants;
import li.strolch.service.*;
import li.strolch.service.api.ServiceResult;
import li.strolch.service.api.ServiceResultState;
@ -92,7 +92,7 @@ public class XmlExportServiceTest {
XmlExportModelArgument arg = new XmlExportModelArgument();
arg.modelFileName = "TestExportOnlyResTemplates.xml";
arg.doOrders = false;
arg.resourceTypes.add(StrolchConstants.TEMPLATE);
arg.resourceTypes.add(StrolchModelConstants.TEMPLATE);
arg.multiFile = true;
ServiceResult result = runtimeMock.getServiceHandler().doService(certificate, service, arg);
RuntimeMock.assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);

View File

@ -19,6 +19,7 @@ import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* @author Robert von Burg &lt;eitch@eitchnet.ch&gt;
@ -168,6 +169,10 @@ public class MapOfLists<T, U> {
}
}
public Stream<U> streamValues() {
return this.mapOfLists.values().stream().flatMap(Collection::stream);
}
@Override
public boolean equals(Object o) {
if (this == o)

View File

@ -19,6 +19,7 @@ import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* <p>
@ -243,6 +244,10 @@ public class MapOfMaps<T, U, V> {
}
}
public Stream<V> streamValues() {
return this.mapOfMaps.values().stream().flatMap(uvMap -> uvMap.values().stream());
}
@Override
public boolean equals(Object o) {
if (this == o)

View File

@ -19,6 +19,7 @@ import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* @author Robert von Burg &lt;eitch@eitchnet.ch&gt;
@ -186,6 +187,10 @@ public class MapOfSets<T, U> {
}
}
public Stream<U> streamValues() {
return this.mapOfSets.values().stream().flatMap(Collection::stream);
}
@Override
public boolean equals(Object o) {
if (this == o)

View File

@ -164,6 +164,22 @@ public class SynchronizedCollections {
this.m.forEach(action);
}
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
synchronized (this.mutex) {
return this.m.equals(o);
}
}
@Override
public int hashCode() {
synchronized (this.mutex) {
return this.m.hashCode();
}
}
}
private static class SynchronizedMapOfMaps<T, U, V> extends MapOfMaps<T, U, V> {
@ -330,6 +346,22 @@ public class SynchronizedCollections {
this.m.forEach(action);
}
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
synchronized (this.mutex) {
return this.m.equals(o);
}
}
@Override
public int hashCode() {
synchronized (this.mutex) {
return this.m.hashCode();
}
}
}
private static class SynchronizedMapOfSets<T, U> extends MapOfSets<T, U> {
@ -635,6 +667,22 @@ public class SynchronizedCollections {
s.defaultWriteObject();
}
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
synchronized (this.mutex) {
return this.c.equals(o);
}
}
@Override
public int hashCode() {
synchronized (this.mutex) {
return this.c.hashCode();
}
}
}
private static class SynchronizedList<E> extends SynchronizedCollection<E> implements List<E> {