BUG-7052: Move ModuleDependencySort to yang-model-util
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / util / ModuleDependencySort.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.util;
9
10 import java.util.Arrays;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13
14 /**
15  * Creates a module dependency graph from provided {@link Module}s and
16  * provides a {@link #sort(Module...)} method. It is topological sort and
17  * returns modules in order in which they should be processed (e.g. if A imports
18  * B, sort returns {B, A}).
19  *
20  * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.ModuleDependencySort} instead.
21  */
22 @Deprecated
23 public final class ModuleDependencySort {
24     /**
25      * It is not desirable to instance this class
26      */
27     private ModuleDependencySort() {
28     }
29
30     /**
31      * Topological sort of module dependency graph.
32      *
33      * @param modules YANG modules
34      * @return Sorted list of Modules. Modules can be further processed in
35      *         returned order.
36      */
37     public static List<Module> sort(final Module... modules) {
38         return sort(Arrays.asList(modules));
39     }
40
41     /**
42      * Topological sort of module dependency graph.
43      *
44      * @param modules YANG modules
45      * @return Sorted list of Modules. Modules can be further processed in
46      *         returned order.
47      */
48     public static List<Module> sort(final Iterable<Module> modules) {
49         try {
50             return org.opendaylight.yangtools.yang.model.util.ModuleDependencySort.sort(modules);
51         } catch (IllegalArgumentException ex) {
52             throw new YangValidationException(ex.getMessage(), ex);
53         }
54     }
55 }