[jOOQ/jOOQ#11867] Improve internal equals() and hashCode() implementations
This commit is contained in:
parent
b50ec7169f
commit
99322b54aa
@ -47,6 +47,7 @@ import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Name;
|
||||
@ -387,11 +388,7 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((userType == null) ? 0 : userType.hashCode());
|
||||
return result;
|
||||
return Objects.hash(type, userType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -49,6 +49,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.tools.JooqLogger;
|
||||
@ -438,51 +439,5 @@ public class DefaultRelations implements Relations {
|
||||
/**
|
||||
* A simple local wrapper for a key definition (table + key name)
|
||||
*/
|
||||
private static class Key {
|
||||
final TableDefinition table;
|
||||
final String keyName;
|
||||
|
||||
Key(TableDefinition table, String keyName) {
|
||||
this.table = table;
|
||||
this.keyName = keyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Key [table=" + table + ", keyName=" + keyName + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((keyName == null) ? 0 : keyName.hashCode());
|
||||
result = prime * result + ((table == null) ? 0 : table.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Key other = (Key) obj;
|
||||
if (keyName == null) {
|
||||
if (other.keyName != null)
|
||||
return false;
|
||||
}
|
||||
else if (!keyName.equals(other.keyName))
|
||||
return false;
|
||||
if (table == null) {
|
||||
if (other.table != null)
|
||||
return false;
|
||||
}
|
||||
else if (!table.equals(other.table))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static final /* record */ class Key { private final TableDefinition table; private final String keyName; public Key(TableDefinition table, String keyName) { this.table = table; this.keyName = keyName; } public TableDefinition table() { return table; } public String keyName() { return keyName; } @Override public boolean equals(Object o) { if (!(o instanceof Key)) return false; Key other = (Key) o; if (!java.util.Objects.equals(this.table, other.table)) return false; if (!java.util.Objects.equals(this.keyName, other.keyName)) return false; return true; } @Override public int hashCode() { return java.util.Objects.hash(this.table, this.keyName); } @Override public String toString() { return new StringBuilder("Key[").append("table=").append(this.table).append(", keyName=").append(this.keyName).append("]").toString(); } }
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ package org.jooq;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -338,13 +339,7 @@ public final class TableOptions implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((onCommit == null) ? 0 : onCommit.hashCode());
|
||||
result = prime * result + ((select == null) ? 0 : select.hashCode());
|
||||
result = prime * result + ((source == null) ? 0 : source.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
return Objects.hash(onCommit, select, source, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -356,23 +351,10 @@ public final class TableOptions implements Serializable {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TableOptions other = (TableOptions) obj;
|
||||
if (onCommit != other.onCommit)
|
||||
return false;
|
||||
if (select == null) {
|
||||
if (other.select != null)
|
||||
return false;
|
||||
}
|
||||
else if (!select.equals(other.select))
|
||||
return false;
|
||||
if (source == null) {
|
||||
if (other.source != null)
|
||||
return false;
|
||||
}
|
||||
else if (!source.equals(other.source))
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
return true;
|
||||
return onCommit == other.onCommit
|
||||
&& Objects.equals(select, other.select)
|
||||
&& Objects.equals(source, other.source)
|
||||
&& type == other.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -41,6 +41,7 @@ import static org.jooq.impl.Tools.anyMatch;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jooq.Constraint;
|
||||
import org.jooq.ConstraintEnforcementStep;
|
||||
@ -120,11 +121,7 @@ abstract class AbstractKey<R extends Record> extends AbstractNamed implements Ke
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + getQualifiedName().hashCode();
|
||||
result = prime * result + ((table == null) ? 0 : table.hashCode());
|
||||
return result;
|
||||
return Objects.hash(getQualifiedName(), table);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jooq.Check;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Constraint;
|
||||
@ -100,8 +102,7 @@ final class CheckImpl<R extends Record> extends AbstractNamed implements Check<R
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((condition == null) ? 0 : condition.hashCode());
|
||||
result = prime * result + ((table == null) ? 0 : table.hashCode());
|
||||
result = prime * result + Objects.hash(getQualifiedName(), condition, table);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -114,21 +115,9 @@ final class CheckImpl<R extends Record> extends AbstractNamed implements Check<R
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CheckImpl<?> other = (CheckImpl<?>) obj;
|
||||
if (!getQualifiedName().equals(other.getQualifiedName()))
|
||||
return false;
|
||||
if (condition == null) {
|
||||
if (other.condition != null)
|
||||
return false;
|
||||
}
|
||||
else if (!condition.equals(other.condition))
|
||||
return false;
|
||||
if (table == null) {
|
||||
if (other.table != null)
|
||||
return false;
|
||||
}
|
||||
else if (!table.equals(other.table))
|
||||
return false;
|
||||
return true;
|
||||
return Objects.equals(getQualifiedName(), other.getQualifiedName())
|
||||
&& Objects.equals(condition, other.condition)
|
||||
&& Objects.equals(table, other.table);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -209,6 +209,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
@ -3691,10 +3692,7 @@ final class Tools {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((method == null) ? 0 : method.getName().hashCode());
|
||||
return result;
|
||||
return Objects.hashCode(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -55,6 +55,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Meta;
|
||||
@ -233,10 +234,7 @@ final class VersionImpl extends AbstractNode<Version> implements Version {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id() == null) ? 0 : id().hashCode());
|
||||
return result;
|
||||
return Objects.hash(id());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -248,13 +246,7 @@ final class VersionImpl extends AbstractNode<Version> implements Version {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VersionImpl other = (VersionImpl) obj;
|
||||
if (id() == null) {
|
||||
if (other.id() != null)
|
||||
return false;
|
||||
}
|
||||
else if (!id().equals(other.id()))
|
||||
return false;
|
||||
return true;
|
||||
return Objects.equals(id(), other.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user