ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [05/50] [abbrv] incubator-ignite git commit: # Cleanup code: use Integer.compare() and Long.compare() in compareTo() methods.
Date Fri, 20 Mar 2015 15:48:00 GMT
# Cleanup code: use Integer.compare() and Long.compare() in compareTo() methods.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/58f0ec97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/58f0ec97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/58f0ec97

Branch: refs/heads/ignite-525
Commit: 58f0ec97c201890de95e25586278c4cc5b377e3e
Parents: 21e1f16
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Thu Mar 19 18:32:08 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Thu Mar 19 18:32:31 2015 +0300

----------------------------------------------------------------------
 .../client/GridClientPartitionAffinity.java     |  8 ++----
 .../processors/cache/GridCacheMapEntry.java     |  5 ++--
 .../processors/cache/GridCacheTtlManager.java   | 12 ++++-----
 .../distributed/dht/GridDhtLocalPartition.java  |  2 +-
 .../preloader/GridDhtPartitionExchangeId.java   |  2 --
 .../dht/preloader/GridDhtPartitionFullMap.java  |  8 ++++--
 .../dht/preloader/GridDhtPartitionMap.java      |  2 +-
 .../query/GridCacheDistributedQueryManager.java |  8 +++---
 .../cache/version/GridCacheVersion.java         | 19 +++++++------
 .../processors/clock/GridClockDeltaVersion.java | 10 +++----
 .../ignite/lang/IgniteProductVersion.java       | 28 +++++++++++---------
 .../java/org/apache/ignite/lang/IgniteUuid.java |  7 ++++-
 .../jobstealing/JobStealingCollisionSpi.java    |  2 +-
 .../tcp/internal/TcpDiscoveryNode.java          | 10 ++++---
 .../index/tree/StreamerTreeIndexProvider.java   |  5 +++-
 15 files changed, 71 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientPartitionAffinity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientPartitionAffinity.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientPartitionAffinity.java
index b747bc4..1cce940 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientPartitionAffinity.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientPartitionAffinity.java
@@ -349,12 +349,8 @@ public class GridClientPartitionAffinity implements GridClientDataAffinity,
Grid
         @Override public int compareTo(NodeInfo o) {
             int diff = nodeId.compareTo(o.nodeId);
 
-            if (diff == 0) {
-                int h1 = hashCode();
-                int h2 = o.hashCode();
-
-                diff = h1 == h2 ? 0 : (h1 < h2 ? -1 : 1);
-            }
+            if (diff == 0)
+                diff = Integer.compare(hashCode(), o.hashCode());
 
             return diff;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index f14a765..cbc16b6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -43,7 +43,6 @@ import javax.cache.processor.*;
 import java.io.*;
 import java.nio.*;
 import java.util.*;
-import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.events.EventType.*;
@@ -3756,11 +3755,11 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
 
     /** {@inheritDoc} */
     @Override public <K, V> Cache.Entry<K, V> wrapLazyValue() {
-        return new LazyValueEntry(key);
+        return new LazyValueEntry<>(key);
     }
 
     /** {@inheritDoc} */
-    @Nullable public CacheObject peekVisibleValue() {
+    @Override @Nullable public CacheObject peekVisibleValue() {
         try {
             IgniteInternalTx tx = cctx.tm().userTx();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
index 7bfdbfa..5198b53 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManager.java
@@ -183,14 +183,12 @@ public class GridCacheTtlManager extends GridCacheManagerAdapter {
 
         /** {@inheritDoc} */
         @Override public int compareTo(EntryWrapper o) {
-            if (expireTime == o.expireTime) {
-                if (entry.startVersion() == o.entry.startVersion())
-                    return 0;
+            int res = Long.compare(expireTime, o.expireTime);
 
-                return entry.startVersion() < o.entry.startVersion() ? -1 : 1;
-            }
-            else
-                return expireTime < o.expireTime ? -1 : 1;
+            if (res == 0)
+                res = Long.compare(entry.startVersion(), o.entry.startVersion());
+
+            return res;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index e142765..881cd9a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -587,7 +587,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>
         if (part == null)
             return 1;
 
-        return id == part.id() ? 0 : id > part.id() ? 1 : -1;
+        return Integer.compare(id, part.id());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
index 22910fd..8a3287c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionExchangeId.java
@@ -125,8 +125,6 @@ public class GridDhtPartitionExchangeId implements Message, Comparable<GridDhtPa
         if (o == this)
             return 0;
 
-
-
         return topVer.compareTo(o.topVer);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
index 2a513ca..d64b3e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
@@ -156,8 +156,12 @@ public class GridDhtPartitionFullMap extends HashMap<UUID, GridDhtPartitionMap>
         else if (nodeId == null && o.nodeId == null)
             return 0;
 
-        return nodeOrder < o.nodeOrder ? -1 : nodeOrder > o.nodeOrder ? 1 :
-            updateSeq < o.updateSeq ? -1 : updateSeq == o.updateSeq ? 0 : 1;
+        int res = Long.compare(nodeOrder, o.nodeOrder);
+
+        if (res == 0)
+            res = Long.compare(updateSeq, o.updateSeq);
+
+        return res;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
index 9108ee4..facf7e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
@@ -167,7 +167,7 @@ public class GridDhtPartitionMap implements Comparable<GridDhtPartitionMap>,
Ext
     @Override public int compareTo(GridDhtPartitionMap o) {
         assert nodeId.equals(o.nodeId);
 
-        return updateSeq < o.updateSeq ? -1 : updateSeq == o.updateSeq ? 0 : 1;
+        return Long.compare(updateSeq, o.updateSeq);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
index 27de8fc..058a95b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
@@ -747,10 +747,12 @@ public class GridCacheDistributedQueryManager<K, V> extends GridCacheQueryManage
 
         /** {@inheritDoc} */
         @Override public int compareTo(CancelMessageId m) {
-            if (m.reqId == reqId)
-                return m.nodeId.compareTo(nodeId);
+            int res = Long.compare(reqId, m.reqId);
 
-            return reqId < m.reqId ? -1 : 1;
+            if (res == 0)
+                res = m.nodeId.compareTo(nodeId);
+
+            return res;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java
index 84b7012..64eef99 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersion.java
@@ -230,14 +230,17 @@ public class GridCacheVersion implements Message, Comparable<GridCacheVersion>,
     /** {@inheritDoc} */
     @SuppressWarnings("IfMayBeConditional")
     @Override public int compareTo(GridCacheVersion other) {
-        if (topologyVersion() == other.topologyVersion()) {
-            if (order == other.order)
-                return nodeOrder() == other.nodeOrder() ? 0 : nodeOrder() < other.nodeOrder()
? -1 : 1;
-            else
-                return order < other.order ? -1 : 1;
-        }
-        else
-            return topologyVersion() < other.topologyVersion() ? -1 : 1;
+        int res = Integer.compare(topologyVersion(), other.topologyVersion());
+
+        if (res != 0)
+            return res;
+
+        res = Long.compare(order, other.order);
+
+        if (res != 0)
+            return res;
+
+        return Integer.compare(nodeOrder(), other.nodeOrder());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java
index 545f626..ffb02f7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaVersion.java
@@ -68,14 +68,12 @@ public class GridClockDeltaVersion implements Message, Comparable<GridClockDelta
 
     /** {@inheritDoc} */
     @Override public int compareTo(GridClockDeltaVersion o) {
-        if (topVer == o.topVer) {
-            if (ver == o.ver)
-                return 0;
+        int res = Long.compare(topVer, o.topVer);
 
-            return ver > o.ver ? 1 : -1;
-        }
+        if (res == 0)
+            res = Long.compare(ver, o.ver);
 
-        return topVer > o.topVer ? 1 : -1;
+        return res;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java
index e5f865d..034fb85 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteProductVersion.java
@@ -176,18 +176,22 @@ public class IgniteProductVersion implements Comparable<IgniteProductVersion>,
E
     /** {@inheritDoc} */
     @Override public int compareTo(@NotNull IgniteProductVersion o) {
         // NOTE: Unknown version is less than any other version.
-        if (major == o.major) {
-            if (minor == o.minor) {
-                if (maintenance == o.maintenance)
-                    return revTs != o.revTs ? revTs < o.revTs ? -1 : 1 : 0;
-                else
-                    return maintenance < o.maintenance ? -1 : 1;
-            }
-            else
-                return minor < o.minor ? -1 : 1;
-        }
-        else
-            return major < o.major ? -1 : 1;
+        int res = Integer.compare(major, o.major);
+
+        if (res != 0)
+            return res;
+
+        res = Integer.compare(minor, o.minor);
+
+        if (res != 0)
+            return res;
+
+        res = Integer.compare(maintenance, o.maintenance);
+
+        if (res != 0)
+            return res;
+
+        return Long.compare(revTs, o.revTs);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
index e36b21f..57e2c0d 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
@@ -172,7 +172,12 @@ public final class IgniteUuid implements Comparable<IgniteUuid>,
Iterable<Ignite
         if (o == null)
             return 1;
 
-        return locId < o.locId ? -1 : locId > o.locId ? 1 : gid.compareTo(o.globalId());
+        int res = Long.compare(locId, o.locId);
+
+        if (res == 0)
+            res = gid.compareTo(o.globalId());
+
+        return res;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingCollisionSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingCollisionSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingCollisionSpi.java
index ddb73a6..b4641fa 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingCollisionSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingCollisionSpi.java
@@ -815,7 +815,7 @@ public class JobStealingCollisionSpi extends IgniteSpiAdapter implements
Collisi
                     int p1 = getJobPriority(o1.getJobContext());
                     int p2 = getJobPriority(o2.getJobContext());
 
-                    return p1 < p2 ? 1 : p1 == p2 ? 0 : -1;
+                    return Integer.compare(p2, p1);
                 }
             };
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
index dfb30b7..450dd8c 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
@@ -378,11 +378,15 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements
Cluste
         if (node == null)
             return 1;
 
-        if (internalOrder() == node.internalOrder())
+        int res = Long.compare(internalOrder(), node.internalOrder());
+
+        if (res == 0) {
             assert id().equals(node.id()) : "Duplicate order [this=" + this + ", other="
+ node + ']';
 
-        return internalOrder() < node.internalOrder() ? -1 : internalOrder() > node.internalOrder()
? 1 :
-            id().compareTo(node.id());
+            res = id().compareTo(node.id());
+        }
+
+        return res;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58f0ec97/modules/core/src/main/java/org/apache/ignite/streamer/index/tree/StreamerTreeIndexProvider.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/streamer/index/tree/StreamerTreeIndexProvider.java
b/modules/core/src/main/java/org/apache/ignite/streamer/index/tree/StreamerTreeIndexProvider.java
index 9c17791..34fc2bb 100644
--- a/modules/core/src/main/java/org/apache/ignite/streamer/index/tree/StreamerTreeIndexProvider.java
+++ b/modules/core/src/main/java/org/apache/ignite/streamer/index/tree/StreamerTreeIndexProvider.java
@@ -509,7 +509,10 @@ public class StreamerTreeIndexProvider<E, K, V> extends StreamerIndexProviderAda
         @Override public int compareTo(Key<V> o) {
             int res = cmp != null ? cmp.compare(val, o.val) : ((Comparable<V>)val).compareTo(o.val);
 
-            return res == 0 ? (seed < o.seed ? -1 : seed > o.seed ? 1 : 0) : res;
+            if (res == 0)
+                res = Long.compare(seed, o.seed);
+
+            return res;
         }
 
         /** {@inheritDoc} */


Mime
View raw message