Permalink
Browse files

Minor code optimizations

Imported some code optimizations from mebigfatguy
  • Loading branch information...
1 parent 40ef19a commit b26f4cb7741d9892c2197369a3a42771993a0ed8 @ctasada committed Feb 19, 2012
@@ -365,10 +365,10 @@ private static void printObject(Object o) {
} else if(o instanceof Map) {
Map<String, Object> m = (Map<String, Object>) o;
System.out.print('{');
- for(String s: m.keySet()) {
- printObject(s);
+ for(Map.Entry<String, Object> entry : m.entrySet()) {
+ printObject(entry.getKey());
System.out.print(':');
- printObject(m.get(s));
+ printObject(entry.getValue());
System.out.print(", ");
}
System.out.print('}');
@@ -1890,9 +1890,8 @@ public String swapStore(int nodeId, String storeName, String storeDir) {
public Map<String, Long> getROCurrentVersion(int nodeId, List<String> storeNames) {
Map<String, Long> returnMap = Maps.newHashMapWithExpectedSize(storeNames.size());
Map<String, String> versionDirs = getROCurrentVersionDir(nodeId, storeNames);
- for(String storeName: versionDirs.keySet()) {
- returnMap.put(storeName,
- ReadOnlyUtils.getVersionId(new File(versionDirs.get(storeName))));
+ for(Map.Entry<String, String> entry: versionDirs.entrySet()) {
+ returnMap.put(entry.getKey(), ReadOnlyUtils.getVersionId(new File(entry.getValue())));
}
return returnMap;
}
@@ -1934,10 +1933,10 @@ public String swapStore(int nodeId, String storeName, String storeDir) {
for(Node node: currentCluster.getNodes()) {
Map<String, Long> currentNodeVersions = getROMaxVersion(node.getId(), storeNames);
- for(String storeName: currentNodeVersions.keySet()) {
- Long maxVersion = storeToMaxVersion.get(storeName);
- if(maxVersion != null && maxVersion < currentNodeVersions.get(storeName)) {
- storeToMaxVersion.put(storeName, currentNodeVersions.get(storeName));
+ for(Map.Entry<String, Long> entry: currentNodeVersions.entrySet()) {
+ Long maxVersion = storeToMaxVersion.get(entry.getKey());
+ if(maxVersion != null && maxVersion < entry.getValue()) {
+ storeToMaxVersion.put(entry.getKey(), entry.getValue());
}
}
}
@@ -73,15 +73,16 @@ public SerializerDefinition(String name,
this.schemaInfoByVersion.put(0, schema);
} else {
int max = -1;
- for(Integer key: schemaInfos.keySet()) {
+ for(Map.Entry<Integer, String> entry: schemaInfos.entrySet()) {
+ Integer key = entry.getKey();
if(key < 0)
throw new IllegalArgumentException("Version cannot be less than 0.");
else if(key > Byte.MAX_VALUE)
throw new IllegalArgumentException("Version cannot be more than "
+ Byte.MAX_VALUE);
if(key > max)
max = key;
- this.schemaInfoByVersion.put(key, schemaInfos.get(key));
+ this.schemaInfoByVersion.put(key, entry.getValue());
}
this.currentSchemaVersion = max;
}
@@ -94,9 +94,9 @@ public boolean equals(Object o) {
else if(thisMap == null || thatMap == null)
return false;
- for(String key: thisMap.keySet()) {
- Object thisValue = thisMap.get(key);
- Object thatValue = thatMap.get(key);
+ for(Map.Entry<String,Object> entry: thisMap.entrySet()) {
+ Object thisValue = entry.getValue();
+ Object thatValue = thatMap.get(entry.getKey());
if(thisValue == null && thatValue == null)
continue;
@@ -129,9 +129,11 @@ private Zone readZone(Element zone) {
int zoneId = Integer.parseInt(zone.getChildText(ZONE_ID_ELMT));
String proximityListTest = zone.getChildText(ZONE_PROXIMITY_LIST_ELMT).trim();
LinkedList<Integer> proximityList = new LinkedList<Integer>();
- for(String node: Utils.COMMA_SEP.split(proximityListTest))
- if(node.trim().length() > 0)
- proximityList.add(Integer.parseInt(node.trim()));
+ for(String node: Utils.COMMA_SEP.split(proximityListTest)) {
+ node = node.trim();
+ if(node.length() > 0)
+ proximityList.add(Integer.parseInt(node));
+ }
return new Zone(zoneId, proximityList);
}
@@ -148,9 +150,11 @@ public Node readServer(Element server) {
: Zone.DEFAULT_ZONE_ID;
String partitionsText = server.getChildText(SERVER_PARTITIONS_ELMT).trim();
List<Integer> partitions = new ArrayList<Integer>();
- for(String aPartition: Utils.COMMA_SEP.split(partitionsText))
- if(aPartition.trim().length() > 0)
- partitions.add(Integer.parseInt(aPartition.trim()));
+ for(String aPartition: Utils.COMMA_SEP.split(partitionsText)) {
+ aPartition = aPartition.trim();
+ if(aPartition.length() > 0)
+ partitions.add(Integer.parseInt(aPartition));
+ }
return new Node(id, host, httpPort, socketPort, adminPort, zoneId, partitions);
}
@@ -422,10 +422,10 @@ private Element storeToElement(StoreDefinition storeDefinition) {
HashMap<Integer, Integer> zoneReplicationFactor = storeDefinition.getZoneReplicationFactor();
if(zoneReplicationFactor != null) {
Element zoneReplicationFactorNode = new Element(STORE_ZONE_REPLICATION_FACTOR_ELMT);
- for(Integer zone: zoneReplicationFactor.keySet()) {
- zoneReplicationFactorNode.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(zoneReplicationFactor.get(zone)))
+ for(Map.Entry<Integer, Integer> entry : zoneReplicationFactor.entrySet()) {
+ zoneReplicationFactorNode.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(entry.getValue()))
.setAttribute(STORE_ZONE_ID_ELMT,
- Integer.toString(zone)));
+ Integer.toString(entry.getKey())));
}
store.addContent(zoneReplicationFactorNode);
}

0 comments on commit b26f4cb

Please sign in to comment.