@Test public void duplicateTest() { MultimediaRecord mr = MultimediaRecord.newBuilder() .setId("777") .setMultimediaItems( Collections.singletonList( Multimedia.newBuilder() .setIdentifier("http: .setReferences("http: .build())) .build(); ImageRecord ir = ImageRecord.newBuilder() .setId("777") .setImageItems( Collections.singletonList( Image.newBuilder() .setIdentifier("http: .setReferences("http: .build())) .build(); AudubonRecord ar = AudubonRecord.newBuilder().setId("777").build(); MultimediaRecord result = MultimediaRecord.newBuilder() .setId("777") .setMultimediaItems( Collections.singletonList( Multimedia.newBuilder() .setIdentifier("http: .setReferences("http: .setType("StillImage") .build())) .build(); MultimediaRecord record = MultimediaConverter.merge(mr, ir, ar); Assert.assertEquals(result, record); }
public static MultimediaRecord merge( @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar) { MultimediaRecord record = MultimediaRecord.newBuilder().setId(mr.getId()).setCreated(mr.getCreated()).build(); boolean isMrEmpty = mr.getMultimediaItems() == null && mr.getIssues().getIssueList().isEmpty(); boolean isIrEmpty = ir.getImageItems() == null && ir.getIssues().getIssueList().isEmpty(); boolean isArEmpty = ar.getAudubonItems() == null && ar.getIssues().getIssueList().isEmpty(); if (isMrEmpty && isIrEmpty && isArEmpty) { return record; } Set<String> issues = new HashSet<>(); issues.addAll(mr.getIssues().getIssueList()); issues.addAll(ir.getIssues().getIssueList()); issues.addAll(ar.getIssues().getIssueList()); Map<String, Multimedia> multimediaMap = new HashMap<>(); putAllAudubonRecord(multimediaMap, ar); putAllImageRecord(multimediaMap, ir); putAllMultimediaRecord(multimediaMap, mr); if (!multimediaMap.isEmpty()) { record.setMultimediaItems(new ArrayList<>(multimediaMap.values())); } if (!issues.isEmpty()) { record.getIssues().getIssueList().addAll(issues); } return record; }
MultimediaConverter { public static MultimediaRecord merge( @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar) { MultimediaRecord record = MultimediaRecord.newBuilder().setId(mr.getId()).setCreated(mr.getCreated()).build(); boolean isMrEmpty = mr.getMultimediaItems() == null && mr.getIssues().getIssueList().isEmpty(); boolean isIrEmpty = ir.getImageItems() == null && ir.getIssues().getIssueList().isEmpty(); boolean isArEmpty = ar.getAudubonItems() == null && ar.getIssues().getIssueList().isEmpty(); if (isMrEmpty && isIrEmpty && isArEmpty) { return record; } Set<String> issues = new HashSet<>(); issues.addAll(mr.getIssues().getIssueList()); issues.addAll(ir.getIssues().getIssueList()); issues.addAll(ar.getIssues().getIssueList()); Map<String, Multimedia> multimediaMap = new HashMap<>(); putAllAudubonRecord(multimediaMap, ar); putAllImageRecord(multimediaMap, ir); putAllMultimediaRecord(multimediaMap, mr); if (!multimediaMap.isEmpty()) { record.setMultimediaItems(new ArrayList<>(multimediaMap.values())); } if (!issues.isEmpty()) { record.getIssues().getIssueList().addAll(issues); } return record; } }
MultimediaConverter { public static MultimediaRecord merge( @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar) { MultimediaRecord record = MultimediaRecord.newBuilder().setId(mr.getId()).setCreated(mr.getCreated()).build(); boolean isMrEmpty = mr.getMultimediaItems() == null && mr.getIssues().getIssueList().isEmpty(); boolean isIrEmpty = ir.getImageItems() == null && ir.getIssues().getIssueList().isEmpty(); boolean isArEmpty = ar.getAudubonItems() == null && ar.getIssues().getIssueList().isEmpty(); if (isMrEmpty && isIrEmpty && isArEmpty) { return record; } Set<String> issues = new HashSet<>(); issues.addAll(mr.getIssues().getIssueList()); issues.addAll(ir.getIssues().getIssueList()); issues.addAll(ar.getIssues().getIssueList()); Map<String, Multimedia> multimediaMap = new HashMap<>(); putAllAudubonRecord(multimediaMap, ar); putAllImageRecord(multimediaMap, ir); putAllMultimediaRecord(multimediaMap, mr); if (!multimediaMap.isEmpty()) { record.setMultimediaItems(new ArrayList<>(multimediaMap.values())); } if (!issues.isEmpty()) { record.getIssues().getIssueList().addAll(issues); } return record; }  }
MultimediaConverter { public static MultimediaRecord merge( @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar) { MultimediaRecord record = MultimediaRecord.newBuilder().setId(mr.getId()).setCreated(mr.getCreated()).build(); boolean isMrEmpty = mr.getMultimediaItems() == null && mr.getIssues().getIssueList().isEmpty(); boolean isIrEmpty = ir.getImageItems() == null && ir.getIssues().getIssueList().isEmpty(); boolean isArEmpty = ar.getAudubonItems() == null && ar.getIssues().getIssueList().isEmpty(); if (isMrEmpty && isIrEmpty && isArEmpty) { return record; } Set<String> issues = new HashSet<>(); issues.addAll(mr.getIssues().getIssueList()); issues.addAll(ir.getIssues().getIssueList()); issues.addAll(ar.getIssues().getIssueList()); Map<String, Multimedia> multimediaMap = new HashMap<>(); putAllAudubonRecord(multimediaMap, ar); putAllImageRecord(multimediaMap, ir); putAllMultimediaRecord(multimediaMap, mr); if (!multimediaMap.isEmpty()) { record.setMultimediaItems(new ArrayList<>(multimediaMap.values())); } if (!issues.isEmpty()) { record.getIssues().getIssueList().addAll(issues); } return record; }  static MultimediaRecord merge(
      @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar); }
MultimediaConverter { public static MultimediaRecord merge( @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar) { MultimediaRecord record = MultimediaRecord.newBuilder().setId(mr.getId()).setCreated(mr.getCreated()).build(); boolean isMrEmpty = mr.getMultimediaItems() == null && mr.getIssues().getIssueList().isEmpty(); boolean isIrEmpty = ir.getImageItems() == null && ir.getIssues().getIssueList().isEmpty(); boolean isArEmpty = ar.getAudubonItems() == null && ar.getIssues().getIssueList().isEmpty(); if (isMrEmpty && isIrEmpty && isArEmpty) { return record; } Set<String> issues = new HashSet<>(); issues.addAll(mr.getIssues().getIssueList()); issues.addAll(ir.getIssues().getIssueList()); issues.addAll(ar.getIssues().getIssueList()); Map<String, Multimedia> multimediaMap = new HashMap<>(); putAllAudubonRecord(multimediaMap, ar); putAllImageRecord(multimediaMap, ir); putAllMultimediaRecord(multimediaMap, mr); if (!multimediaMap.isEmpty()) { record.setMultimediaItems(new ArrayList<>(multimediaMap.values())); } if (!issues.isEmpty()) { record.getIssues().getIssueList().addAll(issues); } return record; }  static MultimediaRecord merge(
      @NonNull MultimediaRecord mr, @NonNull ImageRecord ir, @NonNull AudubonRecord ar);  }