refactored searchers into a class
This commit is contained in:
parent
e1d40829b4
commit
2834168b14
@ -4,10 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import fr.packageviewer.distribution.ArchDistribution;
|
|
||||||
import fr.packageviewer.distribution.Distribution;
|
|
||||||
import fr.packageviewer.pack.SearchedPackage;
|
import fr.packageviewer.pack.SearchedPackage;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@ -43,71 +40,6 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
public static void main(String[] args) {
|
||||||
// send the command line arguments to the parser
|
// send the command line arguments to the parser
|
||||||
ArgParse.parseArguments(args);
|
ArgParse.parseArguments(args);
|
||||||
@ -122,15 +54,16 @@ public class Main {
|
|||||||
List<SearchedPackage> packets = new ArrayList<>();
|
List<SearchedPackage> packets = new ArrayList<>();
|
||||||
|
|
||||||
// distribution is null when no distribution is specified
|
// distribution is null when no distribution is specified
|
||||||
|
// else we get the list of packages from the distribution
|
||||||
if(distribution == null) {
|
if(distribution == null) {
|
||||||
packets = searchForAll(packet);
|
packets = Searcher.searchForAll(packet);
|
||||||
} else {
|
} else {
|
||||||
switch (distribution) {
|
switch (distribution) {
|
||||||
case "archlinux":
|
case "archlinux":
|
||||||
packets = searchForArch(packet);
|
packets = Searcher.searchForArch(packet);
|
||||||
break;
|
break;
|
||||||
case "fedora":
|
case "fedora":
|
||||||
packets = searchForFedora(packet);
|
packets = Searcher.searchForFedora(packet);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Error: Unknown");
|
System.out.println("Error: Unknown");
|
||||||
|
76
src/main/java/fr/packageviewer/Searcher.java
Normal file
76
src/main/java/fr/packageviewer/Searcher.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package fr.packageviewer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import fr.packageviewer.distribution.ArchDistribution;
|
||||||
|
import fr.packageviewer.distribution.Distribution;
|
||||||
|
import fr.packageviewer.pack.SearchedPackage;
|
||||||
|
|
||||||
|
public class Searcher {
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user