1. David Carr
  2. deepdiff

Commits

David Carr  committed 634d69b

Add better ability to test the factories.
Fix a stream closing error that lead to bad file descriptor errors.

  • Participants
  • Parent commits 3586757
  • Branches default

Comments (0)

Files changed (2)

File engine/src/main/java/deepdiff/core/DiffPointProcessorFactory.java

View file
 import java.util.Map;
 
 /**
- * Supports the creation of instances of {@link DiffPointProcessor} with an
- * associated ID, and later look-up of instances by that ID.
+ * Supports the creation of instances of {@link DiffPointProcessor} with an associated ID, and later
+ * look-up of instances by that ID.
  */
 public class DiffPointProcessorFactory {
     private static final String DEFAULT_ID = "default";
-    private static Map<String, DiffPointProcessor> instances = Collections.synchronizedMap(new HashMap<String, DiffPointProcessor>());
+    private static Map<String, DiffPointProcessor> instances = Collections
+            .synchronizedMap(new HashMap<String, DiffPointProcessor>());
 
     /**
      * Returns the instance with the specified ID, or null if none found
-     *
+     * 
      * @param id the ID of the instance to retrieve
-     *
+     * 
      * @return the instance with the specified ID, or null if none found
      */
     public static DiffPointProcessor get(String id) {
         return instances.get(id);
     }
 
+    public static DiffPointProcessor set(String id, DiffPointProcessor processor) {
+        return instances.put(id, processor);
+    }
+
+    public static void clear() {
+        instances.clear();
+    }
+
     /**
-     * Instantiates a new instance of the specified class using reflection, and
-     * stores it with the specified ID.
-     *
+     * Instantiates a new instance of the specified class using reflection, and stores it with the
+     * specified ID.
+     * 
      * @param className the name of the class to instantiate
      * @param id the ID to store the instance under
-     *
+     * 
      * @return the new instance
-     *
+     * 
      * @throws ClassNotFoundException if the specified class could not be found
-     * @throws InstantiationException if the specified class could not be
-     *                                instantiated
-     * @throws IllegalAccessException if the specified class could not be
-     *                                instantiated due to access issues
+     * @throws InstantiationException if the specified class could not be instantiated
+     * @throws IllegalAccessException if the specified class could not be instantiated due to access
+     *             issues
      */
     public static DiffPointProcessor instantiate(String className, String id)
-                                          throws ClassNotFoundException,
-                                                 InstantiationException,
-                                                 IllegalAccessException {
+            throws ClassNotFoundException, InstantiationException, IllegalAccessException {
         Class<?> clazz = Class.forName(className);
         Object obj = clazz.newInstance();
         DiffPointProcessor instance = (DiffPointProcessor) obj;
     }
 
     /**
-     * Returns the default instance of {@link DiffPointProcessor}, or null if
-     * none was configured
-     *
-     * @return the default instance of {@link DiffPointProcessor}, or null if
-     *         none was configured
+     * Returns the default instance of {@link DiffPointProcessor}, or null if none was configured
+     * 
+     * @return the default instance of {@link DiffPointProcessor}, or null if none was configured
      */
     public static DiffPointProcessor getDefault() {
         return get(DEFAULT_ID);

File engine/src/main/java/deepdiff/core/DiffUnitProcessorFactory.java

View file
         return instances.get(id);
     }
 
-    static DiffUnitProcessor set(String id, DiffUnitProcessor processor) {
+    public static DiffUnitProcessor set(String id, DiffUnitProcessor processor) {
         return instances.put(id, processor);
     }
 
-    static void clear() {
+    public static void clear() {
         instances.clear();
     }
 
             }
             try {
                 InputStream leftStream = new FileInputStream(leftFile);
-                try {
-                    InputStream rightStream = new FileInputStream(rightFile);
-                    try {
-                        scope = sdup.createScope(path, leftStream, rightStream);
-                    } finally {
-                        rightStream.close();
-                    }
-                } finally {
-                    leftStream.close();
-                }
+                InputStream rightStream = new FileInputStream(rightFile);
+                scope = sdup.createScope(path, leftStream, rightStream);
             } catch (IOException ex) {
                 log.error("Failure reading from specified files", ex);
             }