ConfigObjectMetadata extends ConfigValueMetadata { public Stream<ConfigMetadataNode> getAllSubConfigs() { if (subConfigs.isEmpty()) { return Stream.of(this); } Stream<ConfigMetadataNode> subconfigs = subConfigs.stream().flatMap(n -> n.accept(SUB_CONFIGS_EXTRACTOR)); return Stream.concat(Stream.of(this), subconfigs); } ConfigObjectMetadata(); static Builder builder(ConfigObjectMetadata baseObject); static Builder builder(); static Builder builder(String name); @Override T accept(ConfigMetadataVisitor<T> visitor); String getTypeLabel(); boolean isAbstractType(); Collection<ConfigMetadataNode> getProperties(); Collection<ConfigMetadataNode> getSubConfigs(); Stream<ConfigMetadataNode> getAllSubConfigs();  }
@Test public void testGetAllSubconfigs() { ConfigObjectMetadata o1 = ConfigObjectMetadata.builder().build(); ConfigObjectMetadata o2 = ConfigObjectMetadata.builder().build(); ConfigObjectMetadata o3 = ConfigObjectMetadata.builder().build(); ConfigObjectMetadata o4 = ConfigObjectMetadata.builder().addSubConfig(o1).build(); ConfigObjectMetadata o5 = ConfigObjectMetadata.builder().addSubConfig(o2).addSubConfig(o3).build(); ConfigObjectMetadata o6 = ConfigObjectMetadata.builder().addSubConfig(o4).addSubConfig(o5).build(); List<ConfigMetadataNode> all6 = o6.getAllSubConfigs().collect(toList()); assertEquals(6, all6.size()); assertTrue(all6.contains(o1)); assertTrue(all6.contains(o2)); assertTrue(all6.contains(o3)); assertTrue(all6.contains(o4)); assertTrue(all6.contains(o5)); assertTrue(all6.contains(o6)); List<ConfigMetadataNode> all4 = o4.getAllSubConfigs().collect(toList()); assertEquals(2, all4.size()); assertTrue(all4.contains(o1)); assertTrue(all4.contains(o4)); List<ConfigMetadataNode> all1 = o1.getAllSubConfigs().collect(toList()); assertEquals(1, all1.size()); assertTrue(all1.contains(o1)); }