Source:
<code>public SchemaRegistry(final ValidatedConfiguration vc) { final ImmutableMap<String, MappingConfiguration> mappings = vc.configuration().mappings; final ImmutableMap<String,Optional<String>> schemaLocationsByMapping = ImmutableMap.copyOf(Maps.transformValues(mappings, config -> config.schemaFile)); <START> final ImmutableMap<String,Optional<Integer>> schemaIdsByLocation = <END> mappings.values() .stream() .filter(config -> config.schemaFile.isPresent()) .map(config -> Maps.immutableEntry(config.schemaFile.get(), config.schemaId)) .collect(MoreCollectors.toImmutableMap()); ImmutableMap.copyOf(Maps.transformValues(mappings, config -> config.schemaId)); logger.debug("Loading schemas for mappings: {}", schemaLocationsByMapping.keySet()); final ImmutableMap<Optional<String>, DivolteSchema> schemasByLocation = schemaLocationsByMapping.values() .stream() .distinct() .map(schemaLocation -> { Schema schema = loadSchema(schemaLocation); Optional<Integer> schemaId = schemaIdsByLocation.get(schemaLocation); return Maps.immutableEntry(schemaLocation, new DivolteSchema(schemaId, schema)); }) .collect(MoreCollectors.toImmutableMap()); schemasByMappingName = ImmutableMap.copyOf(Maps.transformValues(schemaLocationsByMapping, schemasByLocation::get)); logger.info("Loaded schemas used for mappings: {}", schemasByMappingName.keySet()); schemasBySinkName = mappings.values() .stream() .flatMap(config -> config.sinks .stream() .map(sink -> Maps.immutableEntry(sink, schemasByLocation.get(config.schemaFile)))) .distinct() .collect(MoreCollectors.toImmutableMap()); logger.info("Inferred schemas used for sinks: {}", schemasBySinkName.keySet()); }</code><technical_language>do need this separate mapping? mapping carry information DivolteSchema contains ID</technical_language>

Target:
public SchemaRegistry(final ValidatedConfiguration vc) { final ImmutableMap<String, MappingConfiguration> mappings = vc.configuration().mappings; final ImmutableMap<String,Optional<String>> schemaLocationsByMapping = ImmutableMap.copyOf(Maps.transformValues(mappings, config -> config.schemaFile)); final ImmutableMap<String,Optional<Integer>> schemaIdsByLocation = mappings.values() .stream() .filter(config -> config.schemaFile.isPresent()) .collect(ImmutableMap.toImmutableMap(config -> config.schemaFile.get(), config -> config.confluentId)); logger.debug("Loading schemas for mappings: {}", schemaLocationsByMapping.keySet()); final ImmutableMap<Optional<String>, DivolteSchema> schemasByLocation = schemaLocationsByMapping.values() .stream() .distinct() .collect(ImmutableMap.toImmutableMap( Function.identity(), schemaLocation -> { Schema schema = loadSchema(schemaLocation); Optional<Integer> schemaId = schemaLocation.flatMap(schemaIdsByLocation::get); return new DivolteSchema(schemaId, schema); }) ); schemasByMappingName = ImmutableMap.copyOf(Maps.transformValues(schemaLocationsByMapping, schemasByLocation::get)); logger.info("Loaded schemas used for mappings: {}", schemasByMappingName.keySet()); schemasBySinkName = mappings.values() .stream() .flatMap(config -> config.sinks .stream() .map(sink -> Maps.immutableEntry(sink, schemasByLocation.get(config.schemaFile)))) .distinct() .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); logger.info("Inferred schemas used for sinks: {}", schemasBySinkName.keySet()); }