CloudSourceUtils { public static Source flattenBaseSpecs(Source source) { if (source.getBaseSpecs() == null) { return source; } Map<String, Object> params = new HashMap<>(); for (Map<String, Object> baseSpec : source.getBaseSpecs()) { params.putAll(baseSpec); } params.putAll(source.getSpec()); Source result = source.clone(); result.setSpec(params); result.setBaseSpecs(null); return result; }  static Source flattenBaseSpecs(Source source);  }
@Test public void testFlattenBaseSpecs() throws Exception { CloudObject grandparent = CloudObject.forClassName("text"); addString(grandparent, "G", "g_g"); addString(grandparent, "GP", "gp_g"); addString(grandparent, "GC", "gc_g"); addString(grandparent, "GPC", "gpc_g"); CloudObject parent = CloudObject.forClassName("text"); addString(parent, "P", "p_p"); addString(parent, "PC", "pc_p"); addString(parent, "GP", "gp_p"); addString(parent, "GPC", "gpc_p"); CloudObject child = CloudObject.forClassName("text"); addString(child, "C", "c_c"); addString(child, "PC", "pc_c"); addString(child, "GC", "gc_c"); addString(child, "GPC", "gpc_c"); Source source = new Source(); source.setBaseSpecs(new ArrayList<Map<String, Object>>()); source.getBaseSpecs().add(grandparent); source.getBaseSpecs().add(parent); source.setSpec(child); source.setCodec(CloudObjects.asCloudObject(StringUtf8Coder.of(), null)); Source flat = CloudSourceUtils.flattenBaseSpecs(source); assertNull(flat.getBaseSpecs()); assertEquals( StringUtf8Coder.class.getName(), getString(flat.getCodec(), PropertyNames.OBJECT_TYPE_NAME)); CloudObject flatSpec = CloudObject.fromSpec(flat.getSpec()); assertEquals("g_g", getString(flatSpec, "G")); assertEquals("p_p", getString(flatSpec, "P")); assertEquals("c_c", getString(flatSpec, "C")); assertEquals("gp_p", getString(flatSpec, "GP")); assertEquals("gc_c", getString(flatSpec, "GC")); assertEquals("pc_c", getString(flatSpec, "PC")); assertEquals("gpc_c", getString(flatSpec, "GPC")); }