From 2af70cb5173d8eb679e7f7112a0e42a1c2e29192 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Mon, 30 Apr 2012 22:57:22 +0000 Subject: [PATCH] HDFS-3293. Add toString(), equals(..) and hashCode() to JournalInfo. Contributed by Hari Mankude git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1332458 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/protocol/JournalInfo.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index adb26af34a..bf51c6a6f7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -74,6 +74,9 @@ Trunk (unreleased changes) HDFS-2743. Streamline usage of bookkeeper journal manager. (Ivan Kelly via umamahesh) + HDFS-3293. Add toString(), equals(..) and hashCode() to JournalInfo. + (Hari Mankude via szetszwo) + OPTIMIZATIONS HDFS-2834. Add a ByteBuffer-based read API to DFSInputStream. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/protocol/JournalInfo.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/protocol/JournalInfo.java index 530934d237..7261a1c84a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/protocol/JournalInfo.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/protocol/JournalInfo.java @@ -45,4 +45,29 @@ public String getClusterId() { public int getNamespaceId() { return namespaceId; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("lv=").append(layoutVersion).append(";cid=").append(clusterId) + .append(";nsid=").append(namespaceId); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + JournalInfo jInfo; + if (!(o instanceof JournalInfo)) { + return false; + } + jInfo = (JournalInfo) o; + return ((jInfo.clusterId.equals(this.clusterId)) + && (jInfo.namespaceId == this.namespaceId) + && (jInfo.layoutVersion == this.layoutVersion)); + } + + @Override + public int hashCode() { + return (namespaceId ^ layoutVersion ^ clusterId.hashCode()); + } }