I currently have 2 Maps intersectionDiffLeft, intersectionDiffRight with the structure of Map<Boolean, List<Map<String, Object>>
Where if the boolean is true it means it is considered a matching record. If it is true there will be 1 true record from left side and one true record on right side. There can be zero to many in this map. Same goes for if the boolean is false, meaning those records don't match another one on the opposite side, however the same amount on each doesn't need to be the same like if the boolean is true.
I'm looking for a way to create a list of objects such as this one to return after I have finished.
@Value public class ReconciliationResult { Map<String, Object> recordValue; List<Object> keyValues; Origin origin; ReconciliationResultStatus status; public enum ReconciliationResultStatus { INVALID_KEY("INVALID_KEY"), DUPLICATE_KEY("DUPLICATE_KEY"), MATCHING("MATCHING"), NON_MATCHING("NON_MATCHING"); private final String text; ReconciliationResultStatus(String text) { this.text = text; } } public enum Origin { LEFT_SIDE("lhs"), RIGHT_SIDE("rhs"); private final String side; Origin(String side) { this.side = side; } }
I currently have it implemented in a way where I am duplicating code and it works, but am looking for a more elegant solution instead of all of this duplication, note the creation of intersectionDiffRight is the same as intersectionDiffLeft except we use rhsMap, instead of lhsMap.
Please let me know if you need any other code from me.
Map<Boolean, List<Map<String, Object>>> intersectionDiffRight = rhsMap .entrySet() .stream() .collect( Collectors.partitioningBy( entry -> lhsMap.containsKey(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toList()))); List<Map<String, Object>> intersection = new ArrayList<>(); intersection.addAll(intersectionDiffLeft.get(true)); intersection.addAll(intersectionDiffRight.get(true)); List<Map<String, Object>> difference = new ArrayList<>(); difference.addAll(intersectionDiffLeft.get(false)); difference.addAll(intersectionDiffRight.get(false)); List<ReconciliationResult> reconResults = new ArrayList<>(); for (Map<String, Object> map : intersectionDiffLeft.get(true)) { reconResults.add(new ReconciliationResult(map, Collections.singletonList(map.keySet()), ReconciliationResult.Origin.LEFT_SIDE, ReconciliationResult.ReconciliationResultStatus.MATCHING)); } for (Map<String, Object> map : intersectionDiffLeft.get(false)) { reconResults.add(new ReconciliationResult(map, Collections.singletonList(map.keySet()), ReconciliationResult.Origin.LEFT_SIDE, ReconciliationResult.ReconciliationResultStatus.NON_MATCHING); } for (Map<String, Object> map : intersectionDiffRight.get(true)) { reconResults.add(new ReconciliationResult(map, Collections.singletonList(map.keySet()), ReconciliationResult.Origin.RIGHT_SIDE, ReconciliationResult.ReconciliationResultStatus.MATCHING)); } for (Map<String, Object> map : intersectionDiffRight.get(false)) { reconResults.add(new ReconciliationResult(map, Collections.singletonList(map.keySet()), ReconciliationResult.Origin.RIGHT_SIDE, ReconciliationResult.ReconciliationResultStatus.NON_MATCHING)); } ```
@Value
?\$\endgroup\$