move AM model classes to java 7 language features

git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1595941 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
index 37f2bd7..087bf63 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java
@@ -132,7 +132,7 @@
    * Client properties created via the provider -static for the life
    * of the application
    */
-  private Map<String, String> clientProperties = new HashMap<String, String>();
+  private Map<String, String> clientProperties = new HashMap<>();
 
   /**
    The cluster description published to callers
@@ -147,10 +147,10 @@
 
 
   private final Map<Integer, RoleStatus> roleStatusMap =
-    new ConcurrentHashMap<Integer, RoleStatus>();
+    new ConcurrentHashMap<>();
 
   private final Map<String, ProviderRole> roles =
-    new ConcurrentHashMap<String, ProviderRole>();
+    new ConcurrentHashMap<>();
 
   /**
    * The master node.
@@ -162,7 +162,7 @@
    * been allocated but are not live; it is a superset of the live list
    */
   private final ConcurrentMap<ContainerId, RoleInstance> activeContainers =
-    new ConcurrentHashMap<ContainerId, RoleInstance>();
+    new ConcurrentHashMap<>();
 
   /**
    * Hash map of the containers we have released, but we
@@ -170,7 +170,7 @@
    * containers is treated as a successful outcome
    */
   private final ConcurrentMap<ContainerId, Container> containersBeingReleased =
-    new ConcurrentHashMap<ContainerId, Container>();
+    new ConcurrentHashMap<>();
   
   /**
    * Counter for completed containers ( complete denotes successful or failed )
@@ -205,34 +205,34 @@
    * the node is promoted from here to the containerMap
    */
   private final Map<ContainerId, RoleInstance> startingNodes =
-    new ConcurrentHashMap<ContainerId, RoleInstance>();
+    new ConcurrentHashMap<>();
 
   /**
    * List of completed nodes. This isn't kept in the CD as it gets too
    * big for the RPC responses. Indeed, we should think about how deep to get this
    */
   private final Map<ContainerId, RoleInstance> completedNodes
-    = new ConcurrentHashMap<ContainerId, RoleInstance>();
+    = new ConcurrentHashMap<>();
 
   /**
    * Nodes that failed to start.
    * Again, kept out of the CD
    */
   private final Map<ContainerId, RoleInstance> failedNodes =
-    new ConcurrentHashMap<ContainerId, RoleInstance>();
+    new ConcurrentHashMap<>();
 
   /**
    * Nodes that came assigned to a role above that
    * which were asked for -this appears to happen
    */
-  private final Set<ContainerId> surplusNodes = new HashSet<ContainerId>();
+  private final Set<ContainerId> surplusNodes = new HashSet<>();
 
   /**
    * Map of containerID -> cluster nodes, for status reports.
    * Access to this should be synchronized on the clusterDescription
    */
   private final Map<ContainerId, RoleInstance> liveNodes =
-    new ConcurrentHashMap<ContainerId, RoleInstance>();
+    new ConcurrentHashMap<>();
   private final AtomicInteger completionOfNodeNotInLiveListEvent =
     new AtomicInteger();
   private final AtomicInteger completionOfUnknownContainerEvent =
@@ -464,7 +464,7 @@
     this.applicationInfo = applicationInfo != null ? applicationInfo 
                                          : new HashMap<String, String>();
 
-    clientProperties = new HashMap<String, String>();
+    clientProperties = new HashMap<>();
 
 
     Set<String> confKeys = ConfigHelper.sortedConfigKeys(publishedProviderConf);
@@ -778,7 +778,7 @@
   @Override
   public synchronized List<RoleInstance> cloneActiveContainerList() {
     Collection<RoleInstance> values = activeContainers.values();
-    return new ArrayList<RoleInstance>(values);
+    return new ArrayList<>(values);
   }
   
   @Override
@@ -795,7 +795,7 @@
   public synchronized List<RoleInstance> cloneLiveContainerInfoList() {
     List<RoleInstance> allRoleInstances;
     Collection<RoleInstance> values = getLiveNodes().values();
-    allRoleInstances = new ArrayList<RoleInstance>(values);
+    allRoleInstances = new ArrayList<>(values);
     return allRoleInstances;
   }
 
@@ -818,7 +818,7 @@
     Collection<String> containerIDs) {
     //first, a hashmap of those containerIDs is built up
     Set<String> uuidSet = new HashSet<String>(containerIDs);
-    List<RoleInstance> nodes = new ArrayList<RoleInstance>(uuidSet.size());
+    List<RoleInstance> nodes = new ArrayList<>(uuidSet.size());
     Collection<RoleInstance> clusterNodes = getLiveNodes().values();
 
     for (RoleInstance node : clusterNodes) {
@@ -836,7 +836,7 @@
    * @return a list of nodes, may be empty
    */
   public synchronized List<RoleInstance> enumLiveNodesInRole(String role) {
-    List<RoleInstance> nodes = new ArrayList<RoleInstance>();
+    List<RoleInstance> nodes = new ArrayList<>();
     Collection<RoleInstance> allRoleInstances = getLiveNodes().values();
     for (RoleInstance node : allRoleInstances) {
       if (role.isEmpty() || role.equals(node.role)) {
@@ -852,11 +852,11 @@
    * @return the map of Role name to list of role instances
    */
   private synchronized Map<String, List<String>> createRoleToInstanceMap() {
-    Map<String, List<String>> map = new HashMap<String, List<String>>();
+    Map<String, List<String>> map = new HashMap<>();
     for (RoleInstance node : getLiveNodes().values()) {
       List<String> containers = map.get(node.role);
       if (containers == null) {
-        containers = new ArrayList<String>();
+        containers = new ArrayList<>();
         map.put(node.role, containers);
       }
       containers.add(node.id);
@@ -868,13 +868,12 @@
    * @return the map of Role name to list of Cluster Nodes, ready
    */
   private synchronized Map<String, Map<String, ClusterNode>> createRoleToClusterNodeMap() {
-    Map<String, Map<String, ClusterNode>> map =
-      new HashMap<String, Map<String, ClusterNode>>();
+    Map<String, Map<String, ClusterNode>> map = new HashMap<>();
     for (RoleInstance node : getLiveNodes().values()) {
       
       Map<String, ClusterNode> containers = map.get(node.role);
       if (containers == null) {
-        containers = new HashMap<String, ClusterNode>();
+        containers = new HashMap<>();
         map.put(node.role, containers);
       }
       Messages.RoleInstanceState pbuf = node.toProtobuf();
@@ -1226,7 +1225,7 @@
             String user = null;
             try {
               user = SliderUtils.getCurrentUser().getShortUserName();
-            } catch (IOException ioe) {
+            } catch (IOException ignored) {
             }
             String completedLogsUrl = null;
             Container c = roleInstance.container;
@@ -1335,7 +1334,7 @@
     MapOperations infoOps = new MapOperations("info",cd.info);
     infoOps.mergeWithoutOverwrite(applicationInfo);
     SliderUtils.addBuildInfo(infoOps, "status");
-    cd.statistics = new HashMap<String, Map<String, Integer>>();
+    cd.statistics = new HashMap<>();
 
     // build the map of node -> container IDs
     Map<String, List<String>> instanceMap = createRoleToInstanceMap();
@@ -1344,7 +1343,7 @@
     //build the map of node -> containers
     Map<String, Map<String, ClusterNode>> clusterNodes =
       createRoleToClusterNodeMap();
-    cd.status = new HashMap<String, Object>();
+    cd.status = new HashMap<>();
     cd.status.put(ClusterDescriptionKeys.KEY_CLUSTER_LIVE, clusterNodes);
 
 
@@ -1363,7 +1362,7 @@
       cd.statistics.put(rolename, stats);
     }
 
-    Map<String, Integer> sliderstats = new HashMap<String, Integer>();
+    Map<String, Integer> sliderstats = new HashMap<>();
     sliderstats.put(StatusKeys.STATISTICS_CONTAINERS_COMPLETED,
         completedContainerCount.get());
     sliderstats.put(StatusKeys.STATISTICS_CONTAINERS_FAILED,
@@ -1387,8 +1386,7 @@
   public synchronized List<AbstractRMOperation> reviewRequestAndReleaseNodes()
       throws SliderInternalStateException, TriggerClusterTeardownException {
     log.debug("in reviewRequestAndReleaseNodes()");
-    List<AbstractRMOperation> allOperations =
-      new ArrayList<AbstractRMOperation>();
+    List<AbstractRMOperation> allOperations = new ArrayList<>();
     for (RoleStatus roleStatus : getRoleStatusMap().values()) {
       if (!roleStatus.getExcludeFromFlexing()) {
         List<AbstractRMOperation> operations = reviewOneRole(roleStatus);
@@ -1426,7 +1424,7 @@
    */
   public List<AbstractRMOperation> reviewOneRole(RoleStatus role)
       throws SliderInternalStateException, TriggerClusterTeardownException {
-    List<AbstractRMOperation> operations = new ArrayList<AbstractRMOperation>();
+    List<AbstractRMOperation> operations = new ArrayList<>();
     int delta;
     String details;
     int expected;
@@ -1520,7 +1518,7 @@
     Collection<RoleInstance> targets = cloneActiveContainerList();
     log.info("Releasing {} containers", targets.size());
     List<AbstractRMOperation> operations =
-      new ArrayList<AbstractRMOperation>(targets.size());
+      new ArrayList<>(targets.size());
     for (RoleInstance instance : targets) {
       Container possible = instance.container;
       ContainerId id = possible.getId();
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
index 66513d9..06375fb 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeInstance.java
@@ -41,7 +41,7 @@
    */
   public NodeInstance(String hostname, int roles) {
     this.hostname = hostname;
-    nodeEntries = new ArrayList<NodeEntry>(roles);
+    nodeEntries = new ArrayList<>(roles);
   }
 
   /**
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeMap.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeMap.java
index c638843..32b1656 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeMap.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/NodeMap.java
@@ -73,7 +73,7 @@
    * in that role
    */
   public List<NodeInstance> listActiveNodes(int role) {
-    List<NodeInstance> nodes = new ArrayList<NodeInstance>();
+    List<NodeInstance> nodes = new ArrayList<>();
     for (NodeInstance instance : values()) {
       if (instance.getActiveRoleInstances(role) > 0) {
         nodes.add(instance);
@@ -113,9 +113,9 @@
    * @return a possibly empty list of nodes.
    */
   public List<NodeInstance> findNodesForRelease(int role, int count) {
-    List<NodeInstance> targets = new ArrayList<NodeInstance>(count);
+    List<NodeInstance> targets = new ArrayList<>(count);
     List<NodeInstance> active = listActiveNodes(role);
-    List<NodeInstance> multiple = new ArrayList<NodeInstance>();
+    List<NodeInstance> multiple = new ArrayList<>();
     int nodesRemaining = count;
     log.debug("searching for {} nodes with candidate set size {}",
               nodesRemaining, active.size());
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequest.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequest.java
index f75df56..7d3e427 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequest.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequest.java
@@ -57,7 +57,7 @@
   public final String hostname;
 
   /**
-   * requested time -only valid after {@link #buildContainerRequest(Resource, long)}
+   * requested time -only valid after buildContainerRequest(Resource, long)}
    */
   public long requestedTime;
 
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequestTracker.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequestTracker.java
index d847962..fa2c754 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequestTracker.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/OutstandingRequestTracker.java
@@ -43,7 +43,7 @@
     LoggerFactory.getLogger(OutstandingRequestTracker.class);
 
   private Map<OutstandingRequest, OutstandingRequest> requests =
-    new HashMap<OutstandingRequest, OutstandingRequest>();
+    new HashMap<>();
 
   /**
    * Create a new request for the specific role. If a
@@ -161,7 +161,7 @@
    * @return possibly empty list of hostnames
    */
   public synchronized List<NodeInstance> cancelOutstandingRequests(int role) {
-    List<NodeInstance> hosts = new ArrayList<NodeInstance>();
+    List<NodeInstance> hosts = new ArrayList<>();
     Iterator<Map.Entry<OutstandingRequest,OutstandingRequest>> iterator =
       requests.entrySet().iterator();
     while (iterator.hasNext()) {
@@ -178,6 +178,6 @@
   }
   
   public synchronized List<OutstandingRequest> listOutstandingRequests() {
-    return new ArrayList<OutstandingRequest>(requests.values());
+    return new ArrayList<>(requests.values());
   }
 }
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
index fa22676..68e7693 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleHistory.java
@@ -60,7 +60,7 @@
     LoggerFactory.getLogger(RoleHistory.class);
   private final List<ProviderRole> providerRoles;
   private final Map<String, ProviderRole> providerRoleMap =
-    new HashMap<String, ProviderRole>();
+    new HashMap<>();
   private long startTime;
   /**
    * Time when saved
@@ -109,7 +109,7 @@
 
     resetAvailableNodeLists();
     outstandingRequests = new OutstandingRequestTracker();
-    Map<Integer, RoleStatus> roleStats = new HashMap<Integer, RoleStatus>();
+    Map<Integer, RoleStatus> roleStats = new HashMap<>();
 
 
     for (ProviderRole providerRole : providerRoles) {
@@ -141,7 +141,7 @@
    */
   public void addNewProviderRole(ProviderRole providerRole)
     throws BadConfigException {
-    Map<Integer, RoleStatus> roleStats = new HashMap<Integer, RoleStatus>();
+    Map<Integer, RoleStatus> roleStats = new HashMap<>();
 
 
     for (ProviderRole role : providerRoles) {
@@ -155,7 +155,7 @@
    * Clear the lists of available nodes
    */
   private synchronized void resetAvailableNodeLists() {
-    availableNodes = new HashMap<Integer, LinkedList<NodeInstance>>(roleSize);
+    availableNodes = new HashMap<>(roleSize);
   }
 
   /**
@@ -431,8 +431,8 @@
    */
   private LinkedList<NodeInstance> getOrCreateNodesForRoleId(int id) {
     LinkedList<NodeInstance> instances = availableNodes.get(id);
-    if (instances==null) {
-      instances = new LinkedList<NodeInstance>();
+    if (instances == null) {
+      instances = new LinkedList<>();
       availableNodes.put(id, instances);
     }
     return instances;
@@ -544,8 +544,8 @@
   }
 
   /**
-   * Get the node instance of a an address if defined
-   * @param addr address
+   * Get the node instance of a host if defined
+   * @param hostname hostname to look up
    * @return a node instance or null
    */
   public synchronized NodeInstance getExistingNodeInstance(String hostname) {
@@ -565,7 +565,7 @@
     List<Container> requested =
       new ArrayList<Container>(allocatedContainers.size());
     List<Container> unrequested =
-      new ArrayList<Container>(allocatedContainers.size());
+      new ArrayList<>(allocatedContainers.size());
     outstandingRequests.partitionRequests(this, allocatedContainers, requested, unrequested);
     
     //give the unrequested ones lower priority
@@ -742,7 +742,7 @@
    */
   @VisibleForTesting
   public List<NodeInstance> cloneAvailableList(int role) {
-    return new LinkedList<NodeInstance>(getOrCreateNodesForRoleId(role));
+    return new LinkedList<>(getOrCreateNodesForRoleId(role));
   }
 
   /**
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
index 962606e..205edea 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleInstance.java
@@ -18,6 +18,7 @@
 
 package org.apache.slider.server.appmaster.state;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.yarn.api.records.Container;
 import org.apache.hadoop.yarn.api.records.ContainerId;
 import org.apache.hadoop.yarn.api.records.NodeId;
@@ -88,13 +89,11 @@
   public Object providerInfo;
 
   public RoleInstance(Container container) {
+    Preconditions.checkNotNull(container, "Null container");
+    Preconditions.checkState(container.getId() != null, 
+      "Null container ID");
+
     this.container = container;
-    if (container == null) {
-      throw new NullPointerException("Null container");
-    }
-    if (container.getId() == null) {
-      throw new NullPointerException("Null container ID");
-    }
     id = container.getId().toString();
     if (container.getNodeId() != null) {
       host = container.getNodeId().getHost();
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleStatus.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleStatus.java
index 169253b..04d8b37 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleStatus.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/RoleStatus.java
@@ -246,7 +246,7 @@
    * @return a map for use in statistics reports
    */
   public Map<String, Integer> buildStatistics() {
-    Map<String, Integer> stats = new HashMap<String, Integer>();
+    Map<String, Integer> stats = new HashMap<>();
     stats.put(StatusKeys.STATISTICS_CONTAINERS_ACTIVE_REQUESTS, getRequested());
     stats.put(StatusKeys.STATISTICS_CONTAINERS_COMPLETED, getCompleted());
     stats.put(StatusKeys.STATISTICS_CONTAINERS_DESIRED, getDesired());