From 23135fd03b17e311c41987a5cc37fc8de5bb7439 Mon Sep 17 00:00:00 2001 From: Zeeshan Asghar Date: Wed, 13 Jan 2016 14:46:07 +0500 Subject: [PATCH] squid:S1698 Object should be compared with equals() --- .../spy/memcached/DefaultConnectionFactory.java | 2 +- .../net/spy/memcached/KetamaNodeLocator.java | 2 +- .../net/spy/memcached/MemcachedConnection.java | 16 ++++++++-------- .../memcached/protocol/TCPMemcachedNodeImpl.java | 6 +++--- .../memcached/protocol/binary/OperationImpl.java | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java index bee0c4e30..d1c91c36f 100644 --- a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java +++ b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java @@ -438,7 +438,7 @@ public MetricCollector getMetricCollector() { } String enableMetrics = System.getProperty("net.spy.metrics.enable"); - if (enableMetrics().equals(MetricType.OFF) || enableMetrics == "false") { + if (MetricType.OFF.equals(enableMetrics()) || "false".equals(enableMetrics)) { getLogger().debug("Metric collection disabled."); metrics = new NoopMetricCollector(); } else { diff --git a/src/main/java/net/spy/memcached/KetamaNodeLocator.java b/src/main/java/net/spy/memcached/KetamaNodeLocator.java index 981dc2dec..fd80a7669 100644 --- a/src/main/java/net/spy/memcached/KetamaNodeLocator.java +++ b/src/main/java/net/spy/memcached/KetamaNodeLocator.java @@ -175,7 +175,7 @@ protected void setKetamaNodes(List nodes) { int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) { // Ketama does some special work with md5 where it reuses chunks. - if (hashAlg == DefaultHashAlgorithm.KETAMA_HASH) { + if (DefaultHashAlgorithm.KETAMA_HASH.equals(hashAlg)) { for (int i = 0; i < numReps / 4; i++) { byte[] digest = DefaultHashAlgorithm.computeMd5(config.getKeyForNode(node, i)); diff --git a/src/main/java/net/spy/memcached/MemcachedConnection.java b/src/main/java/net/spy/memcached/MemcachedConnection.java index 09f7c49ce..af7f0a102 100644 --- a/src/main/java/net/spy/memcached/MemcachedConnection.java +++ b/src/main/java/net/spy/memcached/MemcachedConnection.java @@ -863,7 +863,7 @@ private void readBufferAndLogMetrics(final Operation currentOp, getLogger().debug("Completed read op: %s and giving the next %d " + "bytes", currentOp, rbuf.remaining()); Operation op = node.removeCurrentReadOp(); - assert op == currentOp : "Expected to pop " + currentOp + " got " + assert op.equals(currentOp) : "Expected to pop " + currentOp + " got " + op; if (op.hasErrored()) { @@ -878,7 +878,7 @@ private void readBufferAndLogMetrics(final Operation currentOp, ((VBucketAware) currentOp).addNotMyVbucketNode( currentOp.getHandlingNode()); Operation op = node.removeCurrentReadOp(); - assert op == currentOp : "Expected to pop " + currentOp + " got " + assert op.equals(currentOp) : "Expected to pop " + currentOp + " got " + op; retryOps.add(currentOp); @@ -905,7 +905,7 @@ private Operation handleReadsWhenChannelEndOfStream(final Operation currentOp, getLogger().debug("Completed read op: %s and giving the next %d bytes", currentOp, rbuf.remaining()); Operation op = node.removeCurrentReadOp(); - assert op == currentOp : "Expected to pop " + currentOp + " got " + op; + assert op.equals(currentOp) : "Expected to pop " + currentOp + " got " + op; return node.getCurrentReadOp(); } else { throw new IOException("Disconnected unexpected, will reconnect."); @@ -1126,7 +1126,7 @@ private void attemptReconnects() { ops = SelectionKey.OP_CONNECT; } node.registerChannel(ch, ch.register(selector, ops, node)); - assert node.getChannel() == ch : "Channel was lost."; + assert node.getChannel().equals(ch) : "Channel was lost."; } else { getLogger().debug("Skipping duplicate reconnect request for %s", node); @@ -1247,7 +1247,7 @@ public void insertOperation(final MemcachedNode node, final Operation o) { metrics.markMeter(OVERALL_REQUEST_METRIC); Selector s = selector.wakeup(); - assert s == selector : "Wakeup returned the wrong selector."; + assert s.equals(selector) : "Wakeup returned the wrong selector."; getLogger().debug("Added %s to %s", o, node); } @@ -1269,7 +1269,7 @@ protected void addOperation(final MemcachedNode node, final Operation o) { metrics.markMeter(OVERALL_REQUEST_METRIC); Selector s = selector.wakeup(); - assert s == selector : "Wakeup returned the wrong selector."; + assert s.equals(selector) : "Wakeup returned the wrong selector."; getLogger().debug("Added %s to %s", o, node); } @@ -1315,7 +1315,7 @@ public CountDownLatch broadcastOperation(final BroadcastOpFactory of, } Selector s = selector.wakeup(); - assert s == selector : "Wakeup returned the wrong selector."; + assert s.equals(selector) : "Wakeup returned the wrong selector."; return latch; } @@ -1326,7 +1326,7 @@ public void shutdown() throws IOException { shutDown = true; try { Selector s = selector.wakeup(); - assert s == selector : "Wakeup returned the wrong selector."; + assert s.equals(selector) : "Wakeup returned the wrong selector."; for (MemcachedNode node : locator.getAll()) { if (node.getChannel() != null) { node.getChannel().close(); diff --git a/src/main/java/net/spy/memcached/protocol/TCPMemcachedNodeImpl.java b/src/main/java/net/spy/memcached/protocol/TCPMemcachedNodeImpl.java index 52deeb04b..c41cc06fa 100644 --- a/src/main/java/net/spy/memcached/protocol/TCPMemcachedNodeImpl.java +++ b/src/main/java/net/spy/memcached/protocol/TCPMemcachedNodeImpl.java @@ -154,7 +154,7 @@ public final void setupResend() { // to requeue them. while (hasReadOp()) { op = removeCurrentReadOp(); - if (op != getCurrentWriteOp()) { + if (!op.equals(getCurrentWriteOp())) { getLogger().warn("Discarding partially completed op: %s", op); op.cancel(); } @@ -240,11 +240,11 @@ private Operation getNextWritableOp() { if (o.isCancelled()) { getLogger().debug("Not writing cancelled op."); Operation cancelledOp = removeCurrentWriteOp(); - assert o == cancelledOp; + assert o.equals(cancelledOp); } else if (o.isTimedOut(defaultOpTimeout)) { getLogger().debug("Not writing timed out op."); Operation timedOutOp = removeCurrentWriteOp(); - assert o == timedOutOp; + assert o.equals(timedOutOp); } else { o.writing(); if (!(o instanceof TapAckOperationImpl)) { diff --git a/src/main/java/net/spy/memcached/protocol/binary/OperationImpl.java b/src/main/java/net/spy/memcached/protocol/binary/OperationImpl.java index a56463620..37152c8ed 100644 --- a/src/main/java/net/spy/memcached/protocol/binary/OperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/binary/OperationImpl.java @@ -333,7 +333,7 @@ protected void prepareBuffer(final String key, final long cas, int bufSize = MIN_RECV_PACKET + keyBytes.length + val.length; ByteBuffer bb = ByteBuffer.allocate(bufSize + extraLen); - assert bb.order() == ByteOrder.BIG_ENDIAN; + assert ByteOrder.BIG_ENDIAN.equals(bb.order()); bb.put(REQ_MAGIC); bb.put(cmd); bb.putShort((short) keyBytes.length);