Source:
<code>protected KinesisDataSourceMetadata createDataSourceMetadataWithoutExpiredPartitions( SeekableStreamDataSourceMetadata<String, String> currentMetadata, Set<String> expiredPartitionIds ) { log.info("Cleaning up dead shards: " + expiredPartitionIds); final KinesisDataSourceMetadata dataSourceMetadata = (KinesisDataSourceMetadata) currentMetadata; SeekableStreamSequenceNumbers<String, String> old = dataSourceMetadata.getSeekableStreamSequenceNumbers(); Map<String, String> oldPartitionSequenceNumberMap = old.getPartitionSequenceNumberMap(); Map<String, String> newPartitionSequenceNumberMap = new HashMap<>(); for (Map.Entry<String, String> entry : oldPartitionSequenceNumberMap.entrySet()) { if (!expiredPartitionIds.contains(entry.getKey())) { newPartitionSequenceNumberMap.put(entry.getKey(), entry.getValue()); } } Set<String> oldExclusiveStartPartitions = null; Set<String> newExclusiveStartPartitions = null; <START> if (old instanceof SeekableStreamStartSequenceNumbers) { <END> newExclusiveStartPartitions = new HashSet<>(); oldExclusiveStartPartitions = ((SeekableStreamStartSequenceNumbers<String, String>) old).getExclusivePartitions(); for (String partitionId : oldExclusiveStartPartitions) { if (!expiredPartitionIds.contains(partitionId)) { newExclusiveStartPartitions.add(partitionId); } } } SeekableStreamSequenceNumbers<String, String> newSequences; if (old instanceof SeekableStreamStartSequenceNumbers) { newSequences = new SeekableStreamStartSequenceNumbers<String, String>( old.getStream(), null, newPartitionSequenceNumberMap, null, newExclusiveStartPartitions ); } else { newSequences = new SeekableStreamEndSequenceNumbers<String, String>( old.getStream(), null, newPartitionSequenceNumberMap, null ); } return new KinesisDataSourceMetadata(newSequences); }</code><technical_language>I "instanceof", I incorrectly designed in class hierarchy, breaks abstractions..</technical_language>

Target:
protected KinesisDataSourceMetadata createDataSourceMetadataWithoutExpiredPartitions( SeekableStreamDataSourceMetadata<String, String> currentMetadata, Set<String> expiredPartitionIds ) { log.info("Cleaning up dead shards: " + expiredPartitionIds); final KinesisDataSourceMetadata dataSourceMetadata = (KinesisDataSourceMetadata) currentMetadata; SeekableStreamSequenceNumbers<String, String> old = dataSourceMetadata.getSeekableStreamSequenceNumbers(); Map<String, String> oldPartitionSequenceNumberMap = old.getPartitionSequenceNumberMap(); Map<String, String> newPartitionSequenceNumberMap = new HashMap<>(); for (Map.Entry<String, String> entry : oldPartitionSequenceNumberMap.entrySet()) { if (!expiredPartitionIds.contains(entry.getKey())) { newPartitionSequenceNumberMap.put(entry.getKey(), entry.getValue()); } } Set<String> oldExclusiveStartPartitions; Set<String> newExclusiveStartPartitions = null; if (old instanceof SeekableStreamStartSequenceNumbers) { newExclusiveStartPartitions = new HashSet<>(); oldExclusiveStartPartitions = ((SeekableStreamStartSequenceNumbers<String, String>) old).getExclusivePartitions(); for (String partitionId : oldExclusiveStartPartitions) { if (!expiredPartitionIds.contains(partitionId)) { newExclusiveStartPartitions.add(partitionId); } } } SeekableStreamSequenceNumbers<String, String> newSequences; if (old instanceof SeekableStreamStartSequenceNumbers) { newSequences = new SeekableStreamStartSequenceNumbers<String, String>( old.getStream(), null, newPartitionSequenceNumberMap, null, newExclusiveStartPartitions ); } else { newSequences = new SeekableStreamEndSequenceNumbers<String, String>( old.getStream(), null, newPartitionSequenceNumberMap, null ); } return new KinesisDataSourceMetadata(newSequences); }