private static <T extends ResourceNameConfig> ImmutableMap<String, T> mergeResourceNameConfigs( DiagCollector diagCollector, Map<String, T> configsFromGapicConfig, Map<String, T> configsFromProtoFile) { Map<String, T> mergedResourceNameConfigs = new HashMap<>(configsFromProtoFile); // If protofile annotations clash with the configs from configProto, use the configProto. for (T resourceFromGapicConfig : configsFromGapicConfig.values()) { if (configsFromProtoFile.containsKey(resourceFromGapicConfig.getEntityId())) { diagCollector.addDiag( Diag.warning( SimpleLocation.TOPLEVEL, "Resource[Set] entity %s from protofile clashes with a" + " Resource[Set] of the same name from the GAPIC config." + " Using the GAPIC config entity.", resourceFromGapicConfig.getEntityId())); } // Add the protofile resourceNameConfigs to the map of resourceNameConfigs. mergedResourceNameConfigs.put(resourceFromGapicConfig.getEntityId(), resourceFromGapicConfig); } return ImmutableMap.copyOf(mergedResourceNameConfigs); }