public ProducerStateEntry withProducerIdAndBatchMetadata(long producerId, Optional<BatchMetadata> batchMetadata) {
        return new ProducerStateEntry(producerId, this.producerEpoch(), this.coordinatorEpoch, this.lastTimestamp,
            this.currentTxnFirstOffset, batchMetadata);
    }
Returns a new instance with the provided parameters (when present) and the values from the current instance
otherwise.
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateEntry.java