FactoryBase { @SuppressWarnings("unchecked") void finalizeChildren() { finalisedChildrenFlat = new ArrayList<>(); getFactoryMetadata().visitChildFactoriesAndViewsFlat(this, childUntyped->{ FactoryBase<?,R> child = (FactoryBase<?,R>)childUntyped; if (child!=null){ if (child.addedTo!= finalisedChildrenFlat){ finalisedChildrenFlat.add(child); child.addedTo= finalisedChildrenFlat; } } }, true); for (FactoryBase<?, R> child : finalisedChildrenFlat) { child.addedTo=null; } } FactoryBase(); UUID getId(); void setId(UUID id); boolean idEquals(FactoryBase<?,?> factory); Internal<L,R> internal(); UtilityFactory<L,R> utility();  }
@Test public void test_visitChildFactoriesAndViewsFlatFixed() { ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); ExampleFactoryB factory = new ExampleFactoryB(); exampleFactoryA.referenceAttribute.set(factory); ((FactoryBase<?, ?>)exampleFactoryA).finalizeChildren(); Assertions.assertEquals(1,((FactoryBase<?, ?>)exampleFactoryA).finalisedChildrenFlat.size()); }
@Test public void test_visitChildFactoriesAndViewsFlatFixed_double_call() { ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); ExampleFactoryB factory = new ExampleFactoryB(); exampleFactoryA.referenceAttribute.set(factory); { ((FactoryBase<?, ?>) exampleFactoryA).finalizeChildren(); Assertions.assertEquals(1,((FactoryBase<?, ?>)exampleFactoryA).finalisedChildrenFlat.size()); } { ((FactoryBase<?, ?>) exampleFactoryA).finalizeChildren(); Assertions.assertEquals(1,((FactoryBase<?, ?>)exampleFactoryA).finalisedChildrenFlat.size()); } }
@Test public void test_visitChildFactoriesAndViewsFlat(){ ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); ExampleFactoryB factory = new ExampleFactoryB(); exampleFactoryA.referenceAttribute.set(factory); exampleFactoryA.referenceListAttribute.add(factory); ((FactoryBase<?, ?>)exampleFactoryA).finalizeChildren(); Assertions.assertEquals(1,((FactoryBase<?, ?>)exampleFactoryA).finalisedChildrenFlat.size()); }