public
Description: Cassandra is a distributed storage system for managing structured data while providing reliability at a massive scale
Homepage: http://code.google.com/p/the-cassandra-project/
Clone URL: git://github.com/tmm1/cassandra-mirror.git
Summary: It's possible that JVMs are smart enough to optimize this, but if 
not,
.isEmpty() is always O(1) whereas computing .size() and comparing against 
0
can be O(n) in a lot of cases.

Issue: CASSANDRA-17

Author: tlipcon

Reviewer: jeff.hammerbacher



git-svn-id: http://the-cassandra-project.googlecode.com/svn/trunk@62 
fb539927-1251-0410-86c0-f5eed957eeac
jeff.hammerbacher (author)
Mon Jul 21 21:52:23 -0700 2008
commit  314b160b367654df4cd0e1431580956cfd1b17f4
tree    41f7e8d97f00fa81154e18cb3523b7059abab2d1
parent  804c9cfdbe7ba621aaf1567e7e8bf4d290ad4cbf
...
134
135
136
137
 
138
139
140
...
134
135
136
 
137
138
139
140
0
@@ -134,7 +134,7 @@ public class BinaryMemtable implements MemtableMBean
0
     */
0
     void flush() throws IOException
0
     {
0
- if ( columnFamilies_.size() == 0 )
0
+ if ( columnFamilies_.isEmpty() )
0
             return;
0
         ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
0
         String directory = DatabaseDescriptor.getDataFileLocation();
...
152
153
154
155
 
156
157
158
...
371
372
373
374
 
375
376
377
...
152
153
154
 
155
156
157
158
...
371
372
373
 
374
375
376
377
0
@@ -152,7 +152,7 @@ public final class ColumnFamily implements Serializable
0
         if ( columnType == null )
0
         {
0
           List<String> tables = DatabaseDescriptor.getTables();
0
- if ( tables.size() > 0 )
0
+ if ( !tables.isEmpty() )
0
           {
0
             String table = tables.get(0);
0
             columnType = Table.open(table).getColumnFamilyType(name_);
0
@@ -371,7 +371,7 @@ public final class ColumnFamily implements Serializable
0
             }
0
           }
0
         }
0
- if(cfDiff.getColumns().size() != 0)
0
+ if(!cfDiff.getColumns().isEmpty())
0
           return cfDiff;
0
         else
0
           return null;
...
125
126
127
128
 
129
130
131
...
197
198
199
200
 
201
202
203
...
738
739
740
741
 
742
743
744
...
1106
1107
1108
1109
 
1110
1111
1112
...
1120
1121
1122
1123
 
1124
1125
1126
 
1127
1128
1129
...
1337
1338
1339
1340
 
1341
1342
1343
...
1348
1349
1350
1351
 
1352
1353
1354
...
1364
1365
1366
1367
 
1368
1369
1370
 
1371
1372
1373
...
125
126
127
 
128
129
130
131
...
197
198
199
 
200
201
202
203
...
738
739
740
 
741
742
743
744
...
1106
1107
1108
 
1109
1110
1111
1112
...
1120
1121
1122
 
1123
1124
1125
 
1126
1127
1128
1129
...
1337
1338
1339
 
1340
1341
1342
1343
...
1348
1349
1350
 
1351
1352
1353
1354
...
1364
1365
1366
 
1367
1368
1369
 
1370
1371
1372
1373
0
@@ -125,7 +125,7 @@ public class ColumnFamilyStore
0
             }
0
         }
0
         Collections.sort(indices);
0
- int value = (indices.size() > 0) ? (indices.get(indices.size() - 1)) : 0;
0
+ int value = (!indices.isEmpty()) ? (indices.get(indices.size() - 1)) : 0;
0
         fileIndexGenerator_.set(value);
0
         memtable_ = new AtomicReference<Memtable>( new Memtable(table_, columnFamily_) );
0
         binaryMemtable_ = new AtomicReference<BinaryMemtable>( new BinaryMemtable(table_, columnFamily_) );
0
@@ -197,7 +197,7 @@ public class ColumnFamilyStore
0
          * no files on disk we do not want to display
0
          * something ugly on the admin page.
0
         */
0
- if ( ssTables_.size() == 0 )
0
+ if ( ssTables_.isEmpty() )
0
         {
0
             return sb.toString();
0
         }
0
@@ -738,7 +738,7 @@ public class ColumnFamilyStore
0
         PriorityQueue<FileStruct> pq = new PriorityQueue<FileStruct>();
0
         long bytesread = -1;
0
 
0
- if (files.size() > 1 || (ranges != null && files.size() > 0))
0
+ if (files.size() > 1 || (ranges != null && !files.isEmpty()))
0
         {
0
             int bufferSize = Math.min( (ColumnFamilyStore.compactionMemoryThreshold_ / files.size()), minBufferSize ) ;
0
             FileStruct fs = null;
0
@@ -1106,7 +1106,7 @@ public class ColumnFamilyStore
0
    return null;
0
    }
0
    PriorityQueue<FileStruct> pq = initializePriorityQueue(files, ranges, minBufferSize);
0
- if (pq.size() > 0)
0
+ if (!pq.isEmpty())
0
    {
0
    mergedFileName = getTempFileName();
0
    SSTable ssTableRange = null ;
0
@@ -1120,10 +1120,10 @@ public class ColumnFamilyStore
0
    BloomFilter compactedRangeBloomFilter = new BloomFilter(expectedBloomFilterSize, 8);
0
    List<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>();
0
 
0
- while (pq.size() > 0 || lfs.size() > 0)
0
+ while (!pq.isEmpty() || !lfs.isEmpty())
0
    {
0
    FileStruct fs = null;
0
- if (pq.size() > 0)
0
+ if (!pq.isEmpty())
0
    {
0
    fs = pq.poll();
0
    }
0
@@ -1337,7 +1337,7 @@ public class ColumnFamilyStore
0
    // If the compaction file path is null that means we have no space left for this compaction.
0
    if( compactionFileLocation == null )
0
    {
0
- if( ranges == null || ranges.size() == 0)
0
+ if( ranges == null || ranges.isEmpty() )
0
      {
0
        String maxFile = getMaxSizeFile( files );
0
        files.remove( maxFile );
0
@@ -1348,7 +1348,7 @@ public class ColumnFamilyStore
0
    return null;
0
    }
0
    PriorityQueue<FileStruct> pq = initializePriorityQueue(files, ranges, minBufferSize);
0
- if (pq.size() > 0)
0
+ if (!pq.isEmpty())
0
    {
0
    String mergedFileName = getTempFileName();
0
    SSTable ssTable = null;
0
@@ -1364,10 +1364,10 @@ public class ColumnFamilyStore
0
    BloomFilter compactedRangeBloomFilter = new BloomFilter(expectedBloomFilterSize, 8);
0
    List<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>();
0
 
0
- while (pq.size() > 0 || lfs.size() > 0)
0
+ while (!pq.isEmpty() || lfs.isEmpty())
0
    {
0
    FileStruct fs = null;
0
- if (pq.size() > 0)
0
+ if (!pq.isEmpty())
0
    {
0
    fs = pq.poll();
0
    }
...
366
367
368
369
 
370
371
372
...
366
367
368
 
369
370
371
372
0
@@ -366,7 +366,7 @@ public class Memtable implements MemtableMBean
0
     void flush(CommitLog.CommitLogContext cLogCtx) throws IOException
0
     {
0
         ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
0
- if ( columnFamilies_.size() == 0 )
0
+ if ( columnFamilies_.isEmpty() )
0
         {
0
           // This should be called even if size is 0
0
           // This is because we should try to delete the useless commitlogs
...
66
67
68
69
 
70
71
72
...
66
67
68
 
69
70
71
72
0
@@ -66,7 +66,7 @@ public class ReadVerbHandler implements IVerbHandler
0
               row = table.get(readMessage.key());
0
             else
0
             {
0
- if(readMessage.getColumnNames().size() == 0)
0
+ if(readMessage.getColumnNames().isEmpty())
0
               {
0
      if(readMessage.count() > 0 && readMessage.start() >= 0)
0
        row = table.getRow(readMessage.key(), readMessage.columnFamily_column(), readMessage.start(), readMessage.count());
...
97
98
99
100
 
101
102
103
...
173
174
175
176
 
177
178
179
...
97
98
99
 
100
101
102
103
...
173
174
175
 
176
177
178
179
0
@@ -97,7 +97,7 @@ public class Row implements Serializable
0
 
0
     public boolean isEmpty()
0
     {
0
- return ( columnFamilies_.size() == 0 );
0
+ return ( columnFamilies_.isEmpty() );
0
     }
0
 
0
     /*
0
@@ -173,7 +173,7 @@ public class Row implements Serializable
0
                 rowDiff.getColumnFamilies().put(cfName, cfDiff);
0
             }
0
         }
0
- if(rowDiff.getColumnFamilies().size() != 0)
0
+ if(!rowDiff.getColumnFamilies().isEmpty())
0
           return rowDiff;
0
         else
0
           return null;
...
293
294
295
296
 
297
298
299
...
293
294
295
 
296
297
298
299
0
@@ -293,7 +293,7 @@ public final class SuperColumn implements IColumn, Serializable
0
             }
0
           }
0
         }
0
- if(columnDiff.getSubColumns().size() != 0)
0
+ if(!columnDiff.getSubColumns().isEmpty())
0
           return columnDiff;
0
         else
0
           return null;
...
419
420
421
422
423
 
424
 
425
426
427
...
453
454
455
456
 
457
458
459
...
1072
1073
1074
1075
 
1076
1077
1078
...
419
420
421
 
 
422
423
424
425
426
427
...
453
454
455
 
456
457
458
459
...
1072
1073
1074
 
1075
1076
1077
1078
0
@@ -419,9 +419,9 @@ public class Gossiper implements IFailureDetectionEventListener, IEndPointStateC
0
      */
0
     boolean doGossipToLiveMember(Message message)
0
     {
0
- int size = liveEndpoints_.size();
0
- if ( size == 0 )
0
+ if (liveEndpoints_.isEmpty())
0
             return false;
0
+
0
         // return sendGossipToLiveNode(message);
0
         /* Use this for a cluster size >= 30 */
0
         return sendGossip(message, liveEndpoints_);
0
@@ -453,7 +453,7 @@ public class Gossiper implements IFailureDetectionEventListener, IEndPointStateC
0
                 return;
0
             }
0
 
0
- if ( liveEndpoints_.size() == 0 )
0
+ if ( liveEndpoints_.isEmpty() )
0
             {
0
                 sendGossip(message, seeds_);
0
             }
0
@@ -1072,7 +1072,7 @@ class GossipDigestAckVerbHandler implements IVerbHandler
0
             List<GossipDigest> gDigestList = gDigestAckMessage.getGossipDigestList();
0
             Map<EndPoint, EndPointState> epStateMap = gDigestAckMessage.getEndPointStateMap();
0
             
0
- if ( epStateMap.size() > 0 )
0
+ if ( !epStateMap.isEmpty() )
0
             {
0
                 /* Notify the Failure Detector */
0
                 Gossiper.instance().notifyFailureDetector(epStateMap);
...
48
49
50
51
 
52
53
54
...
48
49
50
 
51
52
53
54
0
@@ -48,7 +48,7 @@ public class IndexHelper
0
   public static void serialize(int indexSizeInBytes, List<ColumnPositionInfo> columnIndexList, DataOutputStream dos) throws IOException
0
   {
0
     /* if we have no data to index, the write that there is no index present */
0
- if(indexSizeInBytes == 0 || columnIndexList == null || columnIndexList.size() == 0)
0
+ if(indexSizeInBytes == 0 || columnIndexList == null || columnIndexList.isEmpty() )
0
     {
0
       dos.writeBoolean(false);
0
     }
...
886
887
888
889
 
890
891
892
...
1504
1505
1506
1507
 
1508
1509
1510
...
886
887
888
 
889
890
891
892
...
1504
1505
1506
 
1507
1508
1509
1510
0
@@ -886,7 +886,7 @@ public class SequenceFile
0
    bufOut.write(file_, dataSize);
0
                     }
0
                     /* if we need to read the all the columns do not read the column indexes */
0
- else if(columnNames == null || columnNames.size() == 0)
0
+ else if(columnNames == null || columnNames.isEmpty() )
0
                     {
0
                       int bytesSkipped = IndexHelper.skip(file_);
0
    /*
0
@@ -1504,7 +1504,7 @@ public class SequenceFile
0
                         bufOut.write(buffer_, dataSize);
0
                     }
0
                     /* if we need to read the all the columns do not read the column indexes */
0
- else if(columnNames == null || columnNames.size() == 0)
0
+ else if(columnNames == null || columnNames.isEmpty() )
0
                     {
0
                         int bytesSkipped = IndexHelper.skip(buffer_);
0
                         /*
...
358
359
360
361
 
362
363
364
...
416
417
418
419
 
420
421
422
...
461
462
463
464
 
465
466
467
...
489
490
491
492
 
493
494
495
...
536
537
538
539
 
540
541
542
...
564
565
566
567
 
568
569
570
...
607
608
609
610
 
611
612
613
...
635
636
637
638
 
639
640
641
...
794
795
796
797
 
798
799
800
...
811
812
813
814
 
815
816
817
...
825
826
827
828
 
829
830
831
...
867
868
869
870
 
871
872
873
...
884
885
886
887
 
888
889
890
...
898
899
900
901
 
902
903
904
...
358
359
360
 
361
362
363
364
...
416
417
418
 
419
420
421
422
...
461
462
463
 
464
465
466
467
...
489
490
491
 
492
493
494
495
...
536
537
538
 
539
540
541
542
...
564
565
566
 
567
568
569
570
...
607
608
609
 
610
611
612
613
...
635
636
637
 
638
639
640
641
...
794
795
796
 
797
798
799
800
...
811
812
813
 
814
815
816
817
...
825
826
827
 
828
829
830
831
...
867
868
869
 
870
871
872
873
...
884
885
886
 
887
888
889
890
...
898
899
900
 
901
902
903
904
0
@@ -358,7 +358,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
      * Do the consistency checks in the background and return the
0
      * non NULL row.
0
      */
0
- if ( endpoints.size() > 0 )
0
+ if ( !endpoints.isEmpty() )
0
       StorageService.instance().doConsistencyCheck(row, endpoints, columnFamily, columns);
0
     return row;
0
   }
0
@@ -416,7 +416,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
 
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty())
0
       {
0
         logger_  .info("ERROR ColumnFamily " + columnFamily + " map is missing.....: "
0
                + " key:" + key
0
@@ -461,7 +461,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       }
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty() )
0
       {
0
         logger_  .info("ERROR ColumnFamily " + columnFamily_column + " map is missing.....: "
0
                + " key:" + key
0
@@ -489,7 +489,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       {
0
         columns = cfamily.getAllColumns();
0
       }
0
- if (columns == null || columns.size() == 0)
0
+ if (columns == null || columns.isEmpty() )
0
       {
0
         logger_  .info("ERROR Columns are missing.....: "
0
                + " key:" + key
0
@@ -536,7 +536,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       }
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty() )
0
       {
0
         logger_  .info("ERROR ColumnFamily map is missing.....: "
0
                + " key:" + key
0
@@ -564,7 +564,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       {
0
         columns = cfamily.getAllColumns();
0
       }
0
- if (columns == null || columns.size() == 0)
0
+ if (columns == null || columns.isEmpty() )
0
       {
0
         logger_  .info("ERROR Columns are missing.....: "
0
                + " key:" + key
0
@@ -607,7 +607,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       }
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty() )
0
       {
0
         logger_  .info("ERROR ColumnFamily map is missing.....: "
0
                + " key:" + key
0
@@ -635,7 +635,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       {
0
         columns = cfamily.getAllColumns();
0
       }
0
- if (columns == null || columns.size() == 0)
0
+ if (columns == null || columns.isEmpty() )
0
       {
0
         logger_  .info("ERROR Columns are missing.....: "
0
                + " key:" + key
0
@@ -794,7 +794,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       }
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty() )
0
       {
0
         logger_  .info("ERROR ColumnFamily map is missing.....: "
0
                + " key:" + key
0
@@ -811,7 +811,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
         return retlist;
0
       }
0
       Collection<IColumn> columns = cfamily.getAllColumns();
0
- if (columns == null || columns.size() == 0)
0
+ if (columns == null || columns.isEmpty() )
0
       {
0
         logger_  .info("ERROR Columns are missing.....: "
0
                + " key:" + key
0
@@ -825,7 +825,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
         superColumn_t thrift_superColumn = new superColumn_t();
0
         thrift_superColumn.name = column.name();
0
         Collection<IColumn> subColumns = column.getSubColumns();
0
- if(subColumns.size() != 0 )
0
+ if( !subColumns.isEmpty() )
0
         {
0
           thrift_superColumn.columns = new ArrayList<column_t>();
0
           for( IColumn subColumn : subColumns )
0
@@ -867,7 +867,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
       }
0
 
0
       Map<String, ColumnFamily> cfMap = row.getColumnFamilies();
0
- if (cfMap == null || cfMap.size() == 0)
0
+ if (cfMap == null || cfMap.isEmpty() )
0
       {
0
         logger_  .info("ERROR ColumnFamily map is missing.....: "
0
                + " key:" + key
0
@@ -884,7 +884,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
         return ret;
0
       }
0
       Collection<IColumn> columns = cfamily.getAllColumns();
0
- if (columns == null || columns.size() == 0)
0
+ if (columns == null || columns.isEmpty() )
0
       {
0
         logger_  .info("ERROR Columns are missing.....: "
0
                + " key:" + key
0
@@ -898,7 +898,7 @@ public class CassandraImpl extends FacebookBase implements Cassandra.Iface
0
         ret = new superColumn_t();
0
         ret.name = column.name();
0
         Collection<IColumn> subColumns = column.getSubColumns();
0
- if(subColumns.size() != 0 )
0
+ if( !subColumns.isEmpty() )
0
         {
0
           ret.columns = new ArrayList<column_t>();
0
           for(IColumn subColumn : subColumns)
...
170
171
172
173
 
174
175
176
...
170
171
172
 
173
174
175
176
0
@@ -170,7 +170,7 @@ class ConsistencyManager implements Runnable
0
     logger_.debug(" Run the consistency checks for " + columnFamily_);
0
     String table = DatabaseDescriptor.getTables().get(0);
0
     ReadMessage readMessageDigestOnly = null;
0
- if(columnNames_.size() == 0)
0
+ if(columnNames_.isEmpty() )
0
     {
0
       if( start_ >= 0 && count_ < Integer.MAX_VALUE)
0
       {
...
115
116
117
118
 
119
120
121
122
123
124
125
 
126
127
 
128
129
130
...
115
116
117
 
118
119
120
121
122
123
124
 
125
126
 
127
128
129
130
0
@@ -115,16 +115,16 @@ public class ReadResponseResolver implements IResponseResolver<Row>
0
     }
0
     
0
         /* If the rowList is empty then we had some exception above. */
0
- if ( rowList.size() == 0 )
0
+ if ( rowList.isEmpty() )
0
         {
0
             return retRow;
0
         }
0
         
0
         /* Now calculate the resolved row */
0
     retRow = new Row(key);    
0
- for (int i = 0 ; i < rowList.size(); i++)
0
+ for (Row row : rowList)
0
     {
0
- retRow.repair(rowList.get(i));
0
+ retRow.repair(row);
0
     }
0
         // At this point we have the return row.
0
     // Now we need to calculate the differnce
...
495
496
497
498
 
499
500
501
...
495
496
497
 
498
499
500
501
0
@@ -495,7 +495,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
0
         */
0
         private void doTransfer(EndPoint target, List<Range> ranges) throws IOException
0
         {
0
- if ( ranges.size() == 0 )
0
+ if ( ranges.isEmpty() )
0
             {
0
                 logger_.debug("No ranges to give scram ...");
0
                 return;

Comments

    No one has commented yet.