IDE review of tools package

git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1595993 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/ConfigHelper.java b/slider-core/src/main/java/org/apache/slider/common/tools/ConfigHelper.java
index 9884bdd..ff3fd52 100644
--- a/slider-core/src/main/java/org/apache/slider/common/tools/ConfigHelper.java
+++ b/slider-core/src/main/java/org/apache/slider/common/tools/ConfigHelper.java
@@ -77,10 +77,11 @@
   /**
    * Take a configuration and return a sorted set
    * @param conf config
-   * @return
+   * @return the sorted keyset
+
    */
   public static TreeSet<String> sortedConfigKeys(Iterable<Map.Entry<String, String>> conf) {
-    TreeSet<String> sorted = new TreeSet<String>();
+    TreeSet<String> sorted = new TreeSet<>();
     for (Map.Entry<String, String> entry : conf) {
       sorted.add(entry.getKey());
     }
@@ -183,28 +184,19 @@
                                                 IOException {
     int len = (int) fs.getLength(path);
     byte[] data = new byte[len];
-    FSDataInputStream in = fs.open(path);
-    try {
+    try(FSDataInputStream in = fs.open(path)) {
       in.readFully(0, data);
-    } catch (IOException e) {
-      in.close();
     }
-    ByteArrayInputStream in2;
 
     //this is here to track down a parse issue
     //related to configurations
     String s = new String(data, 0, len);
     log.debug("XML resource {} is \"{}\"", path, s);
-    in2 = new ByteArrayInputStream(data);
-    try {
+    try (ByteArrayInputStream in = new ByteArrayInputStream(data)) {
       Document document = parseConfigXML(in);
       return document;
-    } catch (ParserConfigurationException e) {
+    } catch (ParserConfigurationException | SAXException e) {
       throw new IOException(e);
-    } catch (SAXException e) {
-      throw new IOException(e);
-    } finally {
-      in2.close();
     }
 
   }
@@ -222,11 +214,8 @@
                                                                    IOException {
     int len = (int) fs.getLength(path);
     byte[] data = new byte[len];
-    FSDataInputStream in = fs.open(path);
-    try {
+    try (FSDataInputStream in = fs.open(path)) {
       in.readFully(0, data);
-    } catch (IOException e) {
-      in.close();
     }
     ByteArrayInputStream in2;
 
@@ -302,11 +291,26 @@
    */
   public static Configuration loadConfFromFile(File file) throws
                                                           IOException {
+    return loadConfFromFile(file, false);
+  }
+
+  /**
+   *
+   * Load a Hadoop configuration from a local file.
+   * @param file file to load
+   * @param loadDefaults flag to indicate if the defaults should be loaded yet
+   * @return a configuration which hasn't actually had the load triggered
+   * yet.
+   * @throws FileNotFoundException file is not there
+   * @throws IOException any other IO problem
+   */
+  public static Configuration loadConfFromFile(File file,
+      boolean loadDefaults) throws IOException {
     if (!file.exists()) {
       throw new FileNotFoundException("File not found :"
                                           + file.getAbsoluteFile());
     }
-    Configuration conf = new Configuration(false);
+    Configuration conf = new Configuration(loadDefaults);
     try {
       conf.addResource(file.toURI().toURL());
     } catch (MalformedURLException e) {
@@ -357,7 +361,7 @@
                                                         Path templatePath,
                                                         String fallbackResource) throws
                                                                                  IOException {
-    Configuration conf = null;
+    Configuration conf;
     String origin;
     if (fs.exists(templatePath)) {
       log.debug("Loading template configuration {}", templatePath);
@@ -375,8 +379,8 @@
     }
     //force a get
     conf.get(SliderXmlConfKeys.KEY_TEMPLATE_ORIGIN);
-    conf.set(SliderXmlConfKeys.KEY_TEMPLATE_ORIGIN, origin);
     //now set the origin
+    conf.set(SliderXmlConfKeys.KEY_TEMPLATE_ORIGIN, origin);
     return conf;
   }
 
@@ -507,7 +511,7 @@
    * @return hash map
    */
   public static Map<String, String> buildMapFromConfiguration(Configuration conf) {
-    Map<String, String> map = new HashMap<String, String>();
+    Map<String, String> map = new HashMap<>();
     return SliderUtils.mergeEntries(map, conf);
   }
 
@@ -526,7 +530,8 @@
     for (Map.Entry<String, String> entry : keysource) {
       String key = entry.getKey();
       String value = valuesource.get(key);
-      Preconditions.checkState(value!=null, "no reference for \"%s\" in values", key);
+      Preconditions.checkState(value != null,
+          "no reference for \"%s\" in values", key);
       result.set(key, value);
     }
     return result;
diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/CoreFileSystem.java b/slider-core/src/main/java/org/apache/slider/common/tools/CoreFileSystem.java
index dd934ce..a083691 100644
--- a/slider-core/src/main/java/org/apache/slider/common/tools/CoreFileSystem.java
+++ b/slider-core/src/main/java/org/apache/slider/common/tools/CoreFileSystem.java
@@ -113,9 +113,7 @@
    * @return the path for persistent data
    */
   public Path buildClusterDirPath(String clustername) {
-    if (clustername == null) {
-      throw new NullPointerException();
-    }
+    Preconditions.checkNotNull(clustername);
     Path path = getBaseApplicationPath();
     return new Path(path, SliderKeys.CLUSTER_DIRECTORY + "/" + clustername);
   }
@@ -147,8 +145,7 @@
    * to ensure that it is there.
    *
    * @param instancePaths instance paths
-   * @return the path to the cluster directory
-   * @throws java.io.IOException                      trouble
+   * @throws IOException trouble
    * @throws SliderException slider-specific exceptions
    */
   public void createClusterDirectories(InstancePaths instancePaths) throws
@@ -238,7 +235,6 @@
    * Verify that the given directory is not present
    *
    * @param clusterDirectory actual directory to look for
-   * @return the path to the cluster directory
    * @throws IOException    trouble with FS
    * @throws SliderException If the directory exists
    */
@@ -269,7 +265,7 @@
     verifyPathExists(dirPath);
     Path tempFile = new Path(dirPath, "tmp-file-for-checks");
     try {
-      FSDataOutputStream out = null;
+      FSDataOutputStream out ;
       out = fileSystem.create(tempFile, true);
       IOUtils.closeStream(out);
       fileSystem.delete(tempFile, false);
@@ -411,7 +407,7 @@
     //copied to the destination
     FileStatus[] fileset = fileSystem.listStatus(srcDir);
     Map<String, LocalResource> localResources =
-            new HashMap<String, LocalResource>(fileset.length);
+            new HashMap<>(fileset.length);
     for (FileStatus entry : fileset) {
 
       LocalResource resource = createAmResource(entry.getPath(),
diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
index a61e6bb..3f49e1f 100644
--- a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
+++ b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
@@ -123,6 +123,7 @@
    * @param num
    * @param msg the message to be shown in exception
    */
+  @SuppressWarnings("ResultOfMethodCallIgnored")
   private static void validateNumber(String num, String msg)  throws BadConfigException {
     try {
       Integer.parseInt(num);
@@ -188,7 +189,7 @@
 
   /**
    * Find a containing JAR
-   * @param my_class class to find
+   * @param clazz class to find
    * @return the file
    * @throws IOException any IO problem, including the class not having a
    * classloader
@@ -222,8 +223,8 @@
       throw new IOException("Unable to find resources for class " + my_class);
     }
 
-    for (Enumeration itr = urlEnumeration; itr.hasMoreElements(); ) {
-      URL url = (URL) itr.nextElement();
+    for (; urlEnumeration.hasMoreElements(); ) {
+      URL url = urlEnumeration.nextElement();
       if ("jar".equals(url.getProtocol())) {
         String toReturn = url.getPath();
         if (toReturn.startsWith("file:")) {
@@ -429,7 +430,7 @@
    * @return a stringified list
    */
   public static List<String> collectionToStringList(Collection c) {
-    List<String> l = new ArrayList<String>(c.size());
+    List<String> l = new ArrayList<>(c.size());
     for (Object o : c) {
       l.add(o.toString());
     }
@@ -526,7 +527,7 @@
   public static String appReportToString(ApplicationReport r, String separator) {
     StringBuilder builder = new StringBuilder(512);
     builder.append("application ").append(
-      r.getName()).append("/").append(r.getApplicationType()).append(separator);
+        r.getName()).append("/").append(r.getApplicationType()).append(separator);
     Set<String> tags = r.getApplicationTags();
     if (!tags.isEmpty()) {
       for (String tag : tags) {
@@ -710,7 +711,7 @@
 
   /**
    * probe to see if the address
-   * @param address
+   * @param address network address
    * @return true if the scheduler address is set to
    * something other than 0.0.0.0
    */
@@ -820,7 +821,7 @@
    * @return a possibly empty map of environment variables.
    */
   public static Map<String, String> buildEnvMap(Map<String, String> roleOpts) {
-    Map<String, String> env = new HashMap<String, String>();
+    Map<String, String> env = new HashMap<>();
     if (roleOpts != null) {
       for (Map.Entry<String, String> entry: roleOpts.entrySet()) {
         String key = entry.getKey();
@@ -847,7 +848,7 @@
       Map<String, String> optionMap = entry.getValue();
       Map<String, String> existingMap = clusterRoleMap.get(key);
       if (existingMap == null) {
-        existingMap = new HashMap<String, String>();
+        existingMap = new HashMap<>();
       }
       log.debug("Overwriting role options with command line values {}",
                 stringifyMap(optionMap));
@@ -1011,8 +1012,7 @@
   }
 
     public static Map<String, Map<String, String>> deepClone(Map<String, Map<String, String>> src) {
-    Map<String, Map<String, String>> dest =
-      new HashMap<String, Map<String, String>>();
+    Map<String, Map<String, String>> dest = new HashMap<>();
     for (Map.Entry<String, Map<String, String>> entry : src.entrySet()) {
       dest.put(entry.getKey(), stringMapClone(entry.getValue()));
     }
@@ -1020,7 +1020,7 @@
   }
 
   public static Map<String, String> stringMapClone(Map<String, String> src) {
-    Map<String, String> dest =  new HashMap<String, String>();
+    Map<String, String> dest =  new HashMap<>();
     return mergeEntries(dest, src.entrySet());
   }
 
@@ -1249,7 +1249,7 @@
 
   /**
    * Add the cluster build information; this will include Hadoop details too
-   * @param cd cluster
+   * @param info cluster info
    * @param prefix prefix for the build info
    */
   public static void addBuildInfo(Map<String, String> info, String prefix) {