@Test void testRemoveCompoundOrphans() { EditorAttributeIdentifier removedParentId = mock(EditorAttributeIdentifier.class); EditorAttribute attrOther = mock(EditorAttribute.class); EditorAttribute attrA = mock(EditorAttribute.class); EditorAttributeIdentifier attrAid = mock(EditorAttributeIdentifier.class); when(attrAid.getId()).thenReturn("A"); when(attrA.getId()).thenReturn("A"); EditorAttribute attrAA = mock(EditorAttribute.class); EditorAttributeIdentifier attrAAid = mock(EditorAttributeIdentifier.class); when(attrAAid.getId()).thenReturn("AA"); when(attrAA.getId()).thenReturn("AA"); EditorAttribute attrAB = mock(EditorAttribute.class); EditorAttributeIdentifier attrABid = mock(EditorAttributeIdentifier.class); when(attrABid.getId()).thenReturn("AB"); when(attrAB.getId()).thenReturn("AB"); EditorAttribute attrABA = mock(EditorAttribute.class); EditorAttributeIdentifier attrABAid = mock(EditorAttributeIdentifier.class); when(attrABAid.getId()).thenReturn("ABA"); when(attrABA.getId()).thenReturn("ABA"); when(attrA.getParent()).thenReturn(removedParentId); when(attrAA.getParent()).thenReturn(attrAid); when(attrAB.getParent()).thenReturn(attrAid); when(attrABA.getParent()).thenReturn(attrABid); List<EditorAttribute> attrs = newArrayList(attrOther, attrAA, attrAB, attrABA); AttributeMapper.removeCompoundOrphans(attrs); assertEquals(singletonList(attrOther), attrs); }
static void removeCompoundOrphans(List<EditorAttribute> editorAttributes) { Set<String> ids = editorAttributes.stream().map(EditorAttribute::getId).collect(toSet()); List<EditorAttribute> attrsToDelete = editorAttributes.stream() .filter(attr -> attr.getParent() != null) .filter(attr -> !ids.contains(attr.getParent().getId())) .collect(toList()); if (attrsToDelete.isEmpty()) { return; } editorAttributes.removeAll(attrsToDelete); removeCompoundOrphans(editorAttributes); }
AttributeMapper { static void removeCompoundOrphans(List<EditorAttribute> editorAttributes) { Set<String> ids = editorAttributes.stream().map(EditorAttribute::getId).collect(toSet()); List<EditorAttribute> attrsToDelete = editorAttributes.stream() .filter(attr -> attr.getParent() != null) .filter(attr -> !ids.contains(attr.getParent().getId())) .collect(toList()); if (attrsToDelete.isEmpty()) { return; } editorAttributes.removeAll(attrsToDelete); removeCompoundOrphans(editorAttributes); } }
AttributeMapper { static void removeCompoundOrphans(List<EditorAttribute> editorAttributes) { Set<String> ids = editorAttributes.stream().map(EditorAttribute::getId).collect(toSet()); List<EditorAttribute> attrsToDelete = editorAttributes.stream() .filter(attr -> attr.getParent() != null) .filter(attr -> !ids.contains(attr.getParent().getId())) .collect(toList()); if (attrsToDelete.isEmpty()) { return; } editorAttributes.removeAll(attrsToDelete); removeCompoundOrphans(editorAttributes); } AttributeMapper(
      AttributeFactory attributeFactory,
      TagMapper tagMapper,
      EntityTypeReferenceMapper entityTypeReferenceMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      SortMapper sortMapper); }
AttributeMapper { static void removeCompoundOrphans(List<EditorAttribute> editorAttributes) { Set<String> ids = editorAttributes.stream().map(EditorAttribute::getId).collect(toSet()); List<EditorAttribute> attrsToDelete = editorAttributes.stream() .filter(attr -> attr.getParent() != null) .filter(attr -> !ids.contains(attr.getParent().getId())) .collect(toList()); if (attrsToDelete.isEmpty()) { return; } editorAttributes.removeAll(attrsToDelete); removeCompoundOrphans(editorAttributes); } AttributeMapper(
      AttributeFactory attributeFactory,
      TagMapper tagMapper,
      EntityTypeReferenceMapper entityTypeReferenceMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      SortMapper sortMapper); EditorAttribute createEditorAttribute(); }
AttributeMapper { static void removeCompoundOrphans(List<EditorAttribute> editorAttributes) { Set<String> ids = editorAttributes.stream().map(EditorAttribute::getId).collect(toSet()); List<EditorAttribute> attrsToDelete = editorAttributes.stream() .filter(attr -> attr.getParent() != null) .filter(attr -> !ids.contains(attr.getParent().getId())) .collect(toList()); if (attrsToDelete.isEmpty()) { return; } editorAttributes.removeAll(attrsToDelete); removeCompoundOrphans(editorAttributes); } AttributeMapper(
      AttributeFactory attributeFactory,
      TagMapper tagMapper,
      EntityTypeReferenceMapper entityTypeReferenceMapper,
      AttributeReferenceMapper attributeReferenceMapper,
      SortMapper sortMapper); EditorAttribute createEditorAttribute();  }