diff --git a/0-0-intro/pom.xml b/0-0-intro/pom.xml
index b62fec52e..056e51706 100644
--- a/0-0-intro/pom.xml
+++ b/0-0-intro/pom.xml
@@ -17,6 +17,13 @@
java-fundamentals-util1.0-SNAPSHOT
+
+
+ org.projectlombok
+ lombok
+ 1.18.30
+ provided
+
\ No newline at end of file
diff --git a/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java b/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java
index 35d925636..4e6fa2a22 100644
--- a/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java
+++ b/0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java
@@ -1,6 +1,7 @@
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.
@@ -23,8 +24,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!";
}
/**
@@ -39,7 +39,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());
}
}
diff --git a/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/Box.java b/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/Box.java
index 5a2d860ee..1613fcfc3 100644
--- a/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/Box.java
+++ b/1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/Box.java
@@ -7,18 +7,18 @@
*
* 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 {
+ 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;
}
-}
+}
\ No newline at end of file
diff --git a/1-0-java-basics/1-3-1-crazy-generics/pom.xml b/1-0-java-basics/1-3-1-crazy-generics/pom.xml
index cab63d0ba..7ae86d528 100644
--- a/1-0-java-basics/1-3-1-crazy-generics/pom.xml
+++ b/1-0-java-basics/1-3-1-crazy-generics/pom.xml
@@ -10,5 +10,14 @@
4.0.01-3-1-crazy-generics
-
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.30
+ provided
+
+
+
\ No newline at end of file
diff --git a/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/ArrayListPractice.java b/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/ArrayListPractice.java
new file mode 100644
index 000000000..b9e6c5dfe
--- /dev/null
+++ b/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/ArrayListPractice.java
@@ -0,0 +1,77 @@
+package com.bobocode.basics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class ArrayListPractice {
+ public static void main(String[] args) {
+ // 1
+ ArrayList colors = new ArrayList<>();
+ colors.add("Red");
+ colors.add("Green");
+ colors.add("Blue");
+ colors.add("White");
+ System.out.println("1. Initial list: " + colors);
+
+ // 2
+ System.out.println("2. Iterating:");
+ for (String color : colors) {
+ System.out.println(" - " + color);
+ }
+
+ // 3
+ colors.add(0, "Black");
+ System.out.println("3. After adding Black at index 0: " + colors);
+
+ // 4
+ String element = colors.get(2);
+ System.out.println("4. Element at index 2: " + element);
+
+ // 5
+ colors.set(1, "Yellow");
+ System.out.println("5. After setting index 1 to Yellow: " + colors);
+
+ // 6
+ colors.remove(2);
+ System.out.println("6. After removing 3rd element: " + colors);
+
+ // 7
+ boolean containsWhite = colors.contains("White");
+ System.out.println("7. Contains 'White'? " + containsWhite);
+ int index = colors.indexOf("White");
+ System.out.println(" Index of 'White': " + index);
+
+ // 8
+ Collections.sort(colors);
+ System.out.println("8. Sorted list: " + colors);
+
+ // 9
+ ArrayList copyList = new ArrayList<>(colors);
+ Collections.copy(copyList, colors);
+ System.out.println("9. Copied list: " + copyList);
+
+ // 10
+ Collections.reverse(colors);
+ System.out.println("10. Reversed list: " + colors);
+
+ // 11
+ boolean isEqual = colors.equals(copyList);
+ System.out.println("11. Is equal to copy? " + isEqual);
+
+ // 12
+ colors.clear();
+ System.out.println("12. List is cleared.");
+
+ // 13
+ System.out.println("13. Is list empty? " + colors.isEmpty());
+
+ // 14
+ colors.ensureCapacity(20);
+ System.out.println("14. Capacity increased to holding at least 20 elements");
+
+ // 15
+ colors.trimToSize();
+ System.out.println("15. Trimming capacity to size: " + colors.size());
+ }
+}
diff --git a/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/CrazyGenerics.java b/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/CrazyGenerics.java
index 751d5899f..36b0672e1 100644
--- a/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/CrazyGenerics.java
+++ b/1-0-java-basics/1-3-1-crazy-generics/src/main/java/com/bobocode/basics/CrazyGenerics.java
@@ -5,10 +5,8 @@
import lombok.Data;
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
@@ -33,8 +31,8 @@ public class CrazyGenerics {
* @param – 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 {
+ private T value;
private String source;
}
@@ -45,11 +43,10 @@ public static class Sourced { // todo: refactor class to introduce type paramete
* @param – 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 {
+ private final T actual;
+ private final T min;
+ private final T max;
}
/**
@@ -59,8 +56,8 @@ public static class Limited {
* @param – source object type
* @param - converted result type
*/
- public interface Converter { // todo: introduce type parameters
- // todo: add convert method
+ public interface Converter {
+ R convert(T obj);
}
/**
@@ -70,10 +67,10 @@ public interface Converter { // todo: introduce type parameters
*
* @param – value type
*/
- public static class MaxHolder { // todo: refactor class to make it generic
- private Object max;
+ public static class MaxHolder> {
+ private T max;
- public MaxHolder(Object max) {
+ public MaxHolder(T max) {
this.max = max;
}
@@ -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 (max == null || val.compareTo(max) > 0) {
+ max = val;
+ }
}
- public Object getMax() {
+ public T getMax() {
return max;
}
}
@@ -97,8 +96,8 @@ public Object getMax() {
*
* @param – the type of objects that can be processed
*/
- interface StrictProcessor { // todo: make it generic
- void process(Object obj);
+ interface StrictProcessor> {
+ void process(T obj);
}
/**
@@ -108,10 +107,10 @@ interface StrictProcessor { // todo: make it generic
* @param – a type of the entity that should be a subclass of {@link BaseEntity}
* @param – a type of any collection
*/
- interface CollectionRepository { // todo: update interface according to the javadoc
- void save(Object entity);
+ interface CollectionRepository> {
+ void save(T entity);
- Collection