From c12c9e6e29db2ab364106e642c8f1875679b728c Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 11 Nov 2015 10:17:32 +0100 Subject: [PATCH] add equals and hashcode to GsubExpression --- .../processor/mutate/GsubExpression.java | 26 ++++++++++++++++--- .../mutate/MutateProcessorFactoryTests.java | 5 +--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/mutate/GsubExpression.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/mutate/GsubExpression.java index c62577d1cc8..402061b18ac 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/mutate/GsubExpression.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/processor/mutate/GsubExpression.java @@ -19,6 +19,7 @@ package org.elasticsearch.ingest.processor.mutate; +import java.util.Objects; import java.util.regex.Pattern; /** @@ -31,9 +32,9 @@ public class GsubExpression { private final String replacement; public GsubExpression(String fieldName, Pattern pattern, String replacement) { - this.fieldName = fieldName; - this.pattern = pattern; - this.replacement = replacement; + this.fieldName = Objects.requireNonNull(fieldName); + this.pattern = Objects.requireNonNull(pattern); + this.replacement = Objects.requireNonNull(replacement); } public String getFieldName() { @@ -47,4 +48,23 @@ public class GsubExpression { public String getReplacement() { return replacement; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GsubExpression that = (GsubExpression) o; + return Objects.equals(fieldName, that.fieldName) && + Objects.equals(pattern.pattern(), that.pattern.pattern()) && + Objects.equals(replacement, that.replacement); + } + + @Override + public int hashCode() { + return Objects.hash(fieldName, pattern, replacement); + } } diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/mutate/MutateProcessorFactoryTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/mutate/MutateProcessorFactoryTests.java index 017d0465563..3ebd98c10c3 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/mutate/MutateProcessorFactoryTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/processor/mutate/MutateProcessorFactoryTests.java @@ -205,10 +205,7 @@ public class MutateProcessorFactoryTests extends ESTestCase { MutateProcessor processor = factory.create(config); assertThat(processor.getGsub().size(), equalTo(1)); - GsubExpression gsubExpression = processor.getGsub().get(0); - assertThat(gsubExpression.getFieldName(), equalTo("foo")); - assertThat(gsubExpression.getPattern().pattern(), equalTo(Pattern.compile("\\s.*e\\s").pattern())); - assertThat(gsubExpression.getReplacement(), equalTo("")); + assertThat(processor.getGsub().get(0), equalTo(new GsubExpression("foo", Pattern.compile("\\s.*e\\s"), ""))); } public void testCreateGsubPatternInvalidFormat() throws Exception {