Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Solution & Discussion #33

Open
wants to merge 236 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
236 commits
Select commit Hold shift + click to select a range
0b0a61e
GP-24 Implement CrazyLambdas with comments
tboychuk Dec 28, 2020
06339fa
GP-24 Implement CrazyOptionals and copied impl of CrazyStreams
tboychuk Dec 28, 2020
86eca57
Merge branch 'main' into exercise/completed
tboychuk Dec 28, 2020
fc238d7
Merge pull request #3 from bobocode-projects/main
shryhus Dec 29, 2020
8484b36
Merge branch 'main' into exercise/completed
shryhus Dec 29, 2020
0397a73
Merge branch 'main' into exercise/completed
tboychuk Jan 4, 2021
12e944f
Merge branch 'main' into exercise/completed
tboychuk Jan 5, 2021
373d7e3
Merge pull request #12 from bobocode-projects/main
tboychuk Jan 5, 2021
54f3773
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
50d2965
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
9329d5d
GP-26 add the exercise solution with a tail and extra methods
shryhus Jan 5, 2021
4bece28
Merge pull request #16 from bobocode-projects/GP-26_Add_compleated_so…
tboychuk Jan 6, 2021
cf23eca
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
4b74417
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
54bdcc2
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
760dbfc
GP-31 migrate java oop
shryhus Jan 5, 2021
787778d
Merge pull request #18 from bobocode-projects/GP-31_migrate_java_oop_…
tboychuk Jan 6, 2021
97be0be
Merge branch 'main' into exercise/completed
tboychuk Jan 6, 2021
49adec3
GP-28 Add File Reader solution to exercise/completed
shryhus Jan 5, 2021
b917396
GP-28 fix imports
tboychuk Jan 6, 2021
c874d38
Merge pull request #17 from bobocode-projects/GP-28_Migrate_File_Read…
tboychuk Jan 6, 2021
947b71e
GP-25 add new README.md for functional programming basics
tboychuk Jan 6, 2021
47923cb
GP-25 add Lear or Skip section
tboychuk Jan 6, 2021
10eb8ed
Merge branch 'main' into exercise/completed
tboychuk Jan 14, 2021
6232624
Merge branch 'main' into exercise/completed
shryhus Jan 14, 2021
b563231
GP-32 Update Stack(0-2 + 0-6) for completed
shryhus Jan 13, 2021
4daf746
GP-32 Fix the tdd StackTest
shryhus Jan 14, 2021
5dfdbb1
Merge pull request #25 from bobocode-projects/GP-32_Merge_stack_into_…
tboychuk Jan 14, 2021
0f65961
Merge branch 'main' into exercise/completed
tboychuk Jan 14, 2021
d55d67a
GP-33 Add ArrayList completed solution
shryhus Jan 13, 2021
5e2d4c8
Merge pull request #27 from bobocode-projects/GP-33_a_new_ArrayList_e…
tboychuk Jan 14, 2021
f19fb37
Merge branch 'GP-29-Migrate_FileStats_into_Core' into GP-29-Migrate_F…
MrMaksym Jan 16, 2021
d574ffd
GP-29: complete FileStats.java
MrMaksym Jan 16, 2021
b4e2ac5
Merge branch 'GP-29-Migrate_FileStats_into_Core' into GP-29-Migrate_F…
MrMaksym Jan 16, 2021
8c2f26d
Merge branch 'GP-29-Migrate_FileStats_into_Core' into GP-29-Migrate_F…
MrMaksym Jan 16, 2021
62dbe3e
Merge branch 'main' into exercise/completed
tboychuk Jan 18, 2021
46fb57c
Merge pull request #30 from maxstasiuk92/GP-29-Migrate_FileStats_into…
tboychuk Jan 18, 2021
8e2dfed
Merge branch 'GP-41_Fix_method_remove()_of_a_List_into_main' into GP-…
shryhus Jan 20, 2021
3a9ca66
GP-41 Update completed methods
shryhus Jan 20, 2021
127e62a
Merge branch 'GP-41_Fix_method_remove()_of_a_List_into_main' into GP-…
shryhus Jan 20, 2021
0185b13
GP-41 Update completed solution
shryhus Jan 20, 2021
513547d
Merge pull request #32 from bobocode-projects/GP-41_Fix_method_remove…
tboychuk Jan 20, 2021
6160bf6
Merge branch 'main' into exercise/completed
tboychuk Jan 20, 2021
a8cbabf
GP-38 Fix test name in tdd completed
shryhus Jan 21, 2021
2ebab84
Merge branch 'GP-37_Fix_LinkedList_exercise_into_main' into GP-37_Fix…
shryhus Jan 21, 2021
994d38b
Merge branch 'GP-37_Fix_LinkedList_exercise_into_main' into GP-37_Fix…
shryhus Jan 21, 2021
610d12b
GP-37 add completed solution for LinkedList in TDD
shryhus Jan 21, 2021
43c04ff
Merge branch 'GP-37_Fix_LinkedList_exercise_into_main' into GP-37_Fix…
shryhus Jan 21, 2021
2cb8c0e
GP-40: back-up
MrMaksym Jan 19, 2021
6509524
back-up
MrMaksym Jan 20, 2021
043d0ff
GP-40: BinarySearchTree is clean; BinarySearchTreeTest almost ready
MrMaksym Jan 20, 2021
5896515
GP-40: pass all tests
MrMaksym Jan 20, 2021
780aad2
GP-40: clean tests
MrMaksym Jan 21, 2021
1d5b0a0
GP-40: clean tests
MrMaksym Jan 21, 2021
5e45e16
GP-40: prepare README.md
MrMaksym Jan 21, 2021
db5602f
GP-40: prepare TDD module
MrMaksym Jan 21, 2021
e49e234
GP-40: complete TDD module
MrMaksym Jan 21, 2021
61bf641
Merge branch 'main' into completed
tboychuk Jan 22, 2021
5496d28
Merge branch 'completed' into GP-37_Fix_LinkedList_exercise_into_comp…
tboychuk Jan 22, 2021
17cb3c6
Merge pull request #35 from bobocode-projects/GP-37_Fix_LinkedList_ex…
tboychuk Jan 22, 2021
0ce8b6a
* fix contains method
tboychuk Jan 22, 2021
2528021
Merge branch 'main' into completed
tboychuk Jan 22, 2021
a2d3b8f
Implement Introduction
tboychuk Jan 22, 2021
9f4ef70
Merge branch 'main' into completed
tboychuk Jan 22, 2021
d3fb7f5
Merge branch 'main' into completed
tboychuk Jan 22, 2021
ecc1629
Merge branch 'main' into completed
tboychuk Jan 22, 2021
1f56dea
Merge branch 'GP-40-Migrate_BinarySearchTree' into GP-40-Migrate_Bina…
MrMaksym Jan 22, 2021
937963c
GP-40: update test in TDD module to be identical to test in data stru…
MrMaksym Jan 22, 2021
234ea0d
Merge branch 'main' into completed
tboychuk Jan 22, 2021
8b6462d
Merge branch 'main' into completed
tboychuk Jan 22, 2021
0d5f6aa
Merge branch 'GP-40-Migrate_BinarySearchTree' into GP-40-Migrate_Bina…
MrMaksym Jan 22, 2021
4eedd3b
Merge branch 'main' into completed
tboychuk Jan 22, 2021
20391e9
Merge branch 'main' into completed
tboychuk Jan 23, 2021
9a10b60
Merge branch 'main' into completed
tboychuk Jan 23, 2021
975d4bf
Merge branch 'main' into completed
tboychuk Jan 23, 2021
3f18308
Merge branch 'main' into completed
tboychuk Jan 23, 2021
9fa9617
GP-27 complete LinkedQueue
Jan 23, 2021
6974331
Merge pull request #44 from bobocode-projects/GP-27-MigrateLinkedQueu…
tboychuk Jan 23, 2021
818fe1a
Merge pull request #43 from bobocode-projects/UpgradeArrayListImpl
tboychuk Jan 23, 2021
6797233
* add new test to ArrayListTest.java
tboychuk Jan 22, 2021
2957807
* fix order
tboychuk Jan 22, 2021
3da74f4
Merge branch 'main' into completed
tboychuk Jan 23, 2021
d3b6d16
Merge branch 'completed' into GP-40-Migrate_BinarySearchTree-Completed
tboychuk Jan 23, 2021
41061e7
Merge branch 'main' into completed
tboychuk Jan 23, 2021
a7bf2a5
Merge branch 'completed' into GP-40-Migrate_BinarySearchTree-Completed
tboychuk Jan 23, 2021
07fd236
GP-40 remove order from the test
tboychuk Jan 23, 2021
7ab8707
Merge pull request #37 from bobocode-projects/GP-40-Migrate_BinarySea…
tboychuk Jan 23, 2021
e268d8d
Remove ordering from TDD tests
tboychuk Jan 23, 2021
eb45024
Merge branch 'main' into completed
tboychuk Jan 23, 2021
f29fd4c
Merge branch 'main' into completed
tboychuk Jan 23, 2021
c6da406
Merge branch 'main' into completed
shryhus Jan 25, 2021
e2cccf2
Merge branch 'main' into completed
shryhus Jan 25, 2021
b874b4e
GP-46: complete `declarative-sum-of-squares`
v-kuzma Jan 24, 2021
a29b795
Merge pull request #48 from bobocode-projects/GP-46-MigrateDeclarativ…
shryhus Jan 25, 2021
bca0354
Merge branch 'main' into completed
tboychuk Jan 25, 2021
7d65446
Fix ArrayList method remove()
tboychuk Jan 26, 2021
ce83529
Merge branch 'main' into completed
tboychuk Jan 27, 2021
2ad0733
Merge branch 'main' into completed
shryhus Jan 27, 2021
f05394e
GP-47 Update completed solution
shryhus Jan 27, 2021
0d06f07
Merge pull request #51 from bobocode-projects/GP-47_Migrate_lambda-ma…
tboychuk Jan 27, 2021
8cc6cb5
Merge branch 'main' into completed
tboychuk Jan 30, 2021
234ae37
Merge branch 'main' into completed
tboychuk Feb 1, 2021
bca1149
Merge branch 'main' into completed
tboychuk Feb 1, 2021
680f46b
GP-39 fix packages in tdd exercises
tboychuk Feb 1, 2021
6e8d8f6
Merge branch 'main' into completed
tboychuk Feb 1, 2021
ed2e1de
GP-39 fix RecursiveBinarySearchTree.java
tboychuk Feb 1, 2021
2f0dc38
GP-39 fix completed (core module)
tboychuk Feb 1, 2021
5a5a464
Merge branch 'main' into completed
tboychuk Feb 1, 2021
0ee09d2
GP-39 fix packages in OOP exercises
tboychuk Feb 1, 2021
56c6adf
Remove unnecessary checking
sergiiManko Feb 1, 2021
0587496
Merge branch 'main' into completed
tboychuk Feb 2, 2021
231adba
Refactor add() in LinkedList
shryhus Feb 5, 2021
4e94cc7
Merge branch 'main' into completed
shryhus Feb 8, 2021
c9034a4
Merge branch 'main' into completed
tboychuk Feb 9, 2021
5a0c210
Merge branch 'completed' into patch-1
tboychuk Feb 10, 2021
552a961
Merge pull request #56 from sergiiManko/patch-1
tboychuk Feb 10, 2021
07fbe60
Update README.md
tboychuk Feb 10, 2021
c8be790
Update CI pipeline name
tboychuk Feb 10, 2021
ae7ee46
Merge branch 'main' into completed
shryhus Feb 11, 2021
df211f2
Merge branch 'GP-62-NewNodeExercise' into GP-62-NewNodeExerciseCompleted
tboychuk Feb 14, 2021
199408d
GP-62 complete new Node exercise
tboychuk Feb 14, 2021
2a1607c
Merge branch 'main' into completed
shryhus Feb 15, 2021
dab7cfa
Merge pull request #65 from bobocode-projects/GP-62-NewNodeExerciseCo…
shryhus Feb 15, 2021
08b776f
Merge remote-tracking branch 'origin/completed' into completed
shryhus Feb 15, 2021
e645241
Merge branch 'main' into completed
shryhus Feb 16, 2021
f22d159
Merge branch 'main' into completed
tboychuk Feb 26, 2021
c11290f
Merge branch 'main' into completed
tboychuk Feb 26, 2021
59f81e8
Merge branch 'main' into completed
tboychuk Feb 26, 2021
19edf36
Merge branch 'main' into completed
tboychuk Feb 26, 2021
7295ced
GP-39 implement updated PrimeNumbers
tboychuk Feb 26, 2021
7396a4e
Upgrade the impl of PrimeNumbers.java
tboychuk Feb 26, 2021
9331d3d
Merge branch 'main' into completed
tboychuk Feb 26, 2021
5ae47d6
Merge branch 'main' into completed
tboychuk Feb 26, 2021
789afca
Merge branch 'main' into completed
tboychuk Feb 26, 2021
c07652d
Merge branch 'main' into completed
tboychuk Mar 2, 2021
4261c85
Merge branch 'main' into completed
tboychuk Apr 1, 2021
0cad716
Merge branch 'main' into completed
tboychuk Apr 13, 2021
3182d02
Merge branch 'main' into completed
tboychuk Apr 13, 2021
c56f1f2
Merge branch 'main' into completed
tboychuk Apr 21, 2021
71a2099
Merge branch 'main' into completed
tboychuk Apr 21, 2021
cbe1654
Merge branch 'main' into completed
tboychuk Jun 29, 2021
d0e4869
Merge branch 'main' into completed
tboychuk Jul 1, 2021
7fcebab
Complete hello-generics exercise
tboychuk Jul 1, 2021
b1bc0bc
Merge branch 'main' into completed
tboychuk Jul 2, 2021
91117c6
Merge branch 'main' into completed
tboychuk Jul 2, 2021
e12ebde
Complete crazy-generics exercise
tboychuk Jul 2, 2021
c624ae8
Merge branch 'main' into completed
tboychuk Jul 2, 2021
c4ec441
Merge branch 'main' into completed
tboychuk Jul 2, 2021
a28ee35
Merge branch 'main' into completed
tboychuk Jul 13, 2021
32773f9
Merge branch 'main' into completed
tboychuk Jul 13, 2021
9facc50
GP-119 complete tasks related to unbounded wildcard parameters
tboychuk Jul 13, 2021
fa93c86
Merge branch 'main' into completed
tboychuk Jul 30, 2021
34965a2
GP-119 complete new tasks related to generic methods
tboychuk Jul 30, 2021
c9c3a2e
Merge branch 'main' into completed
tboychuk Jul 30, 2021
c204a22
Merge branch 'main' into completed
tboychuk Jul 30, 2021
397b8e7
Merge branch 'main' into completed
tboychuk Aug 3, 2021
10bd3df
GP-119 complete new method and fix conflicts after main updates
tboychuk Aug 3, 2021
4633296
Merge branch 'main' into completed
tboychuk Aug 12, 2021
5ed46eb
Merge branch 'main' into completed
tboychuk Aug 12, 2021
ae6244a
Merge branch 'main' into completed
tboychuk Aug 16, 2021
2e0d7f8
Complete hello-annotations exercise
tboychuk Aug 16, 2021
b5b2508
Merge branch 'main' into completed
tboychuk Aug 16, 2021
5286320
Merge branch 'main' into completed
tboychuk Aug 18, 2021
3b59ea4
Merge branch 'main' into completed
tboychuk Aug 18, 2021
1f8ef75
Merge branch 'main' into completed
tboychuk Aug 20, 2021
9f0694f
Merge branch 'main' into completed
tboychuk Aug 20, 2021
61b7b39
Merge branch 'main' into completed
tboychuk Aug 20, 2021
635ae42
GP-119 add impl for MaxHolder
tboychuk Aug 20, 2021
0a79eb1
Merge branch 'main' into completed
tboychuk Aug 31, 2021
d398296
Merge branch 'main' into completed
tboychuk Sep 1, 2021
d83cb15
Merge branch 'main' into completed
tboychuk Sep 15, 2021
6468e73
Merge branch 'main' into completed
tboychuk Sep 15, 2021
0aef116
Merge branch 'main' into completed
tboychuk Sep 27, 2021
d49a70d
Merge branch 'main' into completed
tboychuk Sep 30, 2021
f1244da
Merge branch 'main' into completed
tboychuk Oct 5, 2021
bb47c02
GP-39 fun-prime-numbers
tboychuk Oct 5, 2021
2c28f90
Merge branch 'main' into completed
tboychuk Oct 5, 2021
c703cbb
GP-39 fun-prime-numbers
tboychuk Oct 5, 2021
24442b9
Merge branch 'main' into completed
tboychuk Oct 11, 2021
5aa68be
Merge branch 'main' into completed
tboychuk Oct 15, 2021
7cefe93
Merge branch 'main' into completed
tboychuk Oct 26, 2021
f0de884
Merge branch 'main' into completed
tboychuk Nov 5, 2021
2e7337c
Merge branch 'main' into completed
tboychuk Nov 5, 2021
b73fbcd
Merge branch 'main' into completed
tboychuk Nov 5, 2021
088f84d
Merge branch 'main' into completed
tboychuk Nov 5, 2021
fe3ff96
Issue-112 complete solution
tboychuk Nov 5, 2021
79618c6
Merge pull request #120 from bobocode-projects/112-crazy-regex-soluti…
tboychuk Nov 5, 2021
4bb6d0f
Update hello-exercise
tboychuk Nov 12, 2021
4212289
Merge branch 'main' into completed
tboychuk Nov 12, 2021
fc67313
Merge branch 'main' into completed
shryhus Jan 4, 2022
5d05b43
Merge branch 'main' into completed
shryhus Jan 12, 2022
a8b422e
#121 add answer in 5-0-2
shryhus Jan 13, 2022
db4d3a5
Merge branch 'main' into completed
tboychuk May 4, 2022
7265777
[2-2-4-linked-list] fix NPE when removing element by zero index from …
andrii-k6a May 4, 2022
25db4c8
Merge branch 'main' into completed
tboychuk Jun 17, 2022
dd40752
GP-145 Complete Hash Table Exercise
tboychuk Jun 17, 2022
e5cff06
Merge branch 'main' into completed
tboychuk Jun 17, 2022
bb6697e
Merge branch 'main' into completed
tboychuk Jun 17, 2022
837637d
Merge branch 'main' into completed
tboychuk Jun 20, 2022
5a05a4d
Merge pull request #124 from bobocode-projects/#121_add_right_answer_…
tboychuk Jun 27, 2022
7770514
[2-2-4-linked-list] add test - removing by zero index from empty list
andrii-k6a May 4, 2022
9119545
Merge branch 'main' into completed
tboychuk Jun 27, 2022
af77c7c
Merge pull request #125 from andrii-k6a/linked-list-exercise-bug-fix-…
tboychuk Jun 27, 2022
5491d51
Merge branch 'main' into completed
tboychuk Jun 27, 2022
f0407cd
Merge branch 'main' into completed
tboychuk Jun 27, 2022
4b31b27
Merge branch 'main' into completed
tboychuk Jun 30, 2022
2763307
GP-146 - complete Heterogeneous Max Holder Exercise
tboychuk Jun 30, 2022
906f05e
Merge branch 'main' into completed
tboychuk Jul 20, 2022
3acaf11
GP-147 fix HeterogeneousMaxHolder
tboychuk Jul 20, 2022
349b096
added tests for size change HashTableTest, (#134)
Stanislav-Zabramnyi Aug 3, 2022
4251b75
Merge branch 'main' into completed
Stanislav-Zabramnyi Aug 3, 2022
51df2ed
Merge branch 'main' into completed
tboychuk Aug 4, 2022
ee914af
Gp 155/random field comparator/completed (#137)
Stanislav-Zabramnyi Aug 12, 2022
eb858fb
fix test add check for tail value (#149)
DimaYakovenko Oct 26, 2022
3cd9bf9
Merge branch 'main' into completed
Stanislav-Zabramnyi Oct 26, 2022
66431a4
Merge branch 'main' into completed
Stanislav-Zabramnyi Oct 26, 2022
31eb00f
[GP-165] Rename 2-2-7-hash-table to 2-2-9-hash-table
BoSerhii Nov 17, 2022
042e9ee
Minor updates for exercise Introduction
tboychuk Nov 20, 2022
1f56c41
Merge branch 'main' into completed
tboychuk Nov 30, 2022
691458c
GP-119 fix tests to follow PECS
tboychuk Nov 30, 2022
476c662
Merge branch 'main' into completed
tboychuk Dec 10, 2022
4fd58b2
CrazyLambdas upgrade
tboychuk Dec 10, 2022
c36f3db
Merge pull request #153 from bobocode-projects/gp_165_rename_hash_table
tboychuk Feb 6, 2023
6ab2baa
Merge branch 'main' into completed
tboychuk Feb 6, 2023
940fa2d
Merge branch 'main' into completed
tboychuk Jun 23, 2023
ef0fe4a
Update CrazyOptionals.java
hladchenko Sep 21, 2023
8a6e28b
Merge branch 'main' into completed
tboychuk Oct 17, 2023
d14505d
Merge pull request #180 from hladchenko/patch-1
tboychuk Jan 15, 2024
f6ad760
CrazyGenerics add test for checking public accessor type by new methods
May 14, 2023
474373d
rename test variable
May 14, 2023
d50009b
rename method names
May 14, 2023
0916202
Rename test name on ArrayListTest
vitshch Oct 25, 2023
88e17bf
GP-145 Fix resizeTable method to calculate HashTable size correctly
tboychuk Jan 15, 2024
cd329eb
Merge branch 'main' into completed
tboychuk Apr 25, 2024
5c4e3ca
Merge branch 'refs/heads/main' into completed
tboychuk Jun 3, 2024
86444d6
Merge branch 'refs/heads/main' into completed
tboychuk Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bobocode.intro;

import com.bobocode.util.ExerciseNotCompletedException;
import java.util.Base64;

/**
* Welcome! This is an introduction exercise that will show you a simple example of Bobocode exercises.
Expand All @@ -23,8 +23,7 @@ public class ExerciseIntroduction {
* @return "The key to efficient learning is practice!"
*/
public String getWelcomeMessage() {
// todo: implement a method and return a message according to javadoc
throw new ExerciseNotCompletedException();
return "The key to efficient learning is practice!";
}

/**
Expand All @@ -39,7 +38,6 @@ public String getWelcomeMessage() {
* @return encoded message
*/
public String encodeMessage(String message) {
// todo: switch to branch "completed" in order to see how it should be implemented
throw new ExerciseNotCompletedException();
return Base64.getEncoder().encodeToString(message.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
* <p>
* todo: refactor this class so it uses generic type "T" and run {@link com.bobocode.basics.BoxTest} to verify it
*/
public class Box {
private Object value;
public class Box<T> {
private T value;

public Box(Object value) {
public Box(T value) {
this.value = value;
}

public Object getValue() {
public T getValue() {
return value;
}

public void setValue(Object value) {
public void setValue(T value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
*/
public class BoxDemoApp {
public static void main(String[] args) {
Box intBox = new Box(123);
Box intBox2 = new Box(321);
System.out.println((int) intBox.getValue() + (int) intBox2.getValue());
Box<Integer> intBox = new Box<>(123);
Box<Integer> intBox2 = new Box<>(321);
System.out.println((int) intBox.getValue() + intBox2.getValue());

intBox.setValue(222);
intBox.setValue("abc"); // this should not be allowed
// the following code will compile, but will throw runtime exception
System.out.println((int) intBox.getValue() + (int) intBox2.getValue());
// intBox.setValue("abc"); // this should not be allowed
System.out.println((int) intBox.getValue() + intBox2.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.bobocode.basics;

import com.bobocode.basics.util.BaseEntity;
import com.bobocode.util.ExerciseNotCompletedException;
import lombok.Data;
import lombok.val;

import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.function.Predicate;

/**
* {@link CrazyGenerics} is an exercise class. It consists of classes, interfaces and methods that should be updated
Expand All @@ -33,8 +31,8 @@ public class CrazyGenerics {
* @param <T> – value type
*/
@Data
public static class Sourced { // todo: refactor class to introduce type parameter and make value generic
private Object value;
public static class Sourced<T> {
private T value;
private String source;
}

Expand All @@ -45,11 +43,10 @@ public static class Sourced { // todo: refactor class to introduce type paramete
* @param <T> – actual, min and max type
*/
@Data
public static class Limited {
// todo: refactor class to introduce type param bounded by number and make fields generic numbers
private final Object actual;
private final Object min;
private final Object max;
public static class Limited<T extends Number> {
private final T actual;
private final T min;
private final T max;
}

/**
Expand All @@ -59,8 +56,8 @@ public static class Limited {
* @param <T> – source object type
* @param <R> - converted result type
*/
public interface Converter { // todo: introduce type parameters
// todo: add convert method
public interface Converter<T, R> {
R convert(T obj);
}

/**
Expand All @@ -70,10 +67,10 @@ public interface Converter { // todo: introduce type parameters
*
* @param <T> – value type
*/
public static class MaxHolder { // todo: refactor class to make it generic
private Object max;
public static class MaxHolder<T extends Comparable<? super T>> { // todo: refactor class to make it generic
private T max;

public MaxHolder(Object max) {
public MaxHolder(T max) {
this.max = max;
}

Expand All @@ -82,11 +79,13 @@ public MaxHolder(Object max) {
*
* @param val a new value
*/
public void put(Object val) {
throw new ExerciseNotCompletedException(); // todo: update parameter and implement the method
public void put(T val) {
if (val.compareTo(max) > 0) {
max = val;
}
}

public Object getMax() {
public T getMax() {
return max;
}
}
Expand All @@ -97,8 +96,8 @@ public Object getMax() {
*
* @param <T> – the type of objects that can be processed
*/
interface StrictProcessor { // todo: make it generic
void process(Object obj);
interface StrictProcessor<T extends Serializable & Comparable<? super T>> { // todo: make it generic
void process(T obj);
}

/**
Expand All @@ -108,10 +107,10 @@ interface StrictProcessor { // todo: make it generic
* @param <T> – a type of the entity that should be a subclass of {@link BaseEntity}
* @param <C> – a type of any collection
*/
interface CollectionRepository { // todo: update interface according to the javadoc
void save(Object entity);
interface CollectionRepository<T extends BaseEntity, C extends Collection<T>> { // todo: update interface according to the javadoc
void save(T entity);

Collection<Object> getEntityCollection();
C getEntityCollection();
}

/**
Expand All @@ -120,7 +119,7 @@ interface CollectionRepository { // todo: update interface according to the java
*
* @param <T> – a type of the entity that should be a subclass of {@link BaseEntity}
*/
interface ListRepository { // todo: update interface according to the javadoc
interface ListRepository<T extends BaseEntity> extends CollectionRepository<T, List<T>> { // todo: update interface according to the javadoc
}

/**
Expand All @@ -133,12 +132,14 @@ interface ListRepository { // todo: update interface according to the javadoc
*
* @param <E> a type of collection elements
*/
interface ComparableCollection { // todo: refactor it to make generic and provide a default impl of compareTo
interface ComparableCollection<E> extends Collection<E>, Comparable<Collection<?>> {

@Override
default int compareTo(Collection<?> o) {
return Integer.compare(this.size(), o.size());
}
}

/**
* {@link CollectionUtil} is an util class that provides various generic helper methods.
*/
static class CollectionUtil {
static final Comparator<BaseEntity> CREATED_ON_COMPARATOR = Comparator.comparing(BaseEntity::getCreatedOn);

Expand All @@ -147,8 +148,7 @@ static class CollectionUtil {
*
* @param list
*/
public static void print(List<Integer> list) {
// todo: refactor it so the list of any type can be printed, not only integers
public static void print(List<?> list) {
list.forEach(element -> System.out.println(" – " + element));
}

Expand All @@ -160,8 +160,9 @@ public static void print(List<Integer> list) {
* @param entities provided collection of entities
* @return true if at least one of the elements has null id
*/
public static boolean hasNewEntities(Collection<BaseEntity> entities) {
throw new ExerciseNotCompletedException(); // todo: refactor parameter and implement method
public static boolean hasNewEntities(Collection<? extends BaseEntity> entities) {
return entities.stream()
.anyMatch(e -> e.getUuid() == null);
}

/**
Expand All @@ -173,8 +174,10 @@ public static boolean hasNewEntities(Collection<BaseEntity> entities) {
* @param validationPredicate criteria for validation
* @return true if all entities fit validation criteria
*/
public static boolean isValidCollection() {
throw new ExerciseNotCompletedException(); // todo: add method parameters and implement the logic
public static boolean isValidCollection(Collection<? extends BaseEntity> entities,
Predicate<? super BaseEntity> validationPredicate) {
return entities.stream()
.allMatch(validationPredicate);
}

/**
Expand All @@ -187,8 +190,10 @@ public static boolean isValidCollection() {
* @param <T> entity type
* @return true if entities list contains target entity more than once
*/
public static boolean hasDuplicates() {
throw new ExerciseNotCompletedException(); // todo: update method signature and implement it
public static <T extends BaseEntity> boolean hasDuplicates(Collection<T> entities, T targetEntity) {
return entities.stream()
.filter(e -> e.getUuid().equals(targetEntity.getUuid()))
.count() > 1;
}

/**
Expand All @@ -200,7 +205,20 @@ public static boolean hasDuplicates() {
* @param <T> type of elements
* @return optional max value
*/
// todo: create a method and implement its logic manually without using util method from JDK
public static <T> Optional<T> findMax(Iterable<T> elements, Comparator<? super T> comparator) {
var iterator = elements.iterator();
if (!iterator.hasNext()) {
return Optional.empty();
}
var max = iterator.next();
while (iterator.hasNext()) {
var element = iterator.next();
if (comparator.compare(element, max) > 0) {
max = element;
}
}
return Optional.of(max);
}

/**
* findMostRecentlyCreatedEntity is a generic util method that accepts a collection of entities and returns the
Expand All @@ -214,7 +232,10 @@ public static boolean hasDuplicates() {
* @param <T> entity type
* @return an entity from the given collection that has the max createdOn value
*/
// todo: create a method according to JavaDoc and implement it using previous method
public static <T extends BaseEntity> T findMostRecentlyCreatedEntity(Collection<T> entities) {
return findMax(entities, CREATED_ON_COMPARATOR)
.orElseThrow();
}

/**
* An util method that allows to swap two elements of any list. It changes the list so the element with the index
Expand All @@ -228,8 +249,13 @@ public static boolean hasDuplicates() {
public static void swap(List<?> elements, int i, int j) {
Objects.checkIndex(i, elements.size());
Objects.checkIndex(j, elements.size());
throw new ExerciseNotCompletedException(); // todo: complete method implementation
swapHelper(elements, i, j);
}

private static <T> void swapHelper(List<T> elements, int i, int j) {
T temp = elements.get(i);
elements.set(i, elements.get(j));
elements.set(j, temp);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.bobocode.basics;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

import static java.util.Objects.requireNonNull;

/**
* {@link HeterogeneousMaxHolder} is a multi-type container that holds maximum values per each type. It's kind of a
* key/value map, where the key is a type and the value is the maximum among all values of this type that were put.
Expand All @@ -15,9 +19,10 @@
* @author Taras Boychuk
*/
public class HeterogeneousMaxHolder {
private Map<Class<?>, Object> typeToMaxValueMap = new HashMap<>();

/**
* A method put stores a provided value by its type, if the value is greater than the current maximum. In other words, the logic
* Stores a provided value by its type, if the value is greater than the current maximum. In other words, the logic
* of this method makes sure that only max value is stored and everything else is ignored.
* <p>
* If the current max value is less than a provided one, or if it's null, then a provided value gets stored and the old
Expand All @@ -30,7 +35,9 @@ public class HeterogeneousMaxHolder {
* @param <T> value type parameter
* @return a smaller value among the provided value and the current maximum
*/
// todo: implement a method according to javadoc
public <T extends Comparable<? super T>> T put(Class<T> key, T value) {
return put(key, value, Comparator.naturalOrder());
}

/**
* An overloaded method put implements the same logic using a custom comparator. A given comparator is wrapped with
Expand All @@ -44,14 +51,27 @@ public class HeterogeneousMaxHolder {
* @param <T> value type parameter
* @return a smaller value among the provided value and the current maximum
*/
// todo: implement a method according to javadoc
public <T> T put(Class<T> key, T value, Comparator<? super T> comparator) {
var currentMax = getMax(requireNonNull(key));
var nullSafeComparator = Comparator.nullsFirst(requireNonNull(comparator));
requireNonNull(value);
if (nullSafeComparator.compare(value, currentMax) > 0) {
typeToMaxValueMap.put(key, value);
return currentMax;
}
return value;
}

/**
* A method getMax returns a max value by the given type. If no value is stored by this type, then it returns null.
* Returns a max value by the given type. If no value is stored by this type, then it returns null.
*
* @param key a provided value type
* @param <T> value type parameter
* @return current max value or null
*/
// todo: implement a method according to javadoc
public <T> T getMax(Class<T> key) {
requireNonNull(key);
var currentMax = typeToMaxValueMap.get(key);
return key.cast(currentMax);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bobocode.basics;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Exercise {
String value();

Level complexityLevel() default Level.BASIC;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
*
* @author Taras Boychuk
*/
@Exercise("hello-annotation-basic")
public class HelloAnnotationsExercise { // todo: mark class with the annotation according to the javadoc
}
Loading
Loading