From 04de4c5aaa1f2235a5209df33f0beb00a2be0078 Mon Sep 17 00:00:00 2001 From: Parth Brahmbhatt Date: Mon, 29 Dec 2014 15:02:39 -0800 Subject: [PATCH] KAFKA-1805: adding equals and hashcode methods to ProducerRecord. --- .../kafka/clients/producer/ProducerRecord.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java b/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java index 065d4e6..e47d12a 100644 --- a/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java +++ b/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java @@ -73,6 +73,7 @@ public final class ProducerRecord { } /** + * The key (or null if no key is specified) */ public K key() { @@ -99,4 +100,28 @@ public final class ProducerRecord { String value = this.value == null ? "null" : this.value.toString(); return "ProducerRecord(topic=" + topic + ", partition=" + partition + ", key=" + key + ", value=" + value; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ProducerRecord)) return false; + + ProducerRecord that = (ProducerRecord) o; + + if (!key.equals(that.key)) return false; + if (!partition.equals(that.partition)) return false; + if (!topic.equals(that.topic)) return false; + if (!value.equals(that.value)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = topic.hashCode(); + result = 31 * result + partition.hashCode(); + result = 31 * result + key.hashCode(); + result = 31 * result + value.hashCode(); + return result; + } } -- 1.9.3 (Apple Git-50)