Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hash code override methods where equals method is overwritten #100

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.16.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<directory>${project.basedir}/target</directory>
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/teragrep/pth_06/config/ConditionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

import org.jooq.DSLContext;

import java.util.Objects;

public final class ConditionConfig {

private final DSLContext ctx;
Expand Down Expand Up @@ -105,16 +107,20 @@ public boolean streamQuery() {
return streamQuery;
}

//* DSLContext must be same instance to be equal */
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final ConditionConfig cast = (ConditionConfig) object;
return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery
&& this.withoutFilters == cast.withoutFilters && this.ctx == cast.ctx;
return bloomEnabled == cast.bloomEnabled && streamQuery == cast.streamQuery
&& withoutFilters == cast.withoutFilters && ctx == cast.ctx && bloomTermId == cast.bloomTermId;
}

@Override
public int hashCode() {
return Objects.hash(ctx, streamQuery, bloomEnabled, withoutFilters, bloomTermId);
}
}
16 changes: 11 additions & 5 deletions src/main/java/com/teragrep/pth_06/planner/CategoryTableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED;

/**
Expand Down Expand Up @@ -167,12 +169,16 @@ public QueryCondition bloommatchCondition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final CategoryTableImpl cast = (CategoryTableImpl) object;
return this.originTable.equals(cast.originTable) && this.ctx == cast.ctx && // equal only if same instance of DSLContext
this.bloomTermId == cast.bloomTermId && this.tableFilters.equals(cast.tableFilters);
return originTable.equals(cast.originTable) && ctx == cast.ctx && // equal only if same instance of DSLContext
bloomTermId == cast.bloomTermId && tableFilters.equals(cast.tableFilters)
&& tableCondition.equals(cast.tableCondition);
}

@Override
public int hashCode() {
return Objects.hash(ctx, originTable, bloomTermId, tableCondition, tableFilters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB;

Expand Down Expand Up @@ -111,11 +112,14 @@ public List<Table<?>> toList() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final PatternMatchTables cast = (PatternMatchTables) object;
return this.patternMatchCondition.equals(cast.patternMatchCondition) && this.ctx == cast.ctx; // only same instance of DSLContext is equal
return patternMatchCondition.equals(cast.patternMatchCondition) && ctx == cast.ctx; // only same instance of DSLContext is equal
}

@Override
public int hashCode() {
return Objects.hash(ctx, patternMatchCondition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.jooq.impl.DSL;
import org.jooq.types.ULong;

import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB;

/**
Expand Down Expand Up @@ -98,11 +100,14 @@ public Result<Record> toResult() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final TableFilterTypesFromMetadata cast = (TableFilterTypesFromMetadata) object;
return this.bloomTermId == cast.bloomTermId && this.table.equals(cast.table) && this.ctx == cast.ctx;
return bloomTermId == cast.bloomTermId && table.equals(cast.table) && ctx == cast.ctx;
}

@Override
public int hashCode() {
return Objects.hash(ctx, table, bloomTermId);
}
}
14 changes: 9 additions & 5 deletions src/main/java/com/teragrep/pth_06/planner/TableFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Objects;
import java.util.regex.Pattern;

import static com.teragrep.pth_06.jooq.generated.bloomdb.Bloomdb.BLOOMDB;
Expand Down Expand Up @@ -157,12 +158,15 @@ public void insertFiltersIntoCategoryTable() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final TableFilters cast = (TableFilters) object;
return this.ctx == cast.ctx && this.value.equals(cast.value) && this.table.equals(cast.table)
&& this.bloomTermId == cast.bloomTermId;
return ctx == cast.ctx && value.equals(cast.value) && table.equals(cast.table)
&& recordsInMetadata.equals(cast.recordsInMetadata) && bloomTermId == cast.bloomTermId;
}

@Override
public int hashCode() {
return Objects.hash(ctx, table, bloomTermId, value, recordsInMetadata);
}
}
12 changes: 8 additions & 4 deletions src/main/java/com/teragrep/pth_06/planner/TokenizedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public final class TokenizedValue {
Expand All @@ -71,11 +72,14 @@ public Set<Token> tokens() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final TokenizedValue cast = (TokenizedValue) object;
return this.value.equals(cast.value);
return value.equals(cast.value);
}

@Override
public int hashCode() {
return Objects.hash(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.jooq.impl.DSL;
import org.jooq.types.ULong;

import java.util.Objects;

import static org.jooq.impl.SQLDataType.BIGINTUNSIGNED;

/**
Expand Down Expand Up @@ -88,11 +90,14 @@ public Condition condition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final CategoryTableCondition cast = (CategoryTableCondition) object;
return this.bloomTermId == cast.bloomTermId && this.comparedTo.equals(cast.comparedTo);
return bloomTermId == cast.bloomTermId && comparedTo.equals(cast.comparedTo);
}

@Override
public int hashCode() {
return Objects.hash(comparedTo, bloomTermId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import java.sql.Date;
import java.time.Instant;
import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.journaldb.Journaldb.JOURNALDB;

Expand Down Expand Up @@ -89,11 +90,14 @@ public Condition condition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final EarliestCondition cast = (EarliestCondition) object;
return this.value.equals(cast.value);
return value.equals(cast.value);
}

@Override
public int hashCode() {
return Objects.hash(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;

import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -133,11 +134,14 @@ public Set<Table<?>> patternMatchTables() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final ElementCondition cast = (ElementCondition) object;
return this.element.equals(cast.element) && this.config.equals(cast.config);
return element.equals(cast.element) && config.equals(cast.config);
}

@Override
public int hashCode() {
return Objects.hash(element, config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import com.teragrep.pth_06.planner.StreamDBClient;
import org.jooq.Condition;

import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.streamdb.Streamdb.STREAMDB;

public final class HostCondition implements QueryCondition {
Expand Down Expand Up @@ -80,12 +82,14 @@ public Condition condition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final HostCondition cast = (HostCondition) object;
return this.streamQuery == cast.streamQuery && this.value.equals(cast.value)
&& this.operation.equals(cast.operation);
return streamQuery == cast.streamQuery && value.equals(cast.value) && operation.equals(cast.operation);
}

@Override
public int hashCode() {
return Objects.hash(value, operation, streamQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import com.teragrep.pth_06.planner.StreamDBClient;
import org.jooq.Condition;

import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.streamdb.Streamdb.STREAMDB;

public final class IndexCondition implements QueryCondition {
Expand Down Expand Up @@ -81,12 +83,14 @@ public Condition condition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final IndexCondition cast = (IndexCondition) object;
return this.streamQuery == cast.streamQuery && this.value.equals(cast.value)
&& this.operation.equals(cast.operation);
return streamQuery == cast.streamQuery && value.equals(cast.value) && operation.equals(cast.operation);
}

@Override
public int hashCode() {
return Objects.hash(value, operation, streamQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public final class IndexStatementCondition implements QueryCondition, BloomQueryCondition {
Expand Down Expand Up @@ -129,11 +130,15 @@ public Set<Table<?>> patternMatchTables() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final IndexStatementCondition cast = (IndexStatementCondition) object;
return this.value.equals(cast.value) && this.config.equals(cast.config);
return value.equals(cast.value) && config.equals(cast.config) && condition.equals(cast.condition)
&& tableSet.equals(cast.tableSet);
}

@Override
public int hashCode() {
return Objects.hash(value, config, condition, tableSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import java.sql.Date;
import java.time.Instant;
import java.util.Objects;

import static com.teragrep.pth_06.jooq.generated.journaldb.Journaldb.JOURNALDB;

Expand Down Expand Up @@ -86,11 +87,14 @@ public Condition condition() {
public boolean equals(final Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
if (object == null || object.getClass() != this.getClass())
return false;
final LatestCondition cast = (LatestCondition) object;
return this.value.equals(cast.value);
return value.equals(cast.value);
}

@Override
public int hashCode() {
return Objects.hash(value);
}
}
Loading