helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-100] Clean up immutable return values
Date Wed, 02 Oct 2013 00:44:36 GMT
Updated Branches:
  refs/heads/helix-logical-model 73db45011 -> 45af07c85


[HELIX-100] Clean up immutable return values


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/45af07c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/45af07c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/45af07c8

Branch: refs/heads/helix-logical-model
Commit: 45af07c85d3dd45887aa4c83d871572fdb05ac24
Parents: 73db450
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Tue Oct 1 17:43:49 2013 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Tue Oct 1 17:43:49 2013 -0700

----------------------------------------------------------------------
 .../org/apache/helix/model/ExternalView.java    | 19 +++++------
 .../java/org/apache/helix/model/IdealState.java | 36 +++++++++-----------
 .../java/org/apache/helix/model/Message.java    |  8 ++---
 .../apache/helix/model/ResourceAssignment.java  |  4 +--
 .../helix/model/StateModelDefinition.java       |  4 +--
 5 files changed, 34 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/45af07c8/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/ExternalView.java b/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
index 77df3cf..15a22ca 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ExternalView.java
@@ -30,8 +30,8 @@ import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.api.id.ResourceId;
 
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 /**
  * External view is an aggregation (across all instances)
@@ -123,11 +123,11 @@ public class ExternalView extends HelixProperty {
    * @return a set of partition ids
    */
   public Set<PartitionId> getPartitionSet() {
-    ImmutableSet.Builder<PartitionId> builder = new ImmutableSet.Builder<PartitionId>();
+    Set<PartitionId> partitionSet = Sets.newHashSet();
     for (String partitionName : getPartitionStringSet()) {
-      builder.add(PartitionId.from(partitionName));
+      partitionSet.add(PartitionId.from(partitionName));
     }
-    return builder.build();
+    return partitionSet;
   }
 
   /**
@@ -149,13 +149,12 @@ public class ExternalView extends HelixProperty {
     if (rawStateMap == null) {
       return null;
     }
-    ImmutableMap.Builder<ParticipantId, State> builder =
-        new ImmutableMap.Builder<ParticipantId, State>();
+    Map<ParticipantId, State> stateMap = Maps.newHashMap();
     for (String participantName : rawStateMap.keySet()) {
-      builder
-          .put(ParticipantId.from(participantName), State.from(rawStateMap.get(participantName)));
+      stateMap.put(ParticipantId.from(participantName),
+          State.from(rawStateMap.get(participantName)));
     }
-    return builder.build();
+    return stateMap;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/45af07c8/helix-core/src/main/java/org/apache/helix/model/IdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/IdealState.java b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
index 5996391..8f579ec 100644
--- a/helix-core/src/main/java/org/apache/helix/model/IdealState.java
+++ b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
@@ -43,12 +43,11 @@ import org.apache.log4j.Logger;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Multimaps;
+import com.google.common.collect.Sets;
 
 /**
  * The ideal states of all partitions in a resource
@@ -294,14 +293,14 @@ public class IdealState extends HelixProperty {
 
   /**
    * Get all of the partitions
-   * @return an immutable set of partitions
+   * @return a set of partitions
    */
   public Set<PartitionId> getPartitionSet() {
-    ImmutableSet.Builder<PartitionId> partitionSetBuilder = new ImmutableSet.Builder<PartitionId>();
+    Set<PartitionId> partitionSet = Sets.newHashSet();
     for (String partitionName : getPartitionStringSet()) {
-      partitionSetBuilder.add(PartitionId.from(partitionName));
+      partitionSet.add(PartitionId.from(partitionName));
     }
-    return partitionSetBuilder.build();
+    return partitionSet;
   }
 
   /**
@@ -331,18 +330,17 @@ public class IdealState extends HelixProperty {
   /**
    * Get the current mapping of a partition
    * @param partitionId the name of the partition
-   * @return the instances where the replicas live and the state of each (immutable)
+   * @return the instances where the replicas live and the state of each
    */
   public Map<ParticipantId, State> getParticipantStateMap(PartitionId partitionId)
{
     Map<String, String> instanceStateMap = getInstanceStateMap(partitionId.stringify());
-    ImmutableMap.Builder<ParticipantId, State> builder =
-        new ImmutableMap.Builder<ParticipantId, State>();
+    Map<ParticipantId, State> participantStateMap = Maps.newHashMap();
     if (instanceStateMap != null) {
       for (String participantId : instanceStateMap.keySet()) {
-        builder.put(ParticipantId.from(participantId),
+        participantStateMap.put(ParticipantId.from(participantId),
             State.from(instanceStateMap.get(participantId)));
       }
-      return builder.build();
+      return participantStateMap;
     }
     return null;
   }
@@ -381,14 +379,14 @@ public class IdealState extends HelixProperty {
   /**
    * Get the participants who host replicas of a partition
    * @param partitionId the partition to look up
-   * @return immutable set of participant ids
+   * @return set of participant ids
    */
   public Set<ParticipantId> getParticipantSet(PartitionId partitionId) {
-    ImmutableSet.Builder<ParticipantId> builder = new ImmutableSet.Builder<ParticipantId>();
+    Set<ParticipantId> participantSet = Sets.newHashSet();
     for (String participantName : getInstanceSet(partitionId.stringify())) {
-      builder.add(ParticipantId.from(participantName));
+      participantSet.add(ParticipantId.from(participantName));
     }
-    return builder.build();
+    return participantSet;
   }
 
   /**
@@ -426,13 +424,13 @@ public class IdealState extends HelixProperty {
    * @return an ordered list of participants that can serve replicas of the partition
    */
   public List<ParticipantId> getPreferenceList(PartitionId partitionId) {
-    ImmutableList.Builder<ParticipantId> builder = new ImmutableList.Builder<ParticipantId>();
+    List<ParticipantId> preferenceList = Lists.newArrayList();
     List<String> preferenceStringList = getPreferenceList(partitionId.stringify());
     if (preferenceStringList != null) {
       for (String participantName : preferenceStringList) {
-        builder.add(ParticipantId.from(participantName));
+        preferenceList.add(ParticipantId.from(participantName));
       }
-      return builder.build();
+      return preferenceList;
     }
     return null;
   }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/45af07c8/helix-core/src/main/java/org/apache/helix/model/Message.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/Message.java b/helix-core/src/main/java/org/apache/helix/model/Message.java
index 71e9696..86319e3 100644
--- a/helix-core/src/main/java/org/apache/helix/model/Message.java
+++ b/helix-core/src/main/java/org/apache/helix/model/Message.java
@@ -44,7 +44,7 @@ import org.apache.helix.api.id.StateModelFactoryId;
 import org.apache.helix.controller.stages.ClusterEvent;
 import org.apache.helix.manager.zk.DefaultSchedulerMessageHandlerFactory;
 
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 
 /**
  * Messages sent internally among nodes in the system to respond to changes in state.
@@ -671,11 +671,11 @@ public class Message extends HelixProperty {
     if (partitionNames == null) {
       return Collections.emptyList();
     }
-    ImmutableList.Builder<PartitionId> builder = new ImmutableList.Builder<PartitionId>();
+    List<PartitionId> partitionIds = Lists.newArrayList();
     for (String partitionName : partitionNames) {
-      builder.add(PartitionId.from(partitionName));
+      partitionIds.add(PartitionId.from(partitionName));
     }
-    return builder.build();
+    return partitionIds;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/45af07c8/helix-core/src/main/java/org/apache/helix/model/ResourceAssignment.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/ResourceAssignment.java b/helix-core/src/main/java/org/apache/helix/model/ResourceAssignment.java
index c478e13..c91a655 100644
--- a/helix-core/src/main/java/org/apache/helix/model/ResourceAssignment.java
+++ b/helix-core/src/main/java/org/apache/helix/model/ResourceAssignment.java
@@ -73,7 +73,7 @@ public class ResourceAssignment extends HelixProperty {
 
   /**
    * Get the currently mapped partitions
-   * @return list of Partition objects
+   * @return list of Partition objects (immutable)
    */
   public List<? extends PartitionId> getMappedPartitions() {
     ImmutableList.Builder<PartitionId> builder = new ImmutableList.Builder<PartitionId>();
@@ -94,7 +94,7 @@ public class ResourceAssignment extends HelixProperty {
   /**
    * Get the participant, state pairs for a partition
    * @param partition the Partition to look up
-   * @return map of (participant id, state)
+   * @return immutable map of (participant id, state)
    */
   public Map<ParticipantId, State> getReplicaMap(PartitionId partitionId) {
     Map<String, String> rawReplicaMap = _record.getMapField(partitionId.stringify());

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/45af07c8/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
index 32ee2c7..af06ecc 100644
--- a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
+++ b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
@@ -159,7 +159,7 @@ public class StateModelDefinition extends HelixProperty {
 
   /**
    * Get an ordered priority list of transitions
-   * @return Transition objects, the first of which is highest priority
+   * @return Transition objects, the first of which is highest priority (immutable)
    */
   public List<Transition> getStateTransitionPriorityList() {
     ImmutableList.Builder<Transition> builder = new ImmutableList.Builder<Transition>();
@@ -179,7 +179,7 @@ public class StateModelDefinition extends HelixProperty {
 
   /**
    * Get an ordered priority list of states
-   * @return immutable list of states, the first of which is highest priority
+   * @return immutable list of states, the first of which is highest priority (immutable)
    */
   public List<State> getStatesPriorityList() {
     ImmutableList.Builder<State> builder = new ImmutableList.Builder<State>();


Mime
View raw message