Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
added equals and hashCode methods to most action implementations - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kramer committed Mar 9, 2015
1 parent 792c3a3 commit ce215ee
Show file tree
Hide file tree
Showing 56 changed files with 1,602 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.searchbox.client.config;

import com.google.gson.Gson;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -101,6 +103,49 @@ public ClientConfig build() {
}
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.append(serverList)
.append(isMultiThreaded)
.append(isDiscoveryEnabled)
.append(discoveryFrequency)
.append(connTimeout)
.append(readTimeout)
.append(discoveryFrequencyTimeUnit)
.append(maxConnectionIdleTime)
.append(maxConnectionIdleTimeDurationTimeUnit)
.append(gson)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

ClientConfig rhs = (ClientConfig) obj;
return new EqualsBuilder()
.append(serverList, rhs.serverList)
.append(isMultiThreaded, rhs.isMultiThreaded)
.append(isDiscoveryEnabled, rhs.isDiscoveryEnabled)
.append(discoveryFrequency, rhs.discoveryFrequency)
.append(connTimeout, rhs.connTimeout)
.append(readTimeout, rhs.readTimeout)
.append(discoveryFrequencyTimeUnit, rhs.discoveryFrequencyTimeUnit)
.append(maxConnectionIdleTime, rhs.maxConnectionIdleTime)
.append(maxConnectionIdleTimeDurationTimeUnit, rhs.maxConnectionIdleTimeDurationTimeUnit)
.append(gson, rhs.gson)
.isEquals();
}

protected static abstract class AbstractBuilder<T extends ClientConfig, K extends AbstractBuilder> {
protected Set<String> serverList = new LinkedHashSet<String>();
protected boolean isMultiThreaded;
Expand Down
30 changes: 29 additions & 1 deletion jest-common/src/main/java/io/searchbox/core/Count.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.google.gson.Gson;
import io.searchbox.action.AbstractAction;
import io.searchbox.action.AbstractMultiTypeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* @author Dogukan Sonmez
Expand Down Expand Up @@ -47,6 +48,33 @@ public Object getData(Gson gson) {
return query;
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(query)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

Count rhs = (Count) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(query, rhs.query)
.isEquals();
}

public static class Builder extends AbstractMultiTypeActionBuilder<Count, Builder> {
private String query;

Expand Down
35 changes: 30 additions & 5 deletions jest-common/src/main/java/io/searchbox/core/DeleteByQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import com.google.gson.Gson;
import io.searchbox.action.AbstractMultiTypeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* @author Dogukan Sonmez
* @author cihat keser
*/
public class DeleteByQuery extends GenericResultAbstractAction {

final static Logger log = LoggerFactory.getLogger(DeleteByQuery.class);
private String query;

public DeleteByQuery(Builder builder) {
Expand All @@ -23,10 +22,9 @@ public DeleteByQuery(Builder builder) {
}

@Override
public String buildURI() {
protected String buildURI() {
StringBuilder sb = new StringBuilder();
sb.append(super.buildURI()).append("/_query");
log.debug("Created URI for delete by query action is : {}", sb.toString());
return sb.toString();
}

Expand All @@ -45,6 +43,33 @@ public Object getData(Gson gson) {
return query;
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(query)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

DeleteByQuery rhs = (DeleteByQuery) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(query, rhs.query)
.isEquals();
}

public static class Builder extends AbstractMultiTypeActionBuilder<DeleteByQuery, Builder> {

private String query;
Expand Down
33 changes: 29 additions & 4 deletions jest-common/src/main/java/io/searchbox/core/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import com.google.gson.Gson;
import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* @author Dogukan Sonmez
* @author cihat keser
*/
public class Explain extends GenericResultAbstractDocumentTargetedAction {

final static Logger log = LoggerFactory.getLogger(Explain.class);
private Object query;

private Explain(Builder builder) {
Expand All @@ -34,10 +33,36 @@ public Object getData(Gson gson) {
protected String buildURI() {
StringBuilder sb = new StringBuilder(super.buildURI());
sb.append("/_explain");
log.debug("Created URI for explain action is :" + sb.toString());
return sb.toString();
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(query)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

Explain rhs = (Explain) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(query, rhs.query)
.isEquals();
}

public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Explain, Builder> {
private final Object query;

Expand Down
29 changes: 29 additions & 0 deletions jest-common/src/main/java/io/searchbox/core/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
import io.searchbox.client.JestResult;
import io.searchbox.params.Parameters;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Collection;

Expand Down Expand Up @@ -51,6 +53,33 @@ public String getBulkMethodName() {
}
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(source)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

Index rhs = (Index) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(source, rhs.source)
.isEquals();
}

public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Index, Builder> {
private final Object source;

Expand Down
33 changes: 29 additions & 4 deletions jest-common/src/main/java/io/searchbox/core/MoreLikeThis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import com.google.gson.Gson;
import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* @author Dogukan Sonmez
* @author cihat keser
*/
public class MoreLikeThis extends GenericResultAbstractDocumentTargetedAction {

final static Logger log = LoggerFactory.getLogger(MoreLikeThis.class);
private Object query;

private MoreLikeThis(Builder builder) {
Expand All @@ -25,7 +24,6 @@ private MoreLikeThis(Builder builder) {
protected String buildURI() {
StringBuilder sb = new StringBuilder(super.buildURI());
sb.append("/_mlt");
log.debug("Created URI for update action is :" + sb.toString());
return sb.toString();
}

Expand All @@ -39,6 +37,33 @@ public Object getData(Gson gson) {
return query;
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(query)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

MoreLikeThis rhs = (MoreLikeThis) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(query, rhs.query)
.isEquals();
}

public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<MoreLikeThis, Builder> {
private Object query;

Expand Down
29 changes: 29 additions & 0 deletions jest-common/src/main/java/io/searchbox/core/MultiGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.searchbox.action.AbstractAction;
import io.searchbox.action.AbstractMultiTypeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Collection;
import java.util.LinkedList;
Expand Down Expand Up @@ -63,6 +65,33 @@ public String getRestMethodName() {
return "GET";
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(source)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

MultiGet rhs = (MultiGet) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(source, rhs.source)
.isEquals();
}

public static class Builder {
private Builder() {
}
Expand Down
Loading

0 comments on commit ce215ee

Please sign in to comment.