@Test public void testMerged_Properties() { DataChannelDescriptor d1 = new DataChannelDescriptor(); d1.getProperties().put("X", "1"); d1.getProperties().put("Y", "2"); DataChannelDescriptor d2 = new DataChannelDescriptor(); d2.getProperties().put("X", "3"); d2.getProperties().put("Z", "4"); DefaultDataChannelDescriptorMerger merger = new DefaultDataChannelDescriptorMerger(); DataChannelDescriptor merged = merger.merge(d1, d2); assertEquals(2, merged.getProperties().size()); assertEquals("3", merged.getProperties().get("X")); assertEquals("4", merged.getProperties().get("Z")); }
public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) { if (descriptors == null || descriptors.length == 0) { throw new IllegalArgumentException("Null or empty descriptors"); } if (descriptors.length == 1) { return descriptors[0]; } int len = descriptors.length; DataChannelDescriptor merged = new DataChannelDescriptor(); merged.setName(descriptors[len - 1].getName()); merged.getProperties().putAll(descriptors[len - 1].getProperties()); for (int i = len - 1; i >= 0; i--) { DataChannelDescriptor descriptor = descriptors[i]; for (DataMap map : descriptor.getDataMaps()) { DataMap existing = merged.getDataMap(map.getName()); if (existing != null) { logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'"); } else { logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged.getDataMaps().add(map); } } for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) { DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName()); if (existing != null) { logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'"); for (String mapName : node.getDataMapNames()) { if (!existing.getDataMapNames().contains(mapName)) { existing.getDataMapNames().add(mapName); } } } else { logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged .getNodeDescriptors() .add(cloneDataNodeDescriptor(node, merged)); } } } return merged; }
DefaultDataChannelDescriptorMerger implements DataChannelDescriptorMerger { public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) { if (descriptors == null || descriptors.length == 0) { throw new IllegalArgumentException("Null or empty descriptors"); } if (descriptors.length == 1) { return descriptors[0]; } int len = descriptors.length; DataChannelDescriptor merged = new DataChannelDescriptor(); merged.setName(descriptors[len - 1].getName()); merged.getProperties().putAll(descriptors[len - 1].getProperties()); for (int i = len - 1; i >= 0; i--) { DataChannelDescriptor descriptor = descriptors[i]; for (DataMap map : descriptor.getDataMaps()) { DataMap existing = merged.getDataMap(map.getName()); if (existing != null) { logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'"); } else { logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged.getDataMaps().add(map); } } for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) { DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName()); if (existing != null) { logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'"); for (String mapName : node.getDataMapNames()) { if (!existing.getDataMapNames().contains(mapName)) { existing.getDataMapNames().add(mapName); } } } else { logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged .getNodeDescriptors() .add(cloneDataNodeDescriptor(node, merged)); } } } return merged; } }
DefaultDataChannelDescriptorMerger implements DataChannelDescriptorMerger { public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) { if (descriptors == null || descriptors.length == 0) { throw new IllegalArgumentException("Null or empty descriptors"); } if (descriptors.length == 1) { return descriptors[0]; } int len = descriptors.length; DataChannelDescriptor merged = new DataChannelDescriptor(); merged.setName(descriptors[len - 1].getName()); merged.getProperties().putAll(descriptors[len - 1].getProperties()); for (int i = len - 1; i >= 0; i--) { DataChannelDescriptor descriptor = descriptors[i]; for (DataMap map : descriptor.getDataMaps()) { DataMap existing = merged.getDataMap(map.getName()); if (existing != null) { logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'"); } else { logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged.getDataMaps().add(map); } } for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) { DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName()); if (existing != null) { logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'"); for (String mapName : node.getDataMapNames()) { if (!existing.getDataMapNames().contains(mapName)) { existing.getDataMapNames().add(mapName); } } } else { logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged .getNodeDescriptors() .add(cloneDataNodeDescriptor(node, merged)); } } } return merged; }  }
DefaultDataChannelDescriptorMerger implements DataChannelDescriptorMerger { public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) { if (descriptors == null || descriptors.length == 0) { throw new IllegalArgumentException("Null or empty descriptors"); } if (descriptors.length == 1) { return descriptors[0]; } int len = descriptors.length; DataChannelDescriptor merged = new DataChannelDescriptor(); merged.setName(descriptors[len - 1].getName()); merged.getProperties().putAll(descriptors[len - 1].getProperties()); for (int i = len - 1; i >= 0; i--) { DataChannelDescriptor descriptor = descriptors[i]; for (DataMap map : descriptor.getDataMaps()) { DataMap existing = merged.getDataMap(map.getName()); if (existing != null) { logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'"); } else { logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged.getDataMaps().add(map); } } for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) { DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName()); if (existing != null) { logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'"); for (String mapName : node.getDataMapNames()) { if (!existing.getDataMapNames().contains(mapName)) { existing.getDataMapNames().add(mapName); } } } else { logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged .getNodeDescriptors() .add(cloneDataNodeDescriptor(node, merged)); } } } return merged; }  DataChannelDescriptor merge(DataChannelDescriptor... descriptors); }
DefaultDataChannelDescriptorMerger implements DataChannelDescriptorMerger { public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) { if (descriptors == null || descriptors.length == 0) { throw new IllegalArgumentException("Null or empty descriptors"); } if (descriptors.length == 1) { return descriptors[0]; } int len = descriptors.length; DataChannelDescriptor merged = new DataChannelDescriptor(); merged.setName(descriptors[len - 1].getName()); merged.getProperties().putAll(descriptors[len - 1].getProperties()); for (int i = len - 1; i >= 0; i--) { DataChannelDescriptor descriptor = descriptors[i]; for (DataMap map : descriptor.getDataMaps()) { DataMap existing = merged.getDataMap(map.getName()); if (existing != null) { logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'"); } else { logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged.getDataMaps().add(map); } } for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) { DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName()); if (existing != null) { logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'"); for (String mapName : node.getDataMapNames()) { if (!existing.getDataMapNames().contains(mapName)) { existing.getDataMapNames().add(mapName); } } } else { logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor"); merged .getNodeDescriptors() .add(cloneDataNodeDescriptor(node, merged)); } } } return merged; }  DataChannelDescriptor merge(DataChannelDescriptor... descriptors);  }