From d31969b8d0722876d3f5447d3fe2cabb5312c42b Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 16:00:53 +0100 Subject: [PATCH] added documentation for the newly added elements --- .../distribution/ArchDistribution.java | 40 +++++++++++-------- .../java/fr/packageviewer/pack/Package.java | 28 ++++++++----- .../packageviewer/pack/SearchedPackage.java | 23 +++++++---- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index 86f8670..1737f00 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -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 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 -> { diff --git a/src/main/java/fr/packageviewer/pack/Package.java b/src/main/java/fr/packageviewer/pack/Package.java index a782a48..34a23a1 100644 --- a/src/main/java/fr/packageviewer/pack/Package.java +++ b/src/main/java/fr/packageviewer/pack/Package.java @@ -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 deps) { + public Package(String name, String version, String repo, String description, String distribution, + List deps) { super(name, version, repo, description, distribution); this.deps = deps; } + /** * Returns a string reprensentation of the package * diff --git a/src/main/java/fr/packageviewer/pack/SearchedPackage.java b/src/main/java/fr/packageviewer/pack/SearchedPackage.java index 50f3e7d..3ec3f45 100644 --- a/src/main/java/fr/packageviewer/pack/SearchedPackage.java +++ b/src/main/java/fr/packageviewer/pack/SearchedPackage.java @@ -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); } }