From 4d3675cb4e7a87184ce88d85889fe4c4203973da Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Wed, 6 Jan 2016 11:10:03 +0100 Subject: [PATCH] Consistent #equals() implementation Also dropped #hashCode(), as it just calls the parent class implementation. --- src/api/java/AST.java | 21 +++++++-------------- src/api/java/FuncDecl.java | 31 ++++++++++--------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/api/java/AST.java b/src/api/java/AST.java index 7bc2a79fc..ebb9fc18e 100644 --- a/src/api/java/AST.java +++ b/src/api/java/AST.java @@ -28,24 +28,17 @@ public class AST extends Z3Object implements Comparable * Object comparison. * * @param o another AST - **/ + **/ @Override public boolean equals(Object o) { - AST casted = null; + if (o == null) return false; + if (o == this) return true; + if (o.getClass() != this.getClass()) return false; + AST casted = (AST) o; - try - { - casted = AST.class.cast(o); - } catch (ClassCastException e) - { - return false; - } - - return (this == casted) || - (this != null) && - (casted != null) && - (getContext().nCtx() == casted.getContext().nCtx()) && + return + (getContext().nCtx() == casted.getContext().nCtx()) && (Native.isEqAst(getContext().nCtx(), getNativeObject(), casted.getNativeObject())); } diff --git a/src/api/java/FuncDecl.java b/src/api/java/FuncDecl.java index ac72c4012..762cc42a2 100644 --- a/src/api/java/FuncDecl.java +++ b/src/api/java/FuncDecl.java @@ -32,28 +32,17 @@ public class FuncDecl extends AST @Override public boolean equals(Object o) { - FuncDecl casted = null; + if (o == null) return false; + if (o == this) return true; + if (o.getClass() != this.getClass()) return false; + FuncDecl other = (FuncDecl) o; - try { - casted = FuncDecl.class.cast(o); - } catch (ClassCastException e) { - return false; - } - - return - (this == casted) || - (this != null) && - (casted != null) && - (getContext().nCtx() == casted.getContext().nCtx()) && - (Native.isEqFuncDecl(getContext().nCtx(), getNativeObject(), casted.getNativeObject())); - } - - /** - * A hash code. - **/ - public int hashCode() - { - return super.hashCode(); + return + (getContext().nCtx() == other.getContext().nCtx()) && + (Native.isEqFuncDecl( + getContext().nCtx(), + getNativeObject(), + other.getNativeObject())); } /**