From 30e8766faa0d8946c7b0b1dda00663600f1fd537 Mon Sep 17 00:00:00 2001 From: jinwoo-Bae Date: Tue, 28 Feb 2023 13:40:04 +0900 Subject: [PATCH] Move equals/hashcode from ChunkIterator to Chunk class Those methods were mistakenly added in ChunkIterator. Issue #4314 --- .../org/springframework/batch/item/Chunk.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java index 084d07604..03c285acb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java @@ -211,6 +211,32 @@ public class Chunk implements Iterable, Serializable { return String.format("[items=%s, skips=%s]", items, skips); } + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof Chunk)) { + return false; + } + Chunk other = (Chunk) obj; + return Objects.equals(this.items, other.items) && Objects.equals(this.skips, other.skips) + && Objects.equals(this.errors, other.errors) && Objects.equals(this.userData, other.userData) + && this.end == other.end && this.busy == other.busy; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + items.hashCode(); + result = 31 * result + skips.hashCode(); + result = 31 * result + errors.hashCode(); + result = 31 * result + Objects.hashCode(userData); + result = 31 * result + (end ? 1 : 0); + result = 31 * result + (busy ? 1 : 0); + return result; + } + /** * Special iterator for a chunk providing the {@link #remove(Throwable)} method for * dynamically removing an item and adding it to the skips. @@ -262,25 +288,6 @@ public class Chunk implements Iterable, Serializable { return String.format("[items=%s, skips=%s]", items, skips); } - @Override - public int hashCode() { - return Objects.hash(items, skips, errors, userData, end, busy); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Chunk)) { - return false; - } - Chunk other = (Chunk) obj; - return Objects.equals(items, other.items) && Objects.equals(skips, other.skips) - && Objects.equals(errors, other.errors) && Objects.equals(userData, other.userData) - && end == other.end && busy == other.busy; - } - } }