finished documentation for classes ArchDistribution, Distribution and AsyncRequestParse

This commit is contained in:
Djalim Simaila 2022-12-14 14:17:51 +01:00
parent 44ac927f6e
commit 052ba40800
3 changed files with 42 additions and 23 deletions

View File

@ -25,8 +25,8 @@ import org.json.*;
public class ArchDistribution extends AsyncRequestsParser implements Distribution { public class ArchDistribution extends AsyncRequestsParser implements Distribution {
/** /**
* Logger object used to split debug output and the application output * Logger object used to split debug output and the application output
*/ */
private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); private static final Logger logger = LoggerManager.getLogger("ArchDistribution");
/** /**

View File

@ -10,18 +10,29 @@ import java.util.concurrent.Future;
/** /**
* This interface specifies the methods needed by a distribtion to be parsable. * This interface specifies the methods needed by a distribtion to be parsable.
* *
* @author R.Thomas * @author R.Thomas
* @version 1.0 * @version 1.0
*/ */
public interface Distribution { public interface Distribution {
/** /**
* Search for a package matching a pattern and return a list of packages and * Search for a package matching a pattern and return a list of packages and
* return a list of string matching this pattern. * return a list of string matching this pattern.
* *
* @param packageName String, the pattern to search in the repositories * @param packageName String, the pattern to search in the repositories
* @return List of SearchedPackage objects * @return List of SearchedPackage objects
*/ */
Future<List<SearchedPackage>> searchPackage(String packageName); Future<List<SearchedPackage>> searchPackage(String packageName);
/**
* This function returns a fully completed package containing all
* information about the package identified by it's exact name passed as
* parametter, the package contains in its dependency list fully formed
* packages that also contains its dependencies, the dependency depth is
* specified by the parametter with the same name.
*
* @param packageName String, The package's exact name
* @param depth int, the depth of the dependency tree
* @return Package, the fully completed package
*/
Future<Package> getPackageTree(String packageName, int depth); Future<Package> getPackageTree(String packageName, int depth);
} }

View File

@ -13,7 +13,7 @@ import java.util.logging.Logger;
/** /**
* This abstract class defines the method that a distribution will use * This abstract class defines the method that a distribution will use
* in order to get a package and fill its dependency list. It does all that * in order to get a package and fill its dependency list. It does all that
* in an asyncron manner * in an asyncron manner
* *
* @author R.Thomas * @author R.Thomas
@ -22,22 +22,30 @@ import java.util.logging.Logger;
*/ */
public abstract class AsyncRequestsParser { public abstract class AsyncRequestsParser {
/** /**
* Logger object used to split debug output and the application output * Logger object used to split debug output and the application output
*/ */
private static final Logger logger = LoggerManager.getLogger("AsyncRequestsParser"); private static final Logger logger = LoggerManager.getLogger("AsyncRequestsParser");
/** /**
* This function return a package from the distribution's api in the form * This function returns a package from the distribution's api in the form
* of a Pair Composed of a Package object, and a set of string containing * of a Pair Composed of a Package object and a set of string containing
* the names of the dependecies of the package. * the names of the dependecies of the package.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @return Pair of Package and Set of String * @return Pair of Package and Set of String
*/ */
protected abstract CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String name); protected abstract CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String name);
/** /**
* This function returns a fully completed package containing all
* information about the package identified by it's exact name passed as
* parametter, the package contains in its dependency list fully formed
* packages that also contains its dependencies, the dependency depth is
* specified by the parametter with the same name.
* *
* @param packageName String, The package's exact name
* @param depth int, the depth of the dependency tree
* @return Package, the fully completed package
*/ */
public CompletableFuture<Package> getPackageTree(String packageName, int depth) { public CompletableFuture<Package> getPackageTree(String packageName, int depth) {
// parse the json // parse the json
@ -53,7 +61,7 @@ public abstract class AsyncRequestsParser {
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
futureRequest.thenAccept(result -> { futureRequest.thenAccept(result -> {
if(result==null){ if (result == null) {
logger.fine("Completing callback INVALID for package %s (depth=%s)".formatted(packageName, depth)); logger.fine("Completing callback INVALID for package %s (depth=%s)".formatted(packageName, depth));
futurePackage.complete(null); futurePackage.complete(null);
return; return;
@ -61,7 +69,6 @@ public abstract class AsyncRequestsParser {
Package pack = result.getFirst(); Package pack = result.getFirst();
Set<String> dependenciesNames = result.getSecond(); Set<String> dependenciesNames = result.getSecond();
// if we're at the maximum depth, return the package without its dependencies // if we're at the maximum depth, return the package without its dependencies
if (depth == 0) { if (depth == 0) {
logger.fine("Completing callback NODEP for package %s (depth=%s)".formatted(packageName, depth)); logger.fine("Completing callback NODEP for package %s (depth=%s)".formatted(packageName, depth));
@ -93,7 +100,8 @@ public abstract class AsyncRequestsParser {
futurePackage.complete(pack); futurePackage.complete(pack);
}).exceptionally(error -> { }).exceptionally(error -> {
error.printStackTrace(); error.printStackTrace();
logger.warning("Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error)); logger.warning(
"Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error));
futurePackage.complete(null); futurePackage.complete(null);
return null; return null;
}); });