Repository: CorporationX/god_bless
Pull request #19444: BJS2-70726
Author: login: AlexandrSid
Created: 2025-04-17T20:56:52Z | Merged: 2025-04-18T15:05:09Z

https://faang-school.atlassian.net/browse/BJS2-70726
Init commit, task framework


Diff:
diff --git a/src/main/java/school/faang/stream2/streamapi1/ListOperations.java b/src/main/java/school/faang/stream2/streamapi1/ListOperations.java
new file mode 100644
index 00000000000..47b3b1d98d0
--- /dev/null
+++ b/src/main/java/school/faang/stream2/streamapi1/ListOperations.java
@@ -0,0 +1,64 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static int sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static int findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .max(Integer::compareTo)
+                .orElseThrow(() -> new IllegalArgumentException("the list is empty"));
+    }
+
+    public static double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseThrow(() -> new IllegalArgumentException("the list is empty"));
+    }
+
+    public static long countStringsStartingWith(List<String> strings, char firstLetter) {
+        return strings.stream()
+                .filter(str -> str.startsWith(String.valueOf(firstLetter)))
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String substring) {
+        return strings.stream()
+                .filter(str -> str.contains(substring))
+                .toList();
+    }
+
+    public static List<String> sortByLength(List<String> strings) {
+        return strings.stream()
+                .sorted(Comparator.comparingInt(String::length))
+                .toList();
+    }
+
+    public static boolean allMatchCondition(List<Integer> numbers, Predicate<Integer> predicate) {
+        return numbers.stream()
+                .allMatch(predicate);
+    }
+
+    public static int findMinGreaterThan(List<Integer> numbers, int threshold) {
+        return numbers.stream()
+                .filter(n -> n > threshold)
+                .min(Integer::compareTo)
+                .orElseThrow(() -> new NoSuchElementException("there is no such element in collection"));
+    }
+
+    public static List<Integer> convertToLengths(List<String> strings) {
+        return strings.stream()
+                .map(String::length)
+                .toList();
+    }
+}
diff --git a/src/main/java/school/faang/stream2/streamapi1/Main.java b/src/main/java/school/faang/stream2/streamapi1/Main.java
new file mode 100644
index 00000000000..82d6403284d
--- /dev/null
+++ b/src/main/java/school/faang/stream2/streamapi1/Main.java
@@ -0,0 +1,28 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class Main {
+    public static void main(String[] args) {
+        List<Integer> numbers1 = Arrays.asList(1, 2, 3, 4, 5, 6);
+        List<Integer> numbers2 = Arrays.asList(10, 5, 20, 15, 3, 7);
+        int threshold = 6;
+        String subString = "an";
+        char firstLetter = 'a';
+        List<String> strings = Arrays.asList("apple", "banana", "cherry", "date");
+
+        System.out.println("Сумма четных чисел: " + ListOperations.sumOfEvenNumbers(numbers1));
+        System.out.println("Максимум: " + ListOperations.findMax(numbers1));
+        System.out.println("Среднее: " + ListOperations.findAverage(numbers1));
+        System.out.printf("Количество строк, начинающихся на '%s': %s\n",
+                firstLetter, ListOperations.countStringsStartingWith(strings, firstLetter));
+        System.out.printf("Строки, содержащие '%s': %s\n",
+                subString, ListOperations.filterStringsContainingSubstring(strings, subString));
+        System.out.println("Отсортированные по длине строки: " + ListOperations.sortByLength(strings));
+        System.out.println("Все ли числа чётные? " + ListOperations.allMatchCondition(numbers1, n -> n % 2 == 0));
+        System.out.printf("Наименьшее число больше %s: %s\n",
+                threshold, ListOperations.findMinGreaterThan(numbers2, threshold));
+        System.out.println("Длины строк: " + ListOperations.convertToLengths(strings));
+    }
+}


Reviews:
user: login: MarselYsup
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-04-17T22:42:09Z
user: login: MarselYsup
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-17T22:43:44Z
user: login: MarselYsup
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-17T22:44:46Z
user: login: MarselYsup
body: Поправь еще небольшие комментарии, все остальное круто!)
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-18T14:33:28Z

Review comments:
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: можно без преобразования в IntStream, достаточно использовать max с Comporator-ом
```
public static Integer findMax(List<Integer> numbers) {
        return numbers.stream()
                .max(Integer::compareTo)
                .orElseGet(null);
    }
 ```
created_at: 2025-04-17T22:33:03Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: по задаче требуется вернуть примитив double
created_at: 2025-04-17T22:33:55Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: по задаче требуется вернуть примитив int, можешь в случае если ничего не найдено кидать exception 
```java
.orElseThrow(...)
```
created_at: 2025-04-17T22:34:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: по задаче требуется вернуть примитив int
created_at: 2025-04-17T22:35:37Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
+        return strings.stream()
+                .filter(str -> str.charAt(0) == a)
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: стоит проверять что строка не пустая , а то словим  ``` java.lang.StringIndexOutOfBoundsException```
created_at: 2025-04-17T22:37:26Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: требуется вернуть примитив
created_at: 2025-04-17T22:37:36Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
+        return strings.stream()
+                .filter(str -> str.charAt(0) == a)
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String an) {
+        return strings.stream()
+                .filter(str -> str.contains(an))
+                .toList();
+    }
+
+    public static List<String> sortByLength(List<String> strings) {
+        return strings.stream()
+                .sorted(Comparator.comparingInt(String::length))
+                .toList();
+    }
+
+    public static <T> Boolean allMatchCondition(List<T> numbers, Predicate<T> predicate) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: требуется вернуть примитив
created_at: 2025-04-17T22:39:00Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
+        return strings.stream()
+                .filter(str -> str.charAt(0) == a)
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String an) {
+        return strings.stream()
+                .filter(str -> str.contains(an))
+                .toList();
+    }
+
+    public static List<String> sortByLength(List<String> strings) {
+        return strings.stream()
+                .sorted(Comparator.comparingInt(String::length))
+                .toList();
+    }
+
+    public static <T> Boolean allMatchCondition(List<T> numbers, Predicate<T> predicate) {
+        return numbers.stream()
+                .allMatch(predicate);
+    }
+
+    public static Integer findMinGreaterThan(List<Integer> numbers, int i) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: лучше назвать второй аргумент метода threshold, это более понятное имя нежели просто i
created_at: 2025-04-17T22:40:25Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
+        return strings.stream()
+                .filter(str -> str.charAt(0) == a)
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String an) {
+        return strings.stream()
+                .filter(str -> str.contains(an))
+                .toList();
+    }
+
+    public static List<String> sortByLength(List<String> strings) {
+        return strings.stream()
+                .sorted(Comparator.comparingInt(String::length))
+                .toList();
+    }
+
+    public static <T> Boolean allMatchCondition(List<T> numbers, Predicate<T> predicate) {
+        return numbers.stream()
+                .allMatch(predicate);
+    }
+
+    public static Integer findMinGreaterThan(List<Integer> numbers, int i) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: аналогично можно не преобразовывать в IntStream, достаточно в min положит Comparator Integer-а
created_at: 2025-04-17T22:41:06Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
+        return strings.stream()
+                .filter(str -> str.charAt(0) == a)
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String an) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: Назови переменную ```an```  более понятно, чтобы сразу было ясно, что она обозначает.
Например - ```substring```
created_at: 2025-04-17T22:43:44Z
author_association: NONE
diff_hunk: @@ -0,0 +1,65 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static Integer sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static Integer findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElseGet(null);
+    }
+
+    public static Double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseGet(null);
+    }
+
+    public static Long countStringsStartingWith(List<String> strings, char a) {
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body: Назови переменную ```a``` более понятно, чтобы сразу было ясно, что она обозначает.
Например - ```sumbol```


created_at: 2025-04-17T22:44:30Z
author_association: NONE
diff_hunk: @@ -0,0 +1,64 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static int sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static int findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .max(Integer::compareTo)
+                .orElseThrow(IllegalArgumentException::new);
+    }
+
+    public static double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseThrow(IllegalArgumentException::new);
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body:  Всегда указывай сообщение при создании исключения. Это поможет лучше понять, почему оно возникло.
created_at: 2025-04-18T14:32:39Z
author_association: NONE
diff_hunk: @@ -0,0 +1,64 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static int sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static int findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .max(Integer::compareTo)
+                .orElseThrow(IllegalArgumentException::new);
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body:  Всегда указывай сообщение при создании исключения. Это поможет лучше понять, почему оно возникло.
created_at: 2025-04-18T14:32:41Z
author_association: NONE
diff_hunk: @@ -0,0 +1,64 @@
+package school.faang.stream2.streamapi1;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.function.Predicate;
+
+public class ListOperations {
+    public static int sumOfEvenNumbers(List<Integer> numbers) {
+        return numbers.stream()
+                .filter(n -> n % 2 == 0)
+                .mapToInt(Integer::intValue)
+                .sum();
+    }
+
+    public static int findMax(List<Integer> numbers) {
+        return numbers.stream()
+                .max(Integer::compareTo)
+                .orElseThrow(IllegalArgumentException::new);
+    }
+
+    public static double findAverage(List<Integer> numbers) {
+        return numbers.stream()
+                .mapToInt(Integer::intValue)
+                .average()
+                .orElseThrow(IllegalArgumentException::new);
+    }
+
+    public static long countStringsStartingWith(List<String> strings, char firstLetter) {
+        return strings.stream()
+                .filter(str -> str.startsWith(String.valueOf(firstLetter)))
+                .count();
+    }
+
+    public static List<String> filterStringsContainingSubstring(List<String> strings, String substring) {
+        return strings.stream()
+                .filter(str -> str.contains(substring))
+                .toList();
+    }
+
+    public static List<String> sortByLength(List<String> strings) {
+        return strings.stream()
+                .sorted(Comparator.comparingInt(String::length))
+                .toList();
+    }
+
+    public static boolean allMatchCondition(List<Integer> numbers, Predicate<Integer> predicate) {
+        return numbers.stream()
+                .allMatch(predicate);
+    }
+
+    public static int findMinGreaterThan(List<Integer> numbers, int threshold) {
+        return numbers.stream()
+                .filter(n -> n > threshold)
+                .min(Integer::compareTo)
+                .orElseThrow(NoSuchElementException::new);
path: src/main/java/school/faang/stream2/streamapi1/ListOperations.java
user: login: MarselYsup
body:  Всегда указывай сообщение при создании исключения. Это поможет лучше понять, почему оно возникло.
created_at: 2025-04-18T14:32:47Z
author_association: NONE

PR comments:
user: login: github-actions[bot]
created_at: 2025-04-17T20:57:18Z
body: ⚠️ **ОШЫБКА**: Сборка завалилась: либо ошибки компиляции, либо не прошли тесты, либо возникли ошибки в стиле кода. Пожалуйста, проверь логи и внеси соответствующие изменения в ПР. После этого красная ошибка ниже должна пропасть, но этот комментарий останется - так и должно быть.
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-04-18T14:43:51Z
body: ⚠️ **ОШЫБКА**: Сборка завалилась: либо ошибки компиляции, либо не прошли тесты, либо возникли ошибки в стиле кода. Пожалуйста, проверь логи и внеси соответствующие изменения в ПР. После этого красная ошибка ниже должна пропасть, но этот комментарий останется - так и должно быть.
author_association: NONE