Exceptions should have serialVersionUid
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / util / ModuleDependencySort.java
index f7e270ea1d5badf84ef605c51a93da8422739e9d..837d71115f567c2ded7b4be8479ca0563f3ebadf 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -22,6 +23,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -41,11 +43,14 @@ import org.slf4j.LoggerFactory;
  */
 public final class ModuleDependencySort {
 
-    private static final Date DEFAULT_REVISION = new Date(0);
+    private static final Date DEFAULT_REVISION = SimpleDateFormatUtil.DEFAULT_DATE_REV;
     private static final Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
     private static final Function<Node, Module> TOPOLOGY_FUNCTION = new Function<TopologicalSort.Node, Module>() {
         @Override
         public Module apply(final TopologicalSort.Node input) {
+            if (input == null) {
+                return null;
+            }
             ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
             return moduleOrModuleBuilder.getModule();
         }
@@ -65,6 +70,9 @@ public final class ModuleDependencySort {
         @Override
         public ModuleBuilder apply(final TopologicalSort.Node input) {
             // Cast to ModuleBuilder from Node and return
+            if (input == null) {
+                return null;
+            }
             ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
             return moduleOrModuleBuilder.getModuleBuilder();
         }
@@ -73,6 +81,7 @@ public final class ModuleDependencySort {
     /**
      * Topological sort of module builder dependency graph.
      *
+     * @param builders builders of Module object
      * @return Sorted list of Module builders. Modules can be further processed
      *         in returned order.
      */
@@ -95,6 +104,9 @@ public final class ModuleDependencySort {
 
             @Override
             public ModuleBuilder apply(final TopologicalSort.Node input) {
+                if (input == null) {
+                    return null;
+                }
                 ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
                 if (moduleOrModuleBuilder.isModuleBuilder()) {
                     return moduleOrModuleBuilder.getModuleBuilder();
@@ -108,6 +120,7 @@ public final class ModuleDependencySort {
     /**
      * Topological sort of module dependency graph.
      *
+     * @param modules YANG modules
      * @return Sorted list of Modules. Modules can be further processed in
      *         returned order.
      */
@@ -323,8 +336,8 @@ public final class ModuleDependencySort {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + ((name == null) ? 0 : name.hashCode());
-            result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+            result = prime * result + Objects.hashCode(name);
+            result = prime * result + Objects.hashCode(revision);
             return result;
         }