Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Minor code optimizations

Imported some code optimizations from mebigfatguy
  • Loading branch information...
commit b26f4cb7741d9892c2197369a3a42771993a0ed8 1 parent 40ef19a
Carlos Tasada authored February 19, 2012
6  src/java/voldemort/VoldemortClientShell.java
@@ -365,10 +365,10 @@ private static void printObject(Object o) {
365 365
         } else if(o instanceof Map) {
366 366
             Map<String, Object> m = (Map<String, Object>) o;
367 367
             System.out.print('{');
368  
-            for(String s: m.keySet()) {
369  
-                printObject(s);
  368
+            for(Map.Entry<String, Object> entry : m.entrySet()) {
  369
+                printObject(entry.getKey());
370 370
                 System.out.print(':');
371  
-                printObject(m.get(s));
  371
+                printObject(entry.getValue());
372 372
                 System.out.print(", ");
373 373
             }
374 374
             System.out.print('}');
13  src/java/voldemort/client/protocol/admin/AdminClient.java
@@ -1890,9 +1890,8 @@ public String swapStore(int nodeId, String storeName, String storeDir) {
1890 1890
     public Map<String, Long> getROCurrentVersion(int nodeId, List<String> storeNames) {
1891 1891
         Map<String, Long> returnMap = Maps.newHashMapWithExpectedSize(storeNames.size());
1892 1892
         Map<String, String> versionDirs = getROCurrentVersionDir(nodeId, storeNames);
1893  
-        for(String storeName: versionDirs.keySet()) {
1894  
-            returnMap.put(storeName,
1895  
-                          ReadOnlyUtils.getVersionId(new File(versionDirs.get(storeName))));
  1893
+        for(Map.Entry<String, String> entry: versionDirs.entrySet()) {
  1894
+            returnMap.put(entry.getKey(), ReadOnlyUtils.getVersionId(new File(entry.getValue())));
1896 1895
         }
1897 1896
         return returnMap;
1898 1897
     }
@@ -1934,10 +1933,10 @@ public String swapStore(int nodeId, String storeName, String storeDir) {
1934 1933
 
1935 1934
         for(Node node: currentCluster.getNodes()) {
1936 1935
             Map<String, Long> currentNodeVersions = getROMaxVersion(node.getId(), storeNames);
1937  
-            for(String storeName: currentNodeVersions.keySet()) {
1938  
-                Long maxVersion = storeToMaxVersion.get(storeName);
1939  
-                if(maxVersion != null && maxVersion < currentNodeVersions.get(storeName)) {
1940  
-                    storeToMaxVersion.put(storeName, currentNodeVersions.get(storeName));
  1936
+            for(Map.Entry<String, Long> entry: currentNodeVersions.entrySet()) {
  1937
+                Long maxVersion = storeToMaxVersion.get(entry.getKey());
  1938
+                if(maxVersion != null && maxVersion < entry.getValue()) {
  1939
+                    storeToMaxVersion.put(entry.getKey(), entry.getValue());
1941 1940
                 }
1942 1941
             }
1943 1942
         }
5  src/java/voldemort/serialization/SerializerDefinition.java
@@ -73,7 +73,8 @@ public SerializerDefinition(String name,
73 73
             this.schemaInfoByVersion.put(0, schema);
74 74
         } else {
75 75
             int max = -1;
76  
-            for(Integer key: schemaInfos.keySet()) {
  76
+            for(Map.Entry<Integer, String> entry: schemaInfos.entrySet()) {
  77
+                Integer key = entry.getKey();
77 78
                 if(key < 0)
78 79
                     throw new IllegalArgumentException("Version cannot be less than 0.");
79 80
                 else if(key > Byte.MAX_VALUE)
@@ -81,7 +82,7 @@ else if(key > Byte.MAX_VALUE)
81 82
                                                        + Byte.MAX_VALUE);
82 83
                 if(key > max)
83 84
                     max = key;
84  
-                this.schemaInfoByVersion.put(key, schemaInfos.get(key));
  85
+                this.schemaInfoByVersion.put(key, entry.getValue());
85 86
             }
86 87
             this.currentSchemaVersion = max;
87 88
         }
6  src/java/voldemort/store/readonly/ReadOnlyStorageMetadata.java
@@ -94,9 +94,9 @@ public boolean equals(Object o) {
94 94
         else if(thisMap == null || thatMap == null)
95 95
             return false;
96 96
 
97  
-        for(String key: thisMap.keySet()) {
98  
-            Object thisValue = thisMap.get(key);
99  
-            Object thatValue = thatMap.get(key);
  97
+        for(Map.Entry<String,Object> entry: thisMap.entrySet()) {
  98
+            Object thisValue = entry.getValue();
  99
+            Object thatValue = thatMap.get(entry.getKey());
100 100
 
101 101
             if(thisValue == null && thatValue == null)
102 102
                 continue;
16  src/java/voldemort/xml/ClusterMapper.java
@@ -129,9 +129,11 @@ private Zone readZone(Element zone) {
129 129
         int zoneId = Integer.parseInt(zone.getChildText(ZONE_ID_ELMT));
130 130
         String proximityListTest = zone.getChildText(ZONE_PROXIMITY_LIST_ELMT).trim();
131 131
         LinkedList<Integer> proximityList = new LinkedList<Integer>();
132  
-        for(String node: Utils.COMMA_SEP.split(proximityListTest))
133  
-            if(node.trim().length() > 0)
134  
-                proximityList.add(Integer.parseInt(node.trim()));
  132
+        for(String node: Utils.COMMA_SEP.split(proximityListTest)) {
  133
+            node = node.trim();
  134
+            if(node.length() > 0)
  135
+                proximityList.add(Integer.parseInt(node));
  136
+        }
135 137
         return new Zone(zoneId, proximityList);
136 138
     }
137 139
 
@@ -148,9 +150,11 @@ public Node readServer(Element server) {
148 150
                                                                 : Zone.DEFAULT_ZONE_ID;
149 151
         String partitionsText = server.getChildText(SERVER_PARTITIONS_ELMT).trim();
150 152
         List<Integer> partitions = new ArrayList<Integer>();
151  
-        for(String aPartition: Utils.COMMA_SEP.split(partitionsText))
152  
-            if(aPartition.trim().length() > 0)
153  
-                partitions.add(Integer.parseInt(aPartition.trim()));
  153
+        for(String aPartition: Utils.COMMA_SEP.split(partitionsText)) {
  154
+            aPartition = aPartition.trim();
  155
+            if(aPartition.length() > 0)
  156
+                partitions.add(Integer.parseInt(aPartition));
  157
+        }
154 158
 
155 159
         return new Node(id, host, httpPort, socketPort, adminPort, zoneId, partitions);
156 160
     }
6  src/java/voldemort/xml/StoreDefinitionsMapper.java
@@ -422,10 +422,10 @@ private Element storeToElement(StoreDefinition storeDefinition) {
422 422
         HashMap<Integer, Integer> zoneReplicationFactor = storeDefinition.getZoneReplicationFactor();
423 423
         if(zoneReplicationFactor != null) {
424 424
             Element zoneReplicationFactorNode = new Element(STORE_ZONE_REPLICATION_FACTOR_ELMT);
425  
-            for(Integer zone: zoneReplicationFactor.keySet()) {
426  
-                zoneReplicationFactorNode.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(zoneReplicationFactor.get(zone)))
  425
+            for(Map.Entry<Integer, Integer> entry : zoneReplicationFactor.entrySet()) {
  426
+                zoneReplicationFactorNode.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(entry.getValue()))
427 427
                                                                                                .setAttribute(STORE_ZONE_ID_ELMT,
428  
-                                                                                                             Integer.toString(zone)));
  428
+                                                                                                             Integer.toString(entry.getKey())));
429 429
             }
430 430
             store.addContent(zoneReplicationFactorNode);
431 431
         }

0 notes on commit b26f4cb

Please sign in to comment.
Something went wrong with that request. Please try again.