diff --git a/.gradle/8.10/checksums/checksums.lock b/.gradle/8.10/checksums/checksums.lock new file mode 100644 index 0000000..16399c0 Binary files /dev/null and b/.gradle/8.10/checksums/checksums.lock differ diff --git a/.gradle/8.10/checksums/md5-checksums.bin b/.gradle/8.10/checksums/md5-checksums.bin new file mode 100644 index 0000000..57f7011 Binary files /dev/null and b/.gradle/8.10/checksums/md5-checksums.bin differ diff --git a/.gradle/8.10/checksums/sha1-checksums.bin b/.gradle/8.10/checksums/sha1-checksums.bin new file mode 100644 index 0000000..9a3d66c Binary files /dev/null and b/.gradle/8.10/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.10/dependencies-accessors/gc.properties b/.gradle/8.10/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.10/executionHistory/executionHistory.bin b/.gradle/8.10/executionHistory/executionHistory.bin new file mode 100644 index 0000000..c808261 Binary files /dev/null and b/.gradle/8.10/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.10/executionHistory/executionHistory.lock b/.gradle/8.10/executionHistory/executionHistory.lock new file mode 100644 index 0000000..48ad371 Binary files /dev/null and b/.gradle/8.10/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.10/fileChanges/last-build.bin b/.gradle/8.10/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.10/fileChanges/last-build.bin differ diff --git a/.gradle/8.10/fileHashes/fileHashes.bin b/.gradle/8.10/fileHashes/fileHashes.bin new file mode 100644 index 0000000..8338b23 Binary files /dev/null and b/.gradle/8.10/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.10/fileHashes/fileHashes.lock b/.gradle/8.10/fileHashes/fileHashes.lock new file mode 100644 index 0000000..1b43f7a Binary files /dev/null and b/.gradle/8.10/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.10/fileHashes/resourceHashesCache.bin b/.gradle/8.10/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..8ffd7f9 Binary files /dev/null and b/.gradle/8.10/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/8.10/gc.properties b/.gradle/8.10/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index bda9823..dec9c60 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties index 6d779e7..ea516a2 100644 --- a/.gradle/buildOutputCleanup/cache.properties +++ b/.gradle/buildOutputCleanup/cache.properties @@ -1,2 +1,2 @@ -#Wed Feb 28 17:19:38 GMT+03:30 2024 -gradle.version=7.4 +#Wed Apr 23 17:07:49 GMT+03:30 2025 +gradle.version=8.10 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 87351e2..5858ca1 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e5284fe..433533f 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.idea/Fourth-Assignment-Steam-Scraper.iml b/.idea/Fourth-Assignment-Steam-Scraper.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Fourth-Assignment-Steam-Scraper.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b589d56..d390bd5 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 611e7c8..89022a7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,7 +4,6 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 08237f1..2e2e093 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f9d2f50..688217e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + 1709128175583 1743341137706 diff --git a/build/classes/java/main/Game.class b/build/classes/java/main/Game.class new file mode 100644 index 0000000..8e35984 Binary files /dev/null and b/build/classes/java/main/Game.class differ diff --git a/build/classes/java/main/Parser.class b/build/classes/java/main/Parser.class new file mode 100644 index 0000000..eea5b36 Binary files /dev/null and b/build/classes/java/main/Parser.class differ diff --git a/build/classes/java/test/ParserTest.class b/build/classes/java/test/ParserTest.class new file mode 100644 index 0000000..2ce9446 Binary files /dev/null and b/build/classes/java/test/ParserTest.class differ diff --git a/build/reports/tests/test/classes/ParserTest.html b/build/reports/tests/test/classes/ParserTest.html index 6888813..78adda7 100644 --- a/build/reports/tests/test/classes/ParserTest.html +++ b/build/reports/tests/test/classes/ParserTest.html @@ -41,7 +41,7 @@

Class ParserTest

-
0.035s
+
0.118s

duration

@@ -75,18 +75,18 @@

Tests

-testSortByArea() -0.028s +testSortByName() +0.075s passed -testSortByName() -0.003s +testSortByPrice() +0.018s passed -testSortByPopulation() -0.004s +testSortByRating() +0.025s passed @@ -99,7 +99,7 @@

Tests

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 8.10 at Apr 23, 2025, 5:19:31 PM

diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index d2f1ae9..25d4ff8 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -38,7 +38,7 @@

Test Summary

-
0.035s
+
0.118s

duration

@@ -85,7 +85,7 @@

Packages

3 0 0 -0.035s +0.118s 100% @@ -112,7 +112,7 @@

Classes

3 0 0 -0.035s +0.118s 100% @@ -126,7 +126,7 @@

Classes

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 8.10 at Apr 23, 2025, 5:19:31 PM

diff --git a/build/reports/tests/test/packages/default-package.html b/build/reports/tests/test/packages/default-package.html index 2ffe0cb..a2641b6 100644 --- a/build/reports/tests/test/packages/default-package.html +++ b/build/reports/tests/test/packages/default-package.html @@ -40,7 +40,7 @@

Default package

-
0.035s
+
0.118s

duration

@@ -66,7 +66,7 @@

Default package

Classes

- + @@ -75,7 +75,7 @@

Classes

- + - +
Class Tests Duration Success rate
ParserTest @@ -83,7 +83,7 @@

Classes

3 0 00.035s0.118s 100%
@@ -96,7 +96,7 @@

Classes

Generated by -Gradle 7.4 at Feb 28, 2024, 6:39:51 PM

+Gradle 8.10 at Apr 23, 2025, 5:19:31 PM

diff --git a/build/test-results/test/TEST-ParserTest.xml b/build/test-results/test/TEST-ParserTest.xml index 0dd5d0b..c56a115 100644 --- a/build/test-results/test/TEST-ParserTest.xml +++ b/build/test-results/test/TEST-ParserTest.xml @@ -1,9 +1,9 @@ - + - - - + + + diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin index 05d8f6a..2571442 100644 Binary files a/build/test-results/test/binary/results.bin and b/build/test-results/test/binary/results.bin differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/Parser.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/Parser.class.uniqueId0 new file mode 100644 index 0000000..379ce58 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/Parser.class.uniqueId0 differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 85f59d9..cfecd40 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index e3bdb4a..73ffabb 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd49..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..9355b41 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..f5feea6 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,12 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +134,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +217,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 79ed925..5ef05e2 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -6,15 +6,15 @@ public class Game { private int price; public Game(String name, double rating, int price) { - //TODO - + this.name = name; + this.rating = rating; + this.price = price; } public String getName() { return name; } - public double getRating() { return rating; } @@ -25,8 +25,11 @@ public int getPrice() { @Override public String toString() { - //TODO - return ""; + return "Game{" + + "name='" + name + '\'' + + ", rating=" + rating + + ", price=" + price + + '}'; } @Override @@ -34,7 +37,13 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Game game = (Game) o; - return Double.compare(game.rating, rating) == 0 && Double.compare(game.price, price) == 0 && Objects.equals(name, game.name); + return Double.compare(game.rating, rating) == 0 && + price == game.price && + Objects.equals(name, game.name); } + @Override + public int hashCode() { + return Objects.hash(name, rating, price); + } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index e6ba90f..d9b6edc 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -11,38 +11,61 @@ public class Parser { public List sortByName(){ List sortedByName = new ArrayList<>(games); - // Sort games alphabetically (least) - //TODO - return sortedByName; + sortedByName.sort(Comparator.comparing(Game::getName)); + return sortedByName; } + public List sortByRating(){ List sortedByRating = new ArrayList<>(games); - // Sort games by rating (most) - //TODO + sortedByRating.sort(Comparator.comparingDouble(Game::getRating).reversed()); return sortedByRating; } + public List sortByPrice(){ List sortedByPrice = new ArrayList<>(games); - // Sort games by price (most) - //TODO + sortedByPrice.sort(Comparator.comparingInt(Game::getPrice).reversed()); return sortedByPrice; } + public void setUp() throws IOException { + File input = new File("src/Resources/Video_Games.html"); // مسیر فایل رو بر اساس محل ذخیره‌سازی واقعی اصلاح کن + Document doc = Jsoup.parse(input, "UTF-8"); - //Parse the HTML file using Jsoup - //TODO + Elements gameElements = doc.select("div.col-md-4.game"); - // Extract data from the HTML - //TODO + for (Element gameElement : gameElements) { + String name = gameElement.selectFirst("h3.game-name").text(); + String ratingText = gameElement.selectFirst("span.game-rating").text(); // مثل 4.9/5 + String priceText = gameElement.selectFirst("span.game-price").text(); // مثل 92 € - // Iterate through each Game div to extract Game data - //TODO + double rating = Double.parseDouble(ratingText.split("/")[0]); + int price = Integer.parseInt(priceText.replaceAll("[^\\d]", "")); + + Game game = new Game(name, rating, price); + games.add(game); + } } + public static void main(String[] args) { - //you can test your code here before you run the unit tests + Parser parser = new Parser(); + try { + parser.setUp(); + System.out.println("Sorted by Name:"); + parser.sortByName().forEach(System.out::println); + + System.out.println("\nSorted by Rating:"); + parser.sortByRating().forEach(System.out::println); + + System.out.println("\nSorted by Price:"); + parser.sortByPrice().forEach(System.out::println); + + } catch (IOException e) { + System.err.println("Error reading HTML file: " + e.getMessage()); + } } + }