use of org.apache.commons.collections4.MultiValuedMap in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.
/**
* Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
FlowPath forwardPath = flow.getForwardPath();
PathSegment firstSegment = forwardPath.getSegments().get(0);
FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
boolean isVxlan = flow.getEncapsulationType() == VXLAN;
flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
}
}
}
if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getProtectedReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
}
}
}
});
return flowEntries.asMap();
}
use of org.apache.commons.collections4.MultiValuedMap in project methods-distance by sevntu-checkstyle.
the class MethodOrder method getMethodInvocationsNesting.
private static MultiValuedMap<MethodInvocation, MethodInvocation> getMethodInvocationsNesting(Map<ResolvedCall, MethodInvocation> callToInvocation) {
final SetValuedMap<MethodInvocation, MethodInvocation> nestedInside = new HashSetValuedHashMap<>();
callToInvocation.entrySet().stream().forEach(entry -> {
final ResolvedCall resolvedCall = entry.getKey();
final MethodInvocation methodInvocation = entry.getValue();
callToInvocation.keySet().stream().filter(rc -> !rc.equals(resolvedCall)).filter(resolvedCall::isNestedInside).forEach(rc -> nestedInside.put(methodInvocation, callToInvocation.get(rc)));
});
return nestedInside;
}
use of org.apache.commons.collections4.MultiValuedMap in project dhis2-core by dhis2.
the class QueryPlannerTest method testGetPermutationDimensionalItemValueMapCocDisabled.
@Test
void testGetPermutationDimensionalItemValueMapCocDisabled() {
MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 1d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 2d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 3d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 4d));
aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 5d));
aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 6d));
aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 7d));
aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 8d));
Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
assertNotNull(permutationMap);
String ouAM1Key = ouA.getUid() + DIMENSION_SEP + "200101";
String ouAM2Key = ouA.getUid() + DIMENSION_SEP + "200102";
String ouBM1Key = ouB.getUid() + DIMENSION_SEP + "200101";
String ouBM2Key = ouB.getUid() + DIMENSION_SEP + "200102";
List<DimensionItemObjectValue> ouAM1 = permutationMap.get(ouAM1Key);
List<DimensionItemObjectValue> ouAM2 = permutationMap.get(ouAM2Key);
List<DimensionItemObjectValue> ouBM1 = permutationMap.get(ouBM1Key);
List<DimensionItemObjectValue> ouBM2 = permutationMap.get(ouBM2Key);
assertEquals(2, ouAM1.size());
assertEquals(2, ouAM2.size());
assertEquals(2, ouBM1.size());
assertEquals(2, ouBM2.size());
List<DimensionItemObjectValue> ouAM1Expected = new ArrayList<>();
ouAM1Expected.add(new DimensionItemObjectValue(deA, 1d));
ouAM1Expected.add(new DimensionItemObjectValue(deB, 5d));
List<DimensionItemObjectValue> ouAM2Expected = new ArrayList<>();
ouAM2Expected.add(new DimensionItemObjectValue(deA, 2d));
ouAM2Expected.add(new DimensionItemObjectValue(deB, 6d));
List<DimensionItemObjectValue> ouBM1Expected = new ArrayList<>();
ouBM1Expected.add(new DimensionItemObjectValue(deA, 3d));
ouBM1Expected.add(new DimensionItemObjectValue(deB, 7d));
List<DimensionItemObjectValue> ouBM2Expected = new ArrayList<>();
ouBM2Expected.add(new DimensionItemObjectValue(deA, 4d));
ouBM2Expected.add(new DimensionItemObjectValue(deB, 8d));
assertCollectionsMatch(ouAM1Expected, ouAM1);
assertCollectionsMatch(ouAM2Expected, ouAM2);
assertCollectionsMatch(ouBM1Expected, ouBM1);
assertCollectionsMatch(ouBM2Expected, ouBM2);
}
use of org.apache.commons.collections4.MultiValuedMap in project dhis2-core by dhis2.
the class QueryPlannerTest method testGetPermutationDimensionalItemValueMap.
@Test
void testGetPermutationDimensionalItemValueMap() {
MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 1d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 2d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 3d));
aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 4d));
aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q1"), new DimensionItemObjectValue(deB, 5d));
aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q2"), new DimensionItemObjectValue(deB, 6d));
aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q1"), new DimensionItemObjectValue(deB, 7d));
aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q2"), new DimensionItemObjectValue(deB, 8d));
Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
assertNotNull(permutationMap);
String ouAQ1Key = ouA.getUid() + DIMENSION_SEP + "2000Q1";
String ouAQ2Key = ouA.getUid() + DIMENSION_SEP + "2000Q2";
String ouBQ1Key = ouB.getUid() + DIMENSION_SEP + "2000Q1";
String ouBQ2Key = ouB.getUid() + DIMENSION_SEP + "2000Q2";
List<DimensionItemObjectValue> ouAQ1 = permutationMap.get(ouAQ1Key);
List<DimensionItemObjectValue> ouAQ2 = permutationMap.get(ouAQ2Key);
List<DimensionItemObjectValue> ouBQ1 = permutationMap.get(ouBQ1Key);
List<DimensionItemObjectValue> ouBQ2 = permutationMap.get(ouBQ2Key);
assertEquals(2, ouAQ1.size());
assertEquals(2, ouAQ2.size());
assertEquals(2, ouBQ1.size());
assertEquals(2, ouBQ2.size());
List<DimensionItemObjectValue> ouAQ1Expected = new ArrayList<>();
ouAQ1Expected.add(new DimensionItemObjectValue(deA, 1d));
ouAQ1Expected.add(new DimensionItemObjectValue(deB, 5d));
List<DimensionItemObjectValue> ouAQ2Expected = new ArrayList<>();
ouAQ2Expected.add(new DimensionItemObjectValue(deA, 2d));
ouAQ2Expected.add(new DimensionItemObjectValue(deB, 6d));
List<DimensionItemObjectValue> ouBQ1Expected = new ArrayList<>();
ouBQ1Expected.add(new DimensionItemObjectValue(deA, 3d));
ouBQ1Expected.add(new DimensionItemObjectValue(deB, 7d));
List<DimensionItemObjectValue> ouBQ2Expected = new ArrayList<>();
ouBQ2Expected.add(new DimensionItemObjectValue(deA, 4d));
ouBQ2Expected.add(new DimensionItemObjectValue(deB, 8d));
assertCollectionsMatch(ouAQ1Expected, ouAQ1);
assertCollectionsMatch(ouAQ2Expected, ouAQ2);
assertCollectionsMatch(ouBQ1Expected, ouBQ1);
assertCollectionsMatch(ouBQ2Expected, ouBQ2);
}
Aggregations