mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Make equals and hashCode null schema safe
This commit is contained in:
parent
961e640662
commit
c851edd4e6
@ -15,6 +15,8 @@ package com.mysema.query.sql;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -41,7 +43,7 @@ public class SchemaAndTable implements Serializable {
|
||||
return true;
|
||||
} else if (o instanceof SchemaAndTable) {
|
||||
SchemaAndTable st = (SchemaAndTable)o;
|
||||
return st.schema.equals(schema) && st.table.equals(table);
|
||||
return Objects.equal(st.schema, schema) && Objects.equal(st.table, table);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -49,7 +51,7 @@ public class SchemaAndTable implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * schema.hashCode() + table.hashCode();
|
||||
return (schema != null ? 31 * schema.hashCode() : 0) + table.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SchemaAndTableTest {
|
||||
|
||||
@Test
|
||||
public void equalsAndHashCode() {
|
||||
SchemaAndTable st1 = new SchemaAndTable(null, "table");
|
||||
SchemaAndTable st2 = new SchemaAndTable(null, "table");
|
||||
assertEquals(st1, st2);
|
||||
assertEquals(st1.hashCode(), st2.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user