get list of searched packages from distrib wanted

This commit is contained in:
Capelier-Marla 2022-12-14 14:32:26 +01:00
parent 32ae539a0d
commit e1d40829b4

View File

@ -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<SearchedPackage> 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<List<SearchedPackage>> archPackages = arch.searchPackage(packet);
Future<List<SearchedPackage>> fedoraPackages = fedora.searchPackage(packet);
// init the list of packages that will be returned
List<SearchedPackage> archResult = new ArrayList<>();
List<SearchedPackage> 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<SearchedPackage> searchForArch(String packet) {
// init distribution to search in it
Distribution arch = new ArchDistribution();
// search for the package in the distribution
Future<List<SearchedPackage>> packages = arch.searchPackage(packet);
// init the list of packages that will be returned
List<SearchedPackage> 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<SearchedPackage> searchForFedora(String packet) {
// init distribution to search in it
Distribution fedora = new ArchDistribution();
// search for the package in the distribution
Future<List<SearchedPackage>> packages = fedora.searchPackage(packet);
// init the list of packages that will be returned
List<SearchedPackage> 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<SearchedPackage> 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;
}
}