From 3ce415e106263b8f2765859ecd1739cfd7c4dbc3 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 6 Jan 2011 09:15:11 -0500 Subject: [PATCH] Java's equality is stupid --- java/hop/ServerApi.java | 2 +- java/hop/SexpBytes.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/java/hop/ServerApi.java b/java/hop/ServerApi.java index 3520442..f0205d4 100644 --- a/java/hop/ServerApi.java +++ b/java/hop/ServerApi.java @@ -59,7 +59,7 @@ public class ServerApi { public synchronized Object create(String nodeClassName, Object arg) throws InterruptedException, SexpSyntaxError { send("factory", SexpMessage.create(nodeClassName, arg, _container.getName(), _kName)); SexpList reply = _nextReply(); - String selector = reply.getBytes(0).getDataString(); + SexpBytes selector = reply.getBytes(0); if (selector.equals(SexpMessage._create_ok)) return null; assert selector.equals(SexpMessage._create_failed); return reply.get(1); diff --git a/java/hop/SexpBytes.java b/java/hop/SexpBytes.java index a168d64..1385e56 100644 --- a/java/hop/SexpBytes.java +++ b/java/hop/SexpBytes.java @@ -6,6 +6,7 @@ package hop; import java.io.IOException; import java.io.OutputStream; +import java.util.Arrays; /** */ @@ -31,4 +32,13 @@ public class SexpBytes { public String toString() { return SexpWriter.writeString(this); } + + public boolean equals(Object other) { + return (other instanceof SexpBytes) && + Arrays.equals(_bytes, ((SexpBytes) other).getData()); + } + + public int hashCode() { + return Arrays.hashCode(_bytes); + } }