cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbros...@apache.org
Subject cassandra git commit: avoid npe chance, use == with enums
Date Sat, 15 Nov 2014 21:22:46 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 9c564f10f -> 2c3f9ba04


avoid npe chance, use == with enums


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2c3f9ba0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2c3f9ba0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2c3f9ba0

Branch: refs/heads/trunk
Commit: 2c3f9ba048af3f4f4bb144f7fdb41a84df5346e2
Parents: 9c564f1
Author: Dave Brosius <dbrosius@mebigfatguy.com>
Authored: Sat Nov 15 16:22:33 2014 -0500
Committer: Dave Brosius <dbrosius@mebigfatguy.com>
Committed: Sat Nov 15 16:22:33 2014 -0500

----------------------------------------------------------------------
 .../org/apache/cassandra/auth/DataResource.java | 10 +++---
 .../apache/cassandra/cache/CachingOptions.java  | 12 +++----
 .../org/apache/cassandra/config/CFMetaData.java |  2 +-
 .../apache/cassandra/cql3/ColumnCondition.java  | 34 ++++++++++----------
 .../cql3/statements/SelectStatement.java        |  4 +--
 .../org/apache/cassandra/db/DataTracker.java    |  2 +-
 .../apache/cassandra/service/ClientState.java   |  8 ++---
 .../cassandra/service/StorageService.java       |  6 ++--
 8 files changed, 40 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/auth/DataResource.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/DataResource.java b/src/java/org/apache/cassandra/auth/DataResource.java
index 9c7a777..75a3fdf 100644
--- a/src/java/org/apache/cassandra/auth/DataResource.java
+++ b/src/java/org/apache/cassandra/auth/DataResource.java
@@ -152,17 +152,17 @@ public class DataResource implements IResource
 
     public boolean isRootLevel()
     {
-        return level.equals(Level.ROOT);
+        return level == Level.ROOT;
     }
 
     public boolean isKeyspaceLevel()
     {
-        return level.equals(Level.KEYSPACE);
+        return level == Level.KEYSPACE;
     }
 
     public boolean isColumnFamilyLevel()
     {
-        return level.equals(Level.COLUMN_FAMILY);
+        return level == Level.COLUMN_FAMILY;
     }
     /**
      * @return keyspace of the resource. Throws IllegalStateException if it's the root-level
resource.
@@ -187,14 +187,16 @@ public class DataResource implements IResource
     /**
      * @return Whether or not the resource has a parent in the hierarchy.
      */
+    @Override
     public boolean hasParent()
     {
-        return !level.equals(Level.ROOT);
+        return level != Level.ROOT;
     }
 
     /**
      * @return Whether or not the resource exists in Cassandra.
      */
+    @Override
     public boolean exists()
     {
         switch (level)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/cache/CachingOptions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cache/CachingOptions.java b/src/java/org/apache/cassandra/cache/CachingOptions.java
index f9c7e64..c2605f5 100644
--- a/src/java/org/apache/cassandra/cache/CachingOptions.java
+++ b/src/java/org/apache/cassandra/cache/CachingOptions.java
@@ -188,7 +188,7 @@ public class CachingOptions
 
         public boolean isEnabled()
         {
-            return type.equals(Type.ALL);
+            return type == Type.ALL;
         }
 
         @Override
@@ -223,7 +223,7 @@ public class CachingOptions
 
         public RowCache(Type type)
         {
-            this(type, type.equals(Type.ALL) ? Integer.MAX_VALUE : 0);
+            this(type, (type == Type.ALL) ? Integer.MAX_VALUE : 0);
         }
         public RowCache(Type type, int rowsToCache)
         {
@@ -246,17 +246,17 @@ public class CachingOptions
         }
         public boolean isEnabled()
         {
-            return type.equals(Type.ALL) || type.equals(Type.HEAD);
+            return (type == Type.ALL) || (type == Type.HEAD);
         }
         public boolean cacheFullPartitions()
         {
-            return type.equals(Type.ALL);
+            return type == Type.ALL;
         }
         @Override
         public String toString()
         {
-            if (type.equals(Type.ALL)) return "ALL";
-            if (type.equals(Type.NONE)) return "NONE";
+            if (type == Type.ALL) return "ALL";
+            if (type == Type.NONE) return "NONE";
             return String.valueOf(rowsToCache);
         }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index 6073594..23c1b8b 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -815,7 +815,7 @@ public final class CFMetaData
             throw new ConfigurationException(String.format("Column family ID mismatch (found
%s; expected %s)",
                                                            cfm.cfId, cfId));
 
-        if (!cfm.cfType.equals(cfType))
+        if (cfm.cfType != cfType)
             throw new ConfigurationException("types do not match.");
 
         if (!cfm.comparator.isCompatibleWith(comparator))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/cql3/ColumnCondition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/ColumnCondition.java b/src/java/org/apache/cassandra/cql3/ColumnCondition.java
index 7daec02..a8c8cc2 100644
--- a/src/java/org/apache/cassandra/cql3/ColumnCondition.java
+++ b/src/java/org/apache/cassandra/cql3/ColumnCondition.java
@@ -59,7 +59,7 @@ public class ColumnCondition
         this.inValues = inValues;
         this.operator = op;
 
-        if (!operator.equals(Operator.IN))
+        if (operator != Operator.IN)
             assert this.inValues == null;
     }
 
@@ -117,7 +117,7 @@ public class ColumnCondition
         if (collectionElement != null)
             collectionElement.collectMarkerSpecification(boundNames);
 
-        if (operator.equals(Operator.IN) && inValues != null)
+        if ((operator == Operator.IN) && inValues != null)
         {
             for (Term value : inValues)
                 value.collectMarkerSpecification(boundNames);
@@ -130,7 +130,7 @@ public class ColumnCondition
 
     public ColumnCondition.Bound bind(QueryOptions options) throws InvalidRequestException
     {
-        boolean isInCondition = operator.equals(Operator.IN);
+        boolean isInCondition = operator == Operator.IN;
         if (column.type instanceof CollectionType)
         {
             if (collectionElement == null)
@@ -186,7 +186,7 @@ public class ColumnCondition
             else if (otherValue == null)
             {
                 // the condition value is not null, so only NEQ can return true
-                return operator.equals(Operator.NEQ);
+                return operator == Operator.NEQ;
             }
             int comparison = type.compare(otherValue, value);
             switch (operator)
@@ -236,7 +236,7 @@ public class ColumnCondition
         {
             super(condition.column, condition.operator);
             assert !(column.type instanceof CollectionType) && condition.collectionElement
== null;
-            assert !condition.operator.equals(Operator.IN);
+            assert condition.operator != Operator.IN;
             this.value = condition.value.bindAndGet(options);
         }
 
@@ -258,7 +258,7 @@ public class ColumnCondition
         {
             super(condition.column, condition.operator);
             assert !(column.type instanceof CollectionType) && condition.collectionElement
== null;
-            assert condition.operator.equals(Operator.IN);
+            assert condition.operator == Operator.IN;
             if (condition.inValues == null)
                 this.inValues = ((Lists.Marker) condition.value).bind(options).getElements();
             else
@@ -291,7 +291,7 @@ public class ColumnCondition
         {
             super(condition.column, condition.operator);
             assert column.type instanceof CollectionType && condition.collectionElement
!= null;
-            assert !condition.operator.equals(Operator.IN);
+            assert condition.operator != Operator.IN;
             this.collectionElement = condition.collectionElement.bindAndGet(options);
             this.value = condition.value.bindAndGet(options);
         }
@@ -468,7 +468,7 @@ public class ColumnCondition
         {
             super(condition.column, condition.operator);
             assert column.type.isCollection() && condition.collectionElement == null;
-            assert !condition.operator.equals(Operator.IN);
+            assert condition.operator != Operator.IN;
             this.value = condition.value.bind(options);
         }
 
@@ -481,9 +481,9 @@ public class ColumnCondition
                 Iterator<Cell> iter = collectionColumns(current.metadata().comparator.create(rowPrefix,
column), current, now);
                 if (value == null)
                 {
-                    if (operator.equals(Operator.EQ))
+                    if (operator == Operator.EQ)
                         return !iter.hasNext();
-                    else if (operator.equals(Operator.NEQ))
+                    else if (operator == Operator.NEQ)
                         return iter.hasNext();
                     else
                         throw new InvalidRequestException(String.format("Invalid comparison
with null for operator \"%s\"", operator));
@@ -535,7 +535,7 @@ public class ColumnCondition
             while(iter.hasNext())
             {
                 if (!conditionIter.hasNext())
-                    return operator.equals(Operator.GT) || operator.equals(Operator.GTE)
|| operator.equals(Operator.NEQ);
+                    return (operator == Operator.GT) || (operator == Operator.GTE) || (operator
== Operator.NEQ);
 
                 // for lists we use the cell value; for sets we use the cell name
                 ByteBuffer cellValue = isSet? iter.next().name().collectionElement() : iter.next().value();
@@ -545,7 +545,7 @@ public class ColumnCondition
             }
 
             if (conditionIter.hasNext())
-                return operator.equals(Operator.LT) || operator.equals(Operator.LTE) || operator.equals(Operator.NEQ);
+                return (operator == Operator.LT) || (operator == Operator.LTE) || (operator
== Operator.NEQ);
 
             // they're equal
             return operator == Operator.EQ || operator == Operator.LTE || operator == Operator.GTE;
@@ -590,7 +590,7 @@ public class ColumnCondition
             while(iter.hasNext())
             {
                 if (!conditionIter.hasNext())
-                    return operator.equals(Operator.GT) || operator.equals(Operator.GTE)
|| operator.equals(Operator.NEQ);
+                    return (operator == Operator.GT) || (operator == Operator.GTE) || (operator
== Operator.NEQ);
 
                 Map.Entry<ByteBuffer, ByteBuffer> conditionEntry = conditionIter.next();
                 Cell c = iter.next();
@@ -607,7 +607,7 @@ public class ColumnCondition
             }
 
             if (conditionIter.hasNext())
-                return operator.equals(Operator.LT) || operator.equals(Operator.LTE) || operator.equals(Operator.NEQ);
+                return (operator == Operator.LT) || (operator == Operator.LTE) || (operator
== Operator.NEQ);
 
             // they're equal
             return operator == Operator.EQ || operator == Operator.LTE || operator == Operator.GTE;
@@ -622,7 +622,7 @@ public class ColumnCondition
         {
             super(condition.column, condition.operator);
             assert column.type instanceof CollectionType && condition.collectionElement
== null;
-            assert condition.operator.equals(Operator.IN);
+            assert condition.operator == Operator.IN;
             inValues = new ArrayList<>();
             if (condition.inValues == null)
             {
@@ -768,7 +768,7 @@ public class ColumnCondition
 
             if (collectionElement == null)
             {
-                if (operator.equals(Operator.IN))
+                if (operator == Operator.IN)
                 {
                     if (inValues == null)
                         return ColumnCondition.inCondition(receiver, inMarker.prepare(keyspace,
receiver));
@@ -802,7 +802,7 @@ public class ColumnCondition
                 default:
                     throw new AssertionError();
             }
-            if (operator.equals(Operator.IN))
+            if (operator == Operator.IN)
             {
                 if (inValues == null)
                     return ColumnCondition.inCondition(receiver, collectionElement.prepare(keyspace,
elementSpec), inMarker.prepare(keyspace, valueSpec));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 621c4db..960abaa 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -1422,7 +1422,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
                         hasQueriableIndex |= queriable[0];
                         hasQueriableClusteringColumnIndex |= queriable[1];
                         names.add(def);
-                        hasMultiColumnRelations |= ColumnDefinition.Kind.CLUSTERING_COLUMN.equals(def.kind);
+                        hasMultiColumnRelations |= ColumnDefinition.Kind.CLUSTERING_COLUMN
== def.kind;
                     }
                     updateRestrictionsForRelation(stmt, names, rel, boundNames);
                 }
@@ -1434,7 +1434,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
                     boolean[] queriable = processRelationEntity(stmt, indexManager, relation,
entity, def);
                     hasQueriableIndex |= queriable[0];
                     hasQueriableClusteringColumnIndex |= queriable[1];
-                    hasSingleColumnRelations |= ColumnDefinition.Kind.CLUSTERING_COLUMN.equals(def.kind);
+                    hasSingleColumnRelations |= ColumnDefinition.Kind.CLUSTERING_COLUMN ==
def.kind;
                     updateRestrictionsForRelation(stmt, def, rel, boundNames);
                 }
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/db/DataTracker.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/DataTracker.java b/src/java/org/apache/cassandra/db/DataTracker.java
index 2799556..f8b9376 100644
--- a/src/java/org/apache/cassandra/db/DataTracker.java
+++ b/src/java/org/apache/cassandra/db/DataTracker.java
@@ -312,7 +312,7 @@ public class DataTracker
     public void replaceEarlyOpenedFiles(Collection<SSTableReader> toReplace, Collection<SSTableReader>
replaceWith)
     {
         for (SSTableReader s : toReplace)
-            assert s.openReason.equals(SSTableReader.OpenReason.EARLY);
+            assert s.openReason == SSTableReader.OpenReason.EARLY;
         // note that we can replace an early opened file with a real one
         replaceReaders(toReplace, replaceWith, false);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/service/ClientState.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/ClientState.java b/src/java/org/apache/cassandra/service/ClientState.java
index 6cc7254..9c8d7d8 100644
--- a/src/java/org/apache/cassandra/service/ClientState.java
+++ b/src/java/org/apache/cassandra/service/ClientState.java
@@ -235,10 +235,10 @@ public class ClientState
             return;
         validateLogin();
         preventSystemKSSchemaModification(keyspace, resource, perm);
-        if (perm.equals(Permission.SELECT) && READABLE_SYSTEM_RESOURCES.contains(resource))
+        if ((perm == Permission.SELECT) && READABLE_SYSTEM_RESOURCES.contains(resource))
             return;
         if (PROTECTED_AUTH_RESOURCES.contains(resource))
-            if (perm.equals(Permission.CREATE) || perm.equals(Permission.ALTER) || perm.equals(Permission.DROP))
+            if ((perm == Permission.CREATE) || (perm == Permission.ALTER) || (perm == Permission.DROP))
                 throw new UnauthorizedException(String.format("%s schema is protected", resource));
         ensureHasPermission(perm, resource);
     }
@@ -258,7 +258,7 @@ public class ClientState
     private void preventSystemKSSchemaModification(String keyspace, DataResource resource,
Permission perm) throws UnauthorizedException
     {
         // we only care about schema modification.
-        if (!(perm.equals(Permission.ALTER) || perm.equals(Permission.DROP) || perm.equals(Permission.CREATE)))
+        if (!((perm == Permission.ALTER) || (perm == Permission.DROP) || (perm == Permission.CREATE)))
             return;
 
         // prevent system keyspace modification
@@ -267,7 +267,7 @@ public class ClientState
 
         // we want to allow altering AUTH_KS and TRACING_KS.
         Set<String> allowAlter = Sets.newHashSet(Auth.AUTH_KS, TraceKeyspace.NAME);
-        if (allowAlter.contains(keyspace.toLowerCase()) && !(resource.isKeyspaceLevel()
&& perm.equals(Permission.ALTER)))
+        if (allowAlter.contains(keyspace.toLowerCase()) && !(resource.isKeyspaceLevel()
&& (perm == Permission.ALTER)))
             throw new UnauthorizedException(String.format("Cannot %s %s", perm, resource));
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2c3f9ba0/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index a0b7975..9cc643b 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -1335,7 +1335,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
      */
     public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value)
     {
-        if (state.equals(ApplicationState.STATUS))
+        if (state == ApplicationState.STATUS)
         {
             String apStateValue = value.value;
             String[] pieces = apStateValue.split(VersionedValue.DELIMITER_STR, -1);
@@ -2194,7 +2194,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
      */
     public void takeSnapshot(String tag, String... keyspaceNames) throws IOException
     {
-        if (operationMode.equals(Mode.JOINING))
+        if (operationMode == Mode.JOINING)
             throw new IOException("Cannot snapshot until bootstrap completes");
         if (tag == null || tag.equals(""))
             throw new IOException("You must supply a snapshot name.");
@@ -2233,7 +2233,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
     {
         if (keyspaceName == null)
             throw new IOException("You must supply a keyspace name");
-        if (operationMode.equals(Mode.JOINING))
+        if (operationMode == Mode.JOINING)
             throw new IOException("Cannot snapshot until bootstrap completes");
 
         if (columnFamilyName == null)


Mime
View raw message