added documentation for the newly added elements

This commit is contained in:
Djalim Simaila 2022-12-14 16:00:53 +01:00
parent 68df90c73d
commit d31969b8d0
3 changed files with 56 additions and 35 deletions

View File

@ -29,10 +29,20 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
*/
private static final Logger logger = LoggerManager.getLogger("ArchDistribution");
private static String trimAfterCharacters(String str, String trimAfterCharacters){
for(char c : trimAfterCharacters.toCharArray()){
/**
* This method remove all characters in the first string passed as
* parametter after one of the character in the second string if found
* in the first string
*
* @param str String, the string to trim
* @param trimAfterCharacters String, the character that delimits our string
* @return
*/
private static String trimAfterCharacters(String str, String trimAfterCharacters) {
for (char c : trimAfterCharacters.toCharArray()) {
int index = str.indexOf(c);
if(index>0)str = str.substring(index);
if (index > 0)
str = str.substring(index);
}
return str;
}
@ -69,8 +79,8 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
// get infos
Set<String> dependenciesNames = new HashSet<>();
for(Object dependency : resultJson.getJSONArray("depends")){
dependenciesNames.add(trimAfterCharacters((String)dependency, "<>="));
for (Object dependency : resultJson.getJSONArray("depends")) {
dependenciesNames.add(trimAfterCharacters((String) dependency, "<>="));
}
futureResult.complete(new Pair<>(
new Package(
@ -78,11 +88,9 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
resultJson.getString("pkgver"),
resultJson.getString("repo"),
resultJson.getString("pkgdesc"),
"arch"
),
dependenciesNames
));
}).exceptionally(error ->{
"arch"),
dependenciesNames));
}).exceptionally(error -> {
error.printStackTrace();
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
futureResult.complete(null);
@ -93,7 +101,6 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
}
/**
* Search for a package matching a pattern and return a list of packages and
* return a list of string matching this pattern.
@ -120,12 +127,11 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
JSONObject searchResultJson = (JSONObject) searchResultObj;
// add package into to list
searchedPackagesList.add(new SearchedPackage(
searchResultJson.getString("pkgname"),
searchResultJson.getString("pkgver"),
searchResultJson.getString("repo"),
searchResultJson.getString("pkgdesc"),
"arch"
));
searchResultJson.getString("pkgname"),
searchResultJson.getString("pkgver"),
searchResultJson.getString("repo"),
searchResultJson.getString("pkgdesc"),
"arch"));
}
futureSearchedPackages.complete(searchedPackagesList);
}).exceptionally(error -> {

View File

@ -38,28 +38,34 @@ public class Package extends SearchedPackage {
* Second constructor for the Package class, allows to create a package
* without supplying a list of dependencies.
*
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
* @param distribution String, the distribution where this specific package
* belongs
*/
public Package(String name, String version, String repo, String description,String distribution) {
public Package(String name, String version, String repo, String description, String distribution) {
this(name, version, repo, description, distribution, new ArrayList<>());
}
/**
* Main constructor for the Package class
*
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
* @param deps List of Package, dependencies of the package
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
* @param distribution String, the distribution where this specific package
* belongs
* @param deps List of Package, dependencies of the package
*/
public Package(String name, String version, String repo, String description,String distribution, List<Package> deps) {
public Package(String name, String version, String repo, String description, String distribution,
List<Package> deps) {
super(name, version, repo, description, distribution);
this.deps = deps;
}
/**
* Returns a string reprensentation of the package
*

View File

@ -24,6 +24,9 @@ public class SearchedPackage {
* Description of the package
*/
private final String description;
/**
* Distribution where this specific package belongs
*/
private final String distribution;
/**
@ -62,7 +65,11 @@ public class SearchedPackage {
return description;
}
/**
* Getter for the distribution attribute
*
* @return String, distribution where this specific package belongs
*/
public String getDistribution() {
return distribution;
}
@ -70,11 +77,12 @@ public class SearchedPackage {
/**
* Constructor for the SearchedPackage class
*
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
*
* @param name String, name of the package
* @param version String, version of the package
* @param repo String, repository where the package is located
* @param description String, description of the package
* @param distribution String, the distribution where this specific package
* belongs
*/
public SearchedPackage(String name, String version, String repo, String description, String distribution) {
this.name = name;
@ -91,6 +99,7 @@ public class SearchedPackage {
*/
@Override
public String toString() {
return "SearchedPackage{name=%s,version=%s,repo=%s,description=%s,distribution=%s}".formatted(name, version, repo, description, distribution);
return "SearchedPackage{name=%s,version=%s,repo=%s,description=%s,distribution=%s}".formatted(name, version,
repo, description, distribution);
}
}