add equals and hashcode to GsubExpression
This commit is contained in:
parent
2b31f4fff7
commit
c12c9e6e29
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.ingest.processor.mutate;
|
package org.elasticsearch.ingest.processor.mutate;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,9 +32,9 @@ public class GsubExpression {
|
||||||
private final String replacement;
|
private final String replacement;
|
||||||
|
|
||||||
public GsubExpression(String fieldName, Pattern pattern, String replacement) {
|
public GsubExpression(String fieldName, Pattern pattern, String replacement) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = Objects.requireNonNull(fieldName);
|
||||||
this.pattern = pattern;
|
this.pattern = Objects.requireNonNull(pattern);
|
||||||
this.replacement = replacement;
|
this.replacement = Objects.requireNonNull(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFieldName() {
|
public String getFieldName() {
|
||||||
|
@ -47,4 +48,23 @@ public class GsubExpression {
|
||||||
public String getReplacement() {
|
public String getReplacement() {
|
||||||
return replacement;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,10 +205,7 @@ public class MutateProcessorFactoryTests extends ESTestCase {
|
||||||
|
|
||||||
MutateProcessor processor = factory.create(config);
|
MutateProcessor processor = factory.create(config);
|
||||||
assertThat(processor.getGsub().size(), equalTo(1));
|
assertThat(processor.getGsub().size(), equalTo(1));
|
||||||
GsubExpression gsubExpression = processor.getGsub().get(0);
|
assertThat(processor.getGsub().get(0), equalTo(new GsubExpression("foo", Pattern.compile("\\s.*e\\s"), "<word_ending_with_e>")));
|
||||||
assertThat(gsubExpression.getFieldName(), equalTo("foo"));
|
|
||||||
assertThat(gsubExpression.getPattern().pattern(), equalTo(Pattern.compile("\\s.*e\\s").pattern()));
|
|
||||||
assertThat(gsubExpression.getReplacement(), equalTo("<word_ending_with_e>"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGsubPatternInvalidFormat() throws Exception {
|
public void testCreateGsubPatternInvalidFormat() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue