Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ModuleComparator |
|
| 2.5;2.5 |
1 | package org.jtheque.core.managers.module; | |
2 | ||
3 | /* | |
4 | * This file is part of JTheque. | |
5 | * | |
6 | * JTheque is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License. | |
9 | * | |
10 | * JTheque is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | import org.jtheque.core.managers.module.beans.ModuleContainer; | |
20 | import org.jtheque.utils.StringUtils; | |
21 | ||
22 | import java.util.Comparator; | |
23 | ||
24 | /** | |
25 | * @author Baptiste Wicht | |
26 | */ | |
27 | 0 | final class ModuleComparator implements Comparator<ModuleContainer> { |
28 | @Override | |
29 | public int compare(ModuleContainer o1, ModuleContainer o2) { | |
30 | //First the modules without dependency | |
31 | 0 | if (hasDependency(o1) && !hasDependency(o2)) { |
32 | 0 | return -1; |
33 | } | |
34 | ||
35 | //And finally all the others | |
36 | 0 | return 0; |
37 | } | |
38 | ||
39 | /** | |
40 | * Indicate if the module has dependency or not. | |
41 | * | |
42 | * @param module The module to test. | |
43 | * @return true if the module has dependency else false. | |
44 | */ | |
45 | private static boolean hasDependency(ModuleContainer module) { | |
46 | 0 | return StringUtils.isNotEmpty(module.getInfos().dependencies()); |
47 | } | |
48 | } |