diff --git a/src/main/java/fr/packageviewer/Main.java b/src/main/java/fr/packageviewer/Main.java index e26ceb1..8e1b5d3 100644 --- a/src/main/java/fr/packageviewer/Main.java +++ b/src/main/java/fr/packageviewer/Main.java @@ -1,7 +1,14 @@ package fr.packageviewer; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.concurrent.Future; + +import fr.packageviewer.distribution.ArchDistribution; +import fr.packageviewer.distribution.Distribution; +import fr.packageviewer.pack.SearchedPackage; public class Main { @@ -35,13 +42,70 @@ public class Main { } } - private static void searchForAll(String packet) { + + private static List searchForAll(String packet) { + // init distribution to search in it + Distribution arch = new ArchDistribution(); + Distribution fedora = new ArchDistribution(); + // search for the package in the distribution + Future> archPackages = arch.searchPackage(packet); + Future> fedoraPackages = fedora.searchPackage(packet); + // init the list of packages that will be returned + List archResult = new ArrayList<>(); + List fedoraResult = new ArrayList<>(); + // try to get the searched packages to return it after + try { + archResult = archPackages.get(); + fedoraResult = fedoraPackages.get(); + } catch (Exception e) { + /* TODO: handle exception */ + } + archResult.addAll(fedoraResult); + return archResult; } - private static void searchForArch(String packet) { + /** + * Search for the specified package in Arch repositories + * @param packet the package to search + * @return The list of packages that match the name + * @author Capelier-Marla + */ + private static List searchForArch(String packet) { + // init distribution to search in it + Distribution arch = new ArchDistribution(); + // search for the package in the distribution + Future> packages = arch.searchPackage(packet); + // init the list of packages that will be returned + List result = new ArrayList<>(); + // try to get the searched packages to return it after + try { + result = packages.get(); + } catch (Exception e) { + /* TODO: handle exception */ + } + return result; } - private static void searchForFedora(String packet) { + /** + * Search for the specified package in Fedora repositories + * @param packet the package to search + * @return The list of packages that match the name + * @author Capelier-Marla + */ + private static List searchForFedora(String packet) { + // init distribution to search in it + Distribution fedora = new ArchDistribution(); + // search for the package in the distribution + Future> packages = fedora.searchPackage(packet); + // init the list of packages that will be returned + List result = new ArrayList<>(); + // try to get the searched packages to return it after + try { + result = packages.get(); + } catch (Exception e) { + /* TODO: handle exception */ + } + return result; } public static void main(String[] args) { @@ -54,19 +118,23 @@ public class Main { System.out.println(packet); System.out.println(distribution); + // the list of packages we will show later + List packets = new ArrayList<>(); + // distribution is null when no distribution is specified if(distribution == null) { - searchForAll(packet); + packets = searchForAll(packet); } else { switch (distribution) { case "archlinux": - searchForArch(packet); + packets = searchForArch(packet); break; case "fedora": - searchForFedora(packet); + packets = searchForFedora(packet); break; default: System.out.println("Error: Unknown"); + System.exit(0); break; } }